aboutsummaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorMartinaHanusovaNXP <martina.hanusova@nxp.com>2021-05-06 09:25:36 +0200
committerAnton Komlev <Anton.Komlev@arm.com>2021-05-06 23:55:06 +0200
commitb3fbaaf7b5c39ad69f41b2e54e9efd9e445123ee (patch)
tree254ff6ab390e6fba82d7218d34f8d3c149f75004 /platform
parentc05319dbb991d153081d5bf5314b8a635063b252 (diff)
downloadtrusted-firmware-m-b3fbaaf7b5c39ad69f41b2e54e9efd9e445123ee.tar.gz
Platform: LPCxpresso55s69: Synchronized platform specific code with NXP MCUx SDK port
Synchronized platform/ext/target/nxp folder with MCUx latest SDK port: - Updated GCC startup files for LPCxpresso55s69 - Updated flash_layout and region_defs in the partions folder for LPCxpresso55s69 - Updated target_cfg files for LPCxpresso55s69 - Added drivers and utilities into NativeDriver folder for LPCxpresso55s69 - Moved common files from lpcxpresso55s69 folder to common folder - Updated parameters for PS in config.cmake Added pull_drivers.cmake module for automatically updating general SDK drivers from github with specific TAG. Signed-off-by: MartinaHanusovaNXP <martina.hanusova@nxp.com> Change-Id: I171d7be665c931bf3be765cc8ee36fb2026d3f70
Diffstat (limited to 'platform')
-rwxr-xr-xplatform/ext/target/nxp/common/CMSIS_Driver/Driver_USART.c65
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.c423
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.h191
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.c1393
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.h648
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_internal.h99
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.c403
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.h57
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/uart/uart.h532
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/components/uart/usart_adapter.c643
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.c2668
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.h312
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.c2031
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.h1240
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.c212
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.h630
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.c544
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.h488
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.c404
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.h64
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.c302
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.h364
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.c1316
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.h438
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.c285
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.h498
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap_ffr.h274
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_iocon.h288
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_power.c19
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_power.h544
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_reset.c99
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_reset.h281
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_rng.c92
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_rng.h95
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_usart.c957
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/drivers/fsl_usart.h718
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/debug_console/fsl_debug_console.c1178
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/debug_console/fsl_debug_console.h231
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/debug_console/fsl_debug_console_conf.h158
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/fsl_assert.c33
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/fsl_notifier.c209
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/fsl_notifier.h237
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/fsl_sbrk.c44
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/fsl_shell.c970
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/fsl_shell.h230
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/str/fsl_str.c1324
-rwxr-xr-xplatform/ext/target/nxp/common/Native_Driver/utilities/str/fsl_str.h66
-rw-r--r--platform/ext/target/nxp/common/plat_attest_hal.c139
-rw-r--r--platform/ext/target/nxp/common/plat_attestation_key.c110
-rw-r--r--platform/ext/target/nxp/common/plat_huk_key.c160
-rw-r--r--[-rwxr-xr-x]platform/ext/target/nxp/common/plat_test.c (renamed from platform/ext/target/nxp/lpcxpresso55s69/plat_test.c)3
-rw-r--r--[-rwxr-xr-x]platform/ext/target/nxp/common/services/src/tfm_platform_system.c (renamed from platform/ext/target/nxp/lpcxpresso55s69/services/src/tfm_platform_system.c)0
-rw-r--r--[-rwxr-xr-x]platform/ext/target/nxp/common/spm_hal.c (renamed from platform/ext/target/nxp/lpcxpresso55s69/spm_hal.c)13
-rw-r--r--platform/ext/target/nxp/common/tfm_hal_isolation.c (renamed from platform/ext/target/nxp/lpcxpresso55s69/tfm_hal_isolation.c)149
-rw-r--r--platform/ext/target/nxp/lpcxpresso55s69/CMakeLists.txt59
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Device/Source/armgcc/startup_LPC55S69_cm33_core0_ns.S266
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Device/Source/armgcc/startup_LPC55S69_cm33_core0_s.S265
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/LPC55S69_cm33_core0.h27477
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/LPC55S69_cm33_core0_features.h387
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/LPC55S69_cm33_core1.h27477
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/LPC55S69_cm33_core1_features.h387
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/fsl_device_registers.h46
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/system_LPC55S69_cm33_core0.c374
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/Native_Driver/system_LPC55S69_cm33_core0.h112
-rw-r--r--platform/ext/target/nxp/lpcxpresso55s69/config.cmake2
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/partition/flash_layout.h69
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/partition/region_defs.h12
-rw-r--r--platform/ext/target/nxp/lpcxpresso55s69/pull_drivers.cmake97
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/target_cfg.c126
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/target_cfg.h13
-rwxr-xr-xplatform/ext/target/nxp/lpcxpresso55s69/tfm_peripherals_def.h1
71 files changed, 1113 insertions, 80928 deletions
diff --git a/platform/ext/target/nxp/common/CMSIS_Driver/Driver_USART.c b/platform/ext/target/nxp/common/CMSIS_Driver/Driver_USART.c
index 13d85fca1..844a977b1 100755
--- a/platform/ext/target/nxp/common/CMSIS_Driver/Driver_USART.c
+++ b/platform/ext/target/nxp/common/CMSIS_Driver/Driver_USART.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2013-2019 Arm Limited. All rights reserved.
- * Copyright (c) 2020 Linaro. All rights reserved.
+ * Copyright 2019-2021 NXP. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -19,6 +19,7 @@
#include "fsl_common.h"
#include "fsl_usart.h"
+#include "fsl_clock.h"
#include "Driver_USART.h"
#include "board.h"
@@ -82,12 +83,15 @@ static ARM_USART_CAPABILITIES ARM_USART_GetCapabilities(void)
int32_t ARM_USARTx_Initialize(USART_Type *usart, usart_config_t *usartConfig)
{
- uint32_t usartClkFreq = 0;
+
+#if (__ARM_FEATURE_CMSE & 0x2) /* Initialize once in S */
+ uint32_t usartClkFreq;
- usartClkFreq = CLOCK_GetFlexCommClkFreq(0);
+ usartClkFreq = BOARD_DEBUG_UART_CLK_FREQ;
USART_Init(usart, usartConfig, usartClkFreq);
-
+#endif
+
return ARM_DRIVER_OK;
}
@@ -128,12 +132,19 @@ int32_t ARM_USARTx_Receive(USART_Type *base, uint8_t *data, size_t length)
status = USART_ReadBlocking(base, data, length);
- return ARM_DRIVER_OK;
+ if (status == kStatus_Success)
+ {
+ return ARM_DRIVER_OK;
+ }
+ else
+ {
+ return ARM_DRIVER_ERROR;
+ }
}
static int32_t ARM_USART0_Initialize(ARM_USART_SignalEvent_t cb_event)
{
- usart_config_t uart0Config;
+ static usart_config_t uart0Config; /* Have to use "static" otherwise it may cause stack corruption in Keil */
/*
* config.baudRate_Bps = 115200U;
@@ -143,10 +154,10 @@ static int32_t ARM_USART0_Initialize(ARM_USART_SignalEvent_t cb_event)
* config.enableTxFifo = false;
* config.enableRxFifo = false;
*/
- USART_GetDefaultConfig(&uart0Config);
- uart0Config.baudRate_Bps = 115200U;
- uart0Config.enableRx = true;
- uart0Config.enableTx = true;
+ USART_GetDefaultConfig(&uart0Config);
+ uart0Config.baudRate_Bps = 115200U;
+ uart0Config.enableRx = true;
+ uart0Config.enableTx = true;
return ARM_USARTx_Initialize(USART0, &uart0Config);
}
@@ -184,14 +195,12 @@ static int32_t ARM_USART0_Transfer(const void *data_out, void *data_in,
static uint32_t ARM_USART0_GetTxCount(void)
{
- /* This operation is not supported. */
- return ARM_DRIVER_OK;
+ return (uint32_t)ARM_DRIVER_ERROR_UNSUPPORTED;
}
static uint32_t ARM_USART0_GetRxCount(void)
{
- /* This operation is not supported. */
- return ARM_DRIVER_OK;
+ return (uint32_t)ARM_DRIVER_ERROR_UNSUPPORTED;
}
static int32_t ARM_USART0_Control(uint32_t control, uint32_t arg)
@@ -219,18 +228,18 @@ static ARM_USART_MODEM_STATUS ARM_USART0_GetModemStatus(void)
extern ARM_DRIVER_USART Driver_USART0;
ARM_DRIVER_USART Driver_USART0 = {
- ARM_USART_GetVersion,
- ARM_USART_GetCapabilities,
- ARM_USART0_Initialize,
- ARM_USART0_Uninitialize,
- ARM_USART0_PowerControl,
- ARM_USART0_Send,
- ARM_USART0_Receive,
- ARM_USART0_Transfer,
- ARM_USART0_GetTxCount,
- ARM_USART0_GetRxCount,
- ARM_USART0_Control,
- ARM_USART0_GetStatus,
- ARM_USART0_SetModemControl,
- ARM_USART0_GetModemStatus
+ .GetVersion = ARM_USART_GetVersion,
+ .GetCapabilities = ARM_USART_GetCapabilities,
+ .Initialize = ARM_USART0_Initialize,
+ .Uninitialize = ARM_USART0_Uninitialize,
+ .PowerControl = ARM_USART0_PowerControl,
+ .Send = ARM_USART0_Send,
+ .Receive = ARM_USART0_Receive,
+ .Transfer = ARM_USART0_Transfer,
+ .GetTxCount = ARM_USART0_GetTxCount,
+ .GetRxCount = ARM_USART0_GetRxCount,
+ .Control = ARM_USART0_Control,
+ .GetStatus = ARM_USART0_GetStatus,
+ .SetModemControl = ARM_USART0_SetModemControl,
+ .GetModemStatus = ARM_USART0_GetModemStatus
};
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.c b/platform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.c
deleted file mode 100755
index e97e3a76e..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.c
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * Copyright 2018-2019 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-/*! *********************************************************************************
-*************************************************************************************
-* Include
-*************************************************************************************
-********************************************************************************** */
-#include "fsl_common.h"
-#include "generic_list.h"
-
-static list_status_t LIST_Scan(list_handle_t list, list_element_handle_t newElement)
-{
- list_element_handle_t element = list->head;
-
- while (element != NULL)
- {
- if (element == newElement)
- {
- return kLIST_DuplicateError;
- }
- element = element->next;
- }
- return kLIST_Ok;
-}
-
-/*! *********************************************************************************
-*************************************************************************************
-* Public functions
-*************************************************************************************
-********************************************************************************** */
-/*! *********************************************************************************
- * \brief Initialises the list descriptor.
- *
- * \param[in] list - LIST_ handle to init.
- * max - Maximum number of elements in list. 0 for unlimited.
- *
- * \return void.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-void LIST_Init(list_handle_t list, uint32_t max)
-{
- list->head = NULL;
- list->tail = NULL;
- list->max = (uint16_t)max;
- list->size = 0;
-}
-
-/*! *********************************************************************************
- * \brief Gets the list that contains the given element.
- *
- * \param[in] element - Handle of the element.
- *
- * \return NULL if element is orphan.
- * Handle of the list the element is inserted into.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_handle_t LIST_GetList(list_element_handle_t element)
-{
- return element->list;
-}
-
-/*! *********************************************************************************
- * \brief Links element to the tail of the list.
- *
- * \param[in] list - ID of list to insert into.
- * element - element to add
- *
- * \return kLIST_Full if list is full.
- * kLIST_Ok if insertion was successful.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_status_t LIST_AddTail(list_handle_t list, list_element_handle_t element)
-{
- uint32_t regPrimask = DisableGlobalIRQ();
-
- if ((list->max != 0U) && (list->max == list->size))
- {
- EnableGlobalIRQ(regPrimask);
- return kLIST_Full;
- }
-
- if (kLIST_DuplicateError == LIST_Scan(list, element))
- {
- EnableGlobalIRQ(regPrimask);
- return kLIST_DuplicateError;
- }
-
- if (list->size == 0U)
- {
- list->head = element;
- }
- else
- {
- list->tail->next = element;
- }
- element->prev = list->tail;
- element->next = NULL;
- element->list = list;
- list->tail = element;
- list->size++;
-
- EnableGlobalIRQ(regPrimask);
- return kLIST_Ok;
-}
-
-/*! *********************************************************************************
- * \brief Links element to the head of the list.
- *
- * \param[in] list - ID of list to insert into.
- * element - element to add
- *
- * \return kLIST_Full if list is full.
- * kLIST_Ok if insertion was successful.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_status_t LIST_AddHead(list_handle_t list, list_element_handle_t element)
-{
- uint32_t regPrimask = DisableGlobalIRQ();
-
- if ((list->max != 0U) && (list->max == list->size))
- {
- EnableGlobalIRQ(regPrimask);
- return kLIST_Full;
- }
-
- if (kLIST_DuplicateError == LIST_Scan(list, element))
- {
- EnableGlobalIRQ(regPrimask);
- return kLIST_DuplicateError;
- }
-
- if (list->size == 0U)
- {
- list->tail = element;
- }
- else
- {
- list->head->prev = element;
- }
- element->next = list->head;
- element->prev = NULL;
- element->list = list;
- list->head = element;
- list->size++;
-
- EnableGlobalIRQ(regPrimask);
- return kLIST_Ok;
-}
-
-/*! *********************************************************************************
- * \brief Unlinks element from the head of the list.
- *
- * \param[in] list - ID of list to remove from.
- *
- * \return NULL if list is empty.
- * ID of removed element(pointer) if removal was successful.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_element_handle_t LIST_RemoveHead(list_handle_t list)
-{
- list_element_handle_t element;
-
- uint32_t regPrimask = DisableGlobalIRQ();
-
- if ((NULL == list) || (list->size == 0U))
- {
- EnableGlobalIRQ(regPrimask);
- return NULL; /*LIST_ is empty*/
- }
-
- element = list->head;
- list->size--;
- if (list->size == 0U)
- {
- list->tail = NULL;
- }
- else
- {
- element->next->prev = NULL;
- }
- list->head = element->next; /*Is NULL if element is head*/
- element->list = NULL;
-
- EnableGlobalIRQ(regPrimask);
- return element;
-}
-
-/*! *********************************************************************************
- * \brief Gets head element ID.
- *
- * \param[in] list - ID of list.
- *
- * \return NULL if list is empty.
- * ID of head element if list is not empty.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_element_handle_t LIST_GetHead(list_handle_t list)
-{
- return list->head;
-}
-
-/*! *********************************************************************************
- * \brief Gets next element ID.
- *
- * \param[in] element - ID of the element.
- *
- * \return NULL if element is tail.
- * ID of next element if exists.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_element_handle_t LIST_GetNext(list_element_handle_t element)
-{
- return element->next;
-}
-
-/*! *********************************************************************************
- * \brief Gets previous element ID.
- *
- * \param[in] element - ID of the element.
- *
- * \return NULL if element is head.
- * ID of previous element if exists.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_element_handle_t LIST_GetPrev(list_element_handle_t element)
-{
- return element->prev;
-}
-
-/*! *********************************************************************************
- * \brief Unlinks an element from its list.
- *
- * \param[in] element - ID of the element to remove.
- *
- * \return kLIST_OrphanElement if element is not part of any list.
- * kLIST_Ok if removal was successful.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_status_t LIST_RemoveElement(list_element_handle_t element)
-{
- if (element->list == NULL)
- {
- return kLIST_OrphanElement; /*Element was previusly removed or never added*/
- }
-
- uint32_t regPrimask = DisableGlobalIRQ();
-
- if (element->prev == NULL) /*Element is head or solo*/
- {
- element->list->head = element->next; /*is null if solo*/
- }
- if (element->next == NULL) /*Element is tail or solo*/
- {
- element->list->tail = element->prev; /*is null if solo*/
- }
- if (element->prev != NULL) /*Element is not head*/
- {
- element->prev->next = element->next;
- }
- if (element->next != NULL) /*Element is not tail*/
- {
- element->next->prev = element->prev;
- }
- element->list->size--;
- element->list = NULL;
-
- EnableGlobalIRQ(regPrimask);
- return kLIST_Ok;
-}
-
-/*! *********************************************************************************
- * \brief Links an element in the previous position relative to a given member
- * of a list.
- *
- * \param[in] element - ID of a member of a list.
- * newElement - new element to insert before the given member.
- *
- * \return kLIST_OrphanElement if element is not part of any list.
- * kLIST_Full if list is full.
- * kLIST_Ok if insertion was successful.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-list_status_t LIST_AddPrevElement(list_element_handle_t element, list_element_handle_t newElement)
-{
- if (element->list == NULL)
- {
- return kLIST_OrphanElement; /*Element was previusly removed or never added*/
- }
- uint32_t regPrimask = DisableGlobalIRQ();
-
- if ((element->list->max != 0U) && (element->list->max == element->list->size))
- {
- EnableGlobalIRQ(regPrimask);
- return kLIST_Full;
- }
-
- if (kLIST_DuplicateError == LIST_Scan(element->list, newElement))
- {
- EnableGlobalIRQ(regPrimask);
- return kLIST_DuplicateError;
- }
-
- if (element->prev == NULL) /*Element is list head*/
- {
- element->list->head = newElement;
- }
- else
- {
- element->prev->next = newElement;
- }
- newElement->list = element->list;
- element->list->size++;
- newElement->next = element;
- newElement->prev = element->prev;
- element->prev = newElement;
-
- EnableGlobalIRQ(regPrimask);
- return kLIST_Ok;
-}
-
-/*! *********************************************************************************
- * \brief Gets the current size of a list.
- *
- * \param[in] list - ID of the list.
- *
- * \return Current size of the list.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-uint32_t LIST_GetSize(list_handle_t list)
-{
- return list->size;
-}
-
-/*! *********************************************************************************
- * \brief Gets the number of free places in the list.
- *
- * \param[in] list - ID of the list.
- *
- * \return Available size of the list.
- *
- * \pre
- *
- * \post
- *
- * \remarks
- *
- ********************************************************************************** */
-uint32_t LIST_GetAvailableSize(list_handle_t list)
-{
- return ((uint32_t)list->max - (uint32_t)list->size);
-}
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.h b/platform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.h
deleted file mode 100755
index 9cf373d52..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/lists/generic_list.h
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright 2018-2019 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _GENERIC_LIST_H_
-#define _GENERIC_LIST_H_
-
-/*!
- * @addtogroup GenericList
- * @{
- */
-
-/*!*********************************************************************************
-*************************************************************************************
-* Include
-*************************************************************************************
-********************************************************************************** */
-
-/*! *********************************************************************************
-*************************************************************************************
-* Public macro definitions
-*************************************************************************************
-********************************************************************************** */
-
-/*! *********************************************************************************
-*************************************************************************************
-* Public type definitions
-*************************************************************************************
-********************************************************************************** */
-/*! @brief The list status */
-typedef enum _list_status
-{
- kLIST_Ok = kStatus_Success, /*!< Success */
- kLIST_DuplicateError = MAKE_STATUS(kStatusGroup_LIST, 1), /*!< Duplicate Error */
- kLIST_Full = MAKE_STATUS(kStatusGroup_LIST, 2), /*!< FULL */
- kLIST_Empty = MAKE_STATUS(kStatusGroup_LIST, 3), /*!< Empty */
- kLIST_OrphanElement = MAKE_STATUS(kStatusGroup_LIST, 4), /*!< Orphan Element */
-} list_status_t;
-
-/*! @brief The list structure*/
-typedef struct list_label
-{
- struct list_element_tag *head; /*!< list head */
- struct list_element_tag *tail; /*!< list tail */
- uint16_t size; /*!< list size */
- uint16_t max; /*!< list max number of elements */
-} list_label_t, *list_handle_t;
-
-/*! @brief The list element*/
-typedef struct list_element_tag
-{
- struct list_element_tag *next; /*!< next list element */
- struct list_element_tag *prev; /*!< previous list element */
- struct list_label *list; /*!< pointer to the list */
-} list_element_t, *list_element_handle_t;
-
-/*! *********************************************************************************
-*************************************************************************************
-* Public prototypes
-*************************************************************************************
-********************************************************************************** */
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif /* _cplusplus */
-/*!
- * @brief Initialize the list.
- *
- * This function initialize the list.
- *
- * @param list - List handle to initialize.
- * @param max - Maximum number of elements in list. 0 for unlimited.
- */
-void LIST_Init(list_handle_t list, uint32_t max);
-
-/*!
- * @brief Gets the list that contains the given element.
- *
- *
- * @param element - Handle of the element.
- * @retval NULL if element is orphan, Handle of the list the element is inserted into.
- */
-list_handle_t LIST_GetList(list_element_handle_t element);
-
-/*!
- * @brief Links element to the head of the list.
- *
- * @param list - Handle of the list.
- * @param element - Handle of the element.
- * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
- */
-list_status_t LIST_AddHead(list_handle_t list, list_element_handle_t element);
-
-/*!
- * @brief Links element to the tail of the list.
- *
- * @param list - Handle of the list.
- * @param element - Handle of the element.
- * @retval kLIST_Full if list is full, kLIST_Ok if insertion was successful.
- */
-list_status_t LIST_AddTail(list_handle_t list, list_element_handle_t element);
-
-/*!
- * @brief Unlinks element from the head of the list.
- *
- * @param list - Handle of the list.
- *
- * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
- */
-list_element_handle_t LIST_RemoveHead(list_handle_t list);
-
-/*!
- * @brief Gets head element handle.
- *
- * @param list - Handle of the list.
- *
- * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
- */
-list_element_handle_t LIST_GetHead(list_handle_t list);
-
-/*!
- * @brief Gets next element handle for given element handle.
- *
- * @param element - Handle of the element.
- *
- * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
- */
-list_element_handle_t LIST_GetNext(list_element_handle_t element);
-
-/*!
- * @brief Gets previous element handle for given element handle.
- *
- * @param element - Handle of the element.
- *
- * @retval NULL if list is empty, handle of removed element(pointer) if removal was successful.
- */
-list_element_handle_t LIST_GetPrev(list_element_handle_t element);
-
-/*!
- * @brief Unlinks an element from its list.
- *
- * @param element - Handle of the element.
- *
- * @retval kLIST_OrphanElement if element is not part of any list.
- * @retval kLIST_Ok if removal was successful.
- */
-list_status_t LIST_RemoveElement(list_element_handle_t element);
-
-/*!
- * @brief Links an element in the previous position relative to a given member of a list.
- *
- * @param element - Handle of the element.
- * @param newElement - New element to insert before the given member.
- *
- * @retval kLIST_OrphanElement if element is not part of any list.
- * @retval kLIST_Ok if removal was successful.
- */
-list_status_t LIST_AddPrevElement(list_element_handle_t element, list_element_handle_t newElement);
-
-/*!
- * @brief Gets the current size of a list.
- *
- * @param list - Handle of the list.
- *
- * @retval Current size of the list.
- */
-uint32_t LIST_GetSize(list_handle_t list);
-
-/*!
- * @brief Gets the number of free places in the list.
- *
- * @param list - Handle of the list.
- *
- * @retval Available size of the list.
- */
-uint32_t LIST_GetAvailableSize(list_handle_t list);
-
-/* @} */
-
-#if defined(__cplusplus)
-}
-#endif
-/*! @}*/
-#endif /*_GENERIC_LIST_H_*/
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.c b/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.c
deleted file mode 100755
index 0ce8a800b..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.c
+++ /dev/null
@@ -1,1393 +0,0 @@
-/*
- * Copyright 2018-2020 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_common.h"
-#include <string.h>
-
-#include "serial_manager.h"
-#include "serial_port_internal.h"
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-#include "generic_list.h"
-
-/*
- * The OSA_USED macro can only be defined when the OSA component is used.
- * If the source code of the OSA component does not exist, the OSA_USED cannot be defined.
- * OR, If OSA component is not added into project event the OSA source code exists, the OSA_USED
- * also cannot be defined.
- * The source code path of the OSA component is <MCUXpresso_SDK>/components/osa.
- *
- */
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-#include "common_task.h"
-#else
-#include "fsl_os_abstraction.h"
-#endif
-
-#endif
-
-#endif
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-#ifndef NDEBUG
-#if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
-#undef assert
-#define assert(n)
-#endif
-#endif
-
-#define SERIAL_EVENT_DATA_RECEIVED (1U << 0)
-#define SERIAL_EVENT_DATA_SENT (1U << 1)
-
-#define SERIAL_MANAGER_WRITE_TAG 0xAABB5754U
-#define SERIAL_MANAGER_READ_TAG 0xBBAA5244U
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-typedef enum _serial_manager_transmission_mode
-{
- kSerialManager_TransmissionBlocking = 0x0U, /*!< Blocking transmission*/
- kSerialManager_TransmissionNonBlocking = 0x1U, /*!< None blocking transmission*/
-} serial_manager_transmission_mode_t;
-
-/* TX transfer structure */
-typedef struct _serial_manager_transfer
-{
- uint8_t *buffer;
- volatile uint32_t length;
- volatile uint32_t soFar;
- serial_manager_transmission_mode_t mode;
- serial_manager_status_t status;
-} serial_manager_transfer_t;
-#endif
-
-/* write handle structure */
-typedef struct _serial_manager_send_handle
-{
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- list_element_t link; /*!< list element of the link */
- serial_manager_transfer_t transfer;
-#endif
- struct _serial_manager_handle *serialManagerHandle;
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- serial_manager_callback_t callback;
- void *callbackParam;
- uint32_t tag;
-#endif
-} serial_manager_write_handle_t;
-
-typedef serial_manager_write_handle_t serial_manager_read_handle_t;
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-/* receive state structure */
-typedef struct _serial_manager_read_ring_buffer
-{
- uint8_t *ringBuffer;
- uint32_t ringBufferSize;
- volatile uint32_t ringHead;
- volatile uint32_t ringTail;
-} serial_manager_read_ring_buffer_t;
-#endif
-
-#if defined(__CC_ARM)
-#pragma anon_unions
-#endif
-/* The serial manager handle structure */
-typedef struct _serial_manager_handle
-{
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- list_label_t runningWriteHandleHead; /*!< The queue of running write handle */
- list_label_t completedWriteHandleHead; /*!< The queue of completed write handle */
-#endif
- serial_manager_read_handle_t *volatile openedReadHandleHead;
- volatile uint32_t openedWriteHandleCount;
- union
- {
- uint32_t lowLevelhandleBuffer[1];
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- uint8_t uartHandleBuffer[SERIAL_PORT_UART_HANDLE_SIZE];
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- uint8_t usbcdcHandleBuffer[SERIAL_PORT_USB_CDC_HANDLE_SIZE];
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- uint8_t swoHandleBuffer[SERIAL_PORT_SWO_HANDLE_SIZE];
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- uint8_t usbcdcVirtualHandleBuffer[SERIAL_PORT_USB_VIRTUAL_HANDLE_SIZE];
-#endif
- };
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- serial_manager_read_ring_buffer_t ringBuffer;
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
- common_task_message_t commontaskMsg;
-#else
- OSA_EVENT_HANDLE_DEFINE(event); /*!< Event instance */
- OSA_TASK_HANDLE_DEFINE(taskId); /*!< Task handle */
-#endif
-
-#endif
-
-#endif
-
- serial_port_type_t type;
-} serial_manager_handle_t;
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-static void SerialManager_Task(void *param);
-#endif
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-
-#else
- /*
- * \brief Defines the serial manager task's stack
- */
-OSA_TASK_DEFINE(SerialManager_Task, SERIAL_MANAGER_TASK_PRIORITY, 1, SERIAL_MANAGER_TASK_STACK_SIZE, false);
-#endif
-
-#endif
-
-#endif
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-static void SerialManager_AddTail(list_label_t *queue, serial_manager_write_handle_t *node)
-{
- (void)LIST_AddTail(queue, &node->link);
-}
-
-static void SerialManager_RemoveHead(list_label_t *queue)
-{
- (void)LIST_RemoveHead(queue);
-}
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-static serial_manager_status_t SerialManager_StartWriting(serial_manager_handle_t *handle)
-{
- serial_manager_status_t status = kStatus_SerialManager_Error;
- serial_manager_write_handle_t *writeHandle =
- (serial_manager_write_handle_t *)(void *)LIST_GetHead(&handle->runningWriteHandleHead);
-
- if (writeHandle != NULL)
- {
- switch (handle->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- status = Serial_UartWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- writeHandle->transfer.buffer, writeHandle->transfer.length);
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- status = Serial_UsbCdcWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- writeHandle->transfer.buffer, writeHandle->transfer.length);
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- status = Serial_SwoWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- writeHandle->transfer.buffer, writeHandle->transfer.length);
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- status = Serial_UsbCdcVirtualWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- writeHandle->transfer.buffer, writeHandle->transfer.length);
- break;
-#endif
- default:
- status = kStatus_SerialManager_Error;
- break;
- }
- }
- return status;
-}
-
-static serial_manager_status_t SerialManager_StartReading(serial_manager_handle_t *handle,
- serial_manager_read_handle_t *readHandle,
- uint8_t *buffer,
- uint32_t length)
-{
- serial_manager_status_t status = kStatus_SerialManager_Error;
-
- if (NULL != readHandle)
- {
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- if (handle->type == kSerialPort_UsbCdc)
- {
- status = Serial_UsbCdcRead(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- if (handle->type == kSerialPort_UsbCdcVirtual)
- {
- status = Serial_UsbCdcVirtualRead(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
-#endif
- }
- return status;
-}
-
-#else /*SERIAL_MANAGER_NON_BLOCKING_MODE > 0U*/
-
-static serial_manager_status_t SerialManager_StartWriting(serial_manager_handle_t *handle,
- serial_manager_write_handle_t *writeHandle,
- uint8_t *buffer,
- uint32_t length)
-{
- serial_manager_status_t status = kStatus_SerialManager_Error;
-
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- if (kSerialPort_Uart == handle->type) /* Serial port UART */
- {
- status = Serial_UartWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- if (kSerialPort_UsbCdc == handle->type) /* Serial port UsbCdc */
- {
- status = Serial_UsbCdcWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- if (kSerialPort_Swo == handle->type) /* Serial port SWO */
- {
- status = Serial_SwoWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- if (kSerialPort_UsbCdcVirtual == handle->type) /* Serial port UsbCdcVirtual */
- {
- status = Serial_UsbCdcVirtualWrite(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
- {
- /*MISRA rule*/
- }
- return status;
-}
-
-static serial_manager_status_t SerialManager_StartReading(serial_manager_handle_t *handle,
- serial_manager_read_handle_t *readHandle,
- uint8_t *buffer,
- uint32_t length)
-{
- serial_manager_status_t status = kStatus_SerialManager_Error;
-
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- if (kSerialPort_Uart == handle->type) /* Serial port UART */
- {
- status = Serial_UartRead(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- if (kSerialPort_UsbCdc == handle->type) /* Serial port UsbCdc */
- {
- status = Serial_UsbCdcRead(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- if (kSerialPort_Swo == handle->type) /* Serial port SWO */
- {
- status = Serial_SwoRead(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
- else
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- if (kSerialPort_UsbCdcVirtual == handle->type) /* Serial port UsbCdcVirtual */
- {
- status = Serial_UsbCdcVirtualRead(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), buffer, length);
- }
-#endif
- {
- /*MISRA rule*/
- }
- return status;
-}
-#endif /*SERIAL_MANAGER_NON_BLOCKING_MODE > 0U*/
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-static void SerialManager_IsrFunction(serial_manager_handle_t *handle)
-{
- uint32_t regPrimask = DisableGlobalIRQ();
- switch (handle->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- Serial_UartIsrFunction(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- Serial_UsbCdcIsrFunction(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- Serial_SwoIsrFunction(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- Serial_UsbCdcVirtualIsrFunction(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
- default:
- /*MISRA rule 16.4*/
- break;
- }
- EnableGlobalIRQ(regPrimask);
-}
-
-static void SerialManager_Task(void *param)
-{
- serial_manager_handle_t *handle = (serial_manager_handle_t *)param;
- serial_manager_write_handle_t *serialWriteHandle;
- serial_manager_read_handle_t *serialReadHandle;
- uint32_t primask;
- serial_manager_callback_message_t msg;
-
- if (NULL != handle)
- {
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-#else
- osa_event_flags_t ev = 0;
-
- do
- {
- if (KOSA_StatusSuccess ==
- OSA_EventWait((osa_event_handle_t)handle->event, osaEventFlagsAll_c, false, osaWaitForever_c, &ev))
- {
- if (ev & SERIAL_EVENT_DATA_SENT)
-#endif
-
-#endif
- {
- serialWriteHandle =
- (serial_manager_write_handle_t *)(void *)LIST_GetHead(&handle->completedWriteHandleHead);
- while (NULL != serialWriteHandle)
- {
- SerialManager_RemoveHead(&handle->completedWriteHandleHead);
- msg.buffer = serialWriteHandle->transfer.buffer;
- msg.length = serialWriteHandle->transfer.soFar;
- serialWriteHandle->transfer.buffer = NULL;
- if (NULL != serialWriteHandle->callback)
- {
- serialWriteHandle->callback(serialWriteHandle->callbackParam, &msg,
- serialWriteHandle->transfer.status);
- }
- serialWriteHandle =
- (serial_manager_write_handle_t *)(void *)LIST_GetHead(&handle->completedWriteHandleHead);
- }
- }
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-#else
- if (ev & SERIAL_EVENT_DATA_RECEIVED)
-#endif
-
-#endif
- {
- primask = DisableGlobalIRQ();
- serialReadHandle = handle->openedReadHandleHead;
- EnableGlobalIRQ(primask);
-
- if (NULL != serialReadHandle)
- {
- if (NULL != serialReadHandle->transfer.buffer)
- {
- if (serialReadHandle->transfer.soFar >= serialReadHandle->transfer.length)
- {
- msg.buffer = serialReadHandle->transfer.buffer;
- msg.length = serialReadHandle->transfer.soFar;
- serialReadHandle->transfer.buffer = NULL;
- if (NULL != serialReadHandle->callback)
- {
- serialReadHandle->callback(serialReadHandle->callbackParam, &msg,
- serialReadHandle->transfer.status);
- }
- }
- }
- }
- }
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-#else
- }
- } while (gUseRtos_c);
-#endif
-
-#endif
- }
-}
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-static void SerialManager_TxCallback(void *callbackParam,
- serial_manager_callback_message_t *message,
- serial_manager_status_t status)
-{
- serial_manager_handle_t *handle;
- serial_manager_write_handle_t *writeHandle;
-
- assert(callbackParam);
- assert(message);
-
- handle = (serial_manager_handle_t *)callbackParam;
-
- writeHandle = (serial_manager_write_handle_t *)(void *)LIST_GetHead(&handle->runningWriteHandleHead);
-
- if (NULL != writeHandle)
- {
- SerialManager_RemoveHead(&handle->runningWriteHandleHead);
- (void)SerialManager_StartWriting(handle);
- writeHandle->transfer.soFar = message->length;
- writeHandle->transfer.status = status;
- if (kSerialManager_TransmissionNonBlocking == writeHandle->transfer.mode)
- {
- SerialManager_AddTail(&handle->completedWriteHandleHead, writeHandle);
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
- handle->commontaskMsg.callback = SerialManager_Task;
- handle->commontaskMsg.callbackParam = handle;
- COMMON_TASK_post_message(&handle->commontaskMsg);
-#else
- (void)OSA_EventSet((osa_event_handle_t)handle->event, SERIAL_EVENT_DATA_SENT);
-#endif
-
-#else
- SerialManager_Task(handle);
-#endif
- }
- else
- {
- writeHandle->transfer.buffer = NULL;
- }
- }
-}
-
-static void SerialManager_RxCallback(void *callbackParam,
- serial_manager_callback_message_t *message,
- serial_manager_status_t status)
-{
- serial_manager_handle_t *handle;
- uint32_t ringBufferLength;
- uint32_t primask;
-
- assert(callbackParam);
- assert(message);
-
- handle = (serial_manager_handle_t *)callbackParam;
-
- status = kStatus_SerialManager_Notify;
-
- for (uint32_t i = 0; i < message->length; i++)
- {
- handle->ringBuffer.ringBuffer[handle->ringBuffer.ringHead++] = message->buffer[i];
- if (handle->ringBuffer.ringHead >= handle->ringBuffer.ringBufferSize)
- {
- handle->ringBuffer.ringHead = 0U;
- }
- if (handle->ringBuffer.ringHead == handle->ringBuffer.ringTail)
- {
- status = kStatus_SerialManager_RingBufferOverflow;
- handle->ringBuffer.ringTail++;
- if (handle->ringBuffer.ringTail >= handle->ringBuffer.ringBufferSize)
- {
- handle->ringBuffer.ringTail = 0U;
- }
- }
- }
-
- ringBufferLength = handle->ringBuffer.ringHead + handle->ringBuffer.ringBufferSize - handle->ringBuffer.ringTail;
- ringBufferLength = ringBufferLength % handle->ringBuffer.ringBufferSize;
-
- primask = DisableGlobalIRQ();
- if ((NULL != handle->openedReadHandleHead) && (NULL != handle->openedReadHandleHead->transfer.buffer))
- {
- if (handle->openedReadHandleHead->transfer.length > handle->openedReadHandleHead->transfer.soFar)
- {
- uint32_t remainLength =
- handle->openedReadHandleHead->transfer.length - handle->openedReadHandleHead->transfer.soFar;
- for (uint32_t i = 0; i < MIN(ringBufferLength, remainLength); i++)
- {
- handle->openedReadHandleHead->transfer.buffer[handle->openedReadHandleHead->transfer.soFar] =
- handle->ringBuffer.ringBuffer[handle->ringBuffer.ringTail];
- handle->ringBuffer.ringTail++;
- handle->openedReadHandleHead->transfer.soFar++;
- if (handle->ringBuffer.ringTail >= handle->ringBuffer.ringBufferSize)
- {
- handle->ringBuffer.ringTail = 0U;
- }
- }
- ringBufferLength = ringBufferLength - MIN(ringBufferLength, remainLength);
- }
-
- if (handle->openedReadHandleHead->transfer.length > handle->openedReadHandleHead->transfer.soFar)
- {
- }
- else
- {
- if (kSerialManager_TransmissionBlocking == handle->openedReadHandleHead->transfer.mode)
- {
- handle->openedReadHandleHead->transfer.buffer = NULL;
- }
- else
- {
- handle->openedReadHandleHead->transfer.status = kStatus_SerialManager_Success;
-
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
- handle->commontaskMsg.callback = SerialManager_Task;
- handle->commontaskMsg.callbackParam = handle;
- COMMON_TASK_post_message(&handle->commontaskMsg);
-#else
- (void)OSA_EventSet((osa_event_handle_t)handle->event, SERIAL_EVENT_DATA_RECEIVED);
-#endif
-
-#else
- SerialManager_Task(handle);
-#endif
- }
- }
- }
-
- if (0U != ringBufferLength)
- {
- message->buffer = NULL;
- message->length = ringBufferLength;
- if ((NULL != handle->openedReadHandleHead) && (NULL != handle->openedReadHandleHead->callback))
- {
- handle->openedReadHandleHead->callback(handle->openedReadHandleHead->callbackParam, message, status);
- }
- }
-
- ringBufferLength = handle->ringBuffer.ringBufferSize - 1U - ringBufferLength;
-
- if (NULL != handle->openedReadHandleHead)
- {
- (void)SerialManager_StartReading(handle, handle->openedReadHandleHead, NULL, ringBufferLength);
- }
- EnableGlobalIRQ(primask);
-}
-
-static serial_manager_status_t SerialManager_Write(serial_write_handle_t writeHandle,
- uint8_t *buffer,
- uint32_t length,
- serial_manager_transmission_mode_t mode)
-{
- serial_manager_write_handle_t *serialWriteHandle;
- serial_manager_handle_t *handle;
- serial_manager_status_t status = kStatus_SerialManager_Success;
- uint32_t primask;
- uint8_t isEmpty = 0U;
-
- assert(writeHandle);
- assert(buffer);
- assert(length);
-
- serialWriteHandle = (serial_manager_write_handle_t *)writeHandle;
- handle = serialWriteHandle->serialManagerHandle;
-
- assert(handle);
- assert(SERIAL_MANAGER_WRITE_TAG == serialWriteHandle->tag);
- assert(!((kSerialManager_TransmissionNonBlocking == mode) && (NULL == serialWriteHandle->callback)));
-
- primask = DisableGlobalIRQ();
- if (NULL != serialWriteHandle->transfer.buffer)
- {
- EnableGlobalIRQ(primask);
- return kStatus_SerialManager_Busy;
- }
- serialWriteHandle->transfer.buffer = buffer;
- serialWriteHandle->transfer.length = length;
- serialWriteHandle->transfer.soFar = 0U;
- serialWriteHandle->transfer.mode = mode;
-
- if (NULL == LIST_GetHead(&handle->runningWriteHandleHead))
- {
- isEmpty = 1U;
- }
- SerialManager_AddTail(&handle->runningWriteHandleHead, serialWriteHandle);
- EnableGlobalIRQ(primask);
-
- if (0U != isEmpty)
- {
- status = SerialManager_StartWriting(handle);
- if ((serial_manager_status_t)kStatus_SerialManager_Success != status)
- {
-#if (USB_CDC_SERIAL_MANAGER_RUN_NO_HOST == 1)
- if (status == kStatus_SerialManager_NotConnected)
- {
- SerialManager_RemoveHead(&handle->runningWriteHandleHead);
- serialWriteHandle->transfer.buffer = 0;
- serialWriteHandle->transfer.length = 0;
- }
-#endif /* USB_CDC_SERIAL_MANAGER_RUN_NO_HOST == 1 */
- return status;
- }
- }
-
- if (kSerialManager_TransmissionBlocking == mode)
- {
- while (serialWriteHandle->transfer.length > serialWriteHandle->transfer.soFar)
- {
-#if defined(__GIC_PRIO_BITS)
- if (0x13 == (__get_CPSR() & CPSR_M_Msk))
-#else
- if (0U != __get_IPSR())
-#endif
- {
- SerialManager_IsrFunction(handle);
- }
- }
- }
- return kStatus_SerialManager_Success;
-}
-
-static serial_manager_status_t SerialManager_Read(serial_read_handle_t readHandle,
- uint8_t *buffer,
- uint32_t length,
- serial_manager_transmission_mode_t mode,
- uint32_t *receivedLength)
-{
- serial_manager_read_handle_t *serialReadHandle;
- serial_manager_handle_t *handle;
- uint32_t dataLength;
- uint32_t primask;
-
- assert(readHandle);
- assert(buffer);
- assert(length);
-
- serialReadHandle = (serial_manager_read_handle_t *)readHandle;
- handle = serialReadHandle->serialManagerHandle;
-
- assert(handle);
- assert(SERIAL_MANAGER_READ_TAG == serialReadHandle->tag);
- assert(!((kSerialManager_TransmissionNonBlocking == mode) && (NULL == serialReadHandle->callback)));
-
- primask = DisableGlobalIRQ();
- if (NULL != serialReadHandle->transfer.buffer)
- {
- EnableGlobalIRQ(primask);
- return kStatus_SerialManager_Busy;
- }
- serialReadHandle->transfer.buffer = buffer;
- serialReadHandle->transfer.length = length;
- serialReadHandle->transfer.soFar = 0U;
- serialReadHandle->transfer.mode = mode;
-
- dataLength = handle->ringBuffer.ringHead + handle->ringBuffer.ringBufferSize - handle->ringBuffer.ringTail;
- dataLength = dataLength % handle->ringBuffer.ringBufferSize;
-
- for (serialReadHandle->transfer.soFar = 0U; serialReadHandle->transfer.soFar < MIN(dataLength, length);
- serialReadHandle->transfer.soFar++)
- {
- buffer[serialReadHandle->transfer.soFar] = handle->ringBuffer.ringBuffer[handle->ringBuffer.ringTail];
- handle->ringBuffer.ringTail++;
- if (handle->ringBuffer.ringTail >= handle->ringBuffer.ringBufferSize)
- {
- handle->ringBuffer.ringTail = 0U;
- }
- }
-
- dataLength = handle->ringBuffer.ringHead + handle->ringBuffer.ringBufferSize - handle->ringBuffer.ringTail;
- dataLength = dataLength % handle->ringBuffer.ringBufferSize;
- dataLength = handle->ringBuffer.ringBufferSize - 1U - dataLength;
-
- (void)SerialManager_StartReading(handle, readHandle, NULL, dataLength);
-
- if (NULL != receivedLength)
- {
- *receivedLength = serialReadHandle->transfer.soFar;
- serialReadHandle->transfer.buffer = NULL;
- EnableGlobalIRQ(primask);
- }
- else
- {
- if (serialReadHandle->transfer.soFar >= serialReadHandle->transfer.length)
- {
- serialReadHandle->transfer.buffer = NULL;
- EnableGlobalIRQ(primask);
- if (kSerialManager_TransmissionNonBlocking == mode)
- {
- if (NULL != serialReadHandle->callback)
- {
- serial_manager_callback_message_t msg;
- msg.buffer = buffer;
- msg.length = serialReadHandle->transfer.soFar;
- serialReadHandle->callback(serialReadHandle->callbackParam, &msg, kStatus_SerialManager_Success);
- }
- }
- }
- else
- {
- EnableGlobalIRQ(primask);
- }
-
- if (kSerialManager_TransmissionBlocking == mode)
- {
- while (serialReadHandle->transfer.length > serialReadHandle->transfer.soFar)
- {
- }
- }
- }
-
- return kStatus_SerialManager_Success;
-}
-
-#else
-
-static serial_manager_status_t SerialManager_Write(serial_write_handle_t writeHandle, uint8_t *buffer, uint32_t length)
-{
- serial_manager_write_handle_t *serialWriteHandle;
- serial_manager_handle_t *handle;
-
- assert(writeHandle);
- assert(buffer);
- assert(length);
-
- serialWriteHandle = (serial_manager_write_handle_t *)writeHandle;
- handle = serialWriteHandle->serialManagerHandle;
-
- assert(handle);
-
- return SerialManager_StartWriting(handle, serialWriteHandle, buffer, length);
-}
-
-static serial_manager_status_t SerialManager_Read(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length)
-{
- serial_manager_read_handle_t *serialReadHandle;
- serial_manager_handle_t *handle;
-
- assert(readHandle);
- assert(buffer);
- assert(length);
-
- serialReadHandle = (serial_manager_read_handle_t *)readHandle;
- handle = serialReadHandle->serialManagerHandle;
-
- assert(handle);
-
- return SerialManager_StartReading(handle, serialReadHandle, buffer, length);
-}
-#endif
-
-serial_manager_status_t SerialManager_Init(serial_handle_t serialHandle, serial_manager_config_t *config)
-{
- serial_manager_handle_t *handle;
- serial_manager_status_t status = kStatus_SerialManager_Error;
-
- assert(config);
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- assert(config->ringBuffer);
- assert(config->ringBufferSize);
-#endif
- assert(serialHandle);
- assert(SERIAL_MANAGER_HANDLE_SIZE >= sizeof(serial_manager_handle_t));
-
- handle = (serial_manager_handle_t *)serialHandle;
-
- (void)memset(handle, 0, SERIAL_MANAGER_HANDLE_SIZE);
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-
- COMMON_TASK_init();
-
-#else
- if (KOSA_StatusSuccess != OSA_EventCreate((osa_event_handle_t)handle->event, true))
- {
- return kStatus_SerialManager_Error;
- }
-
- if (KOSA_StatusSuccess != OSA_TaskCreate((osa_task_handle_t)handle->taskId, OSA_TASK(SerialManager_Task), handle))
- {
- return kStatus_SerialManager_Error;
- }
-#endif
-
-#endif
-
-#endif
-
- handle->type = config->type;
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- handle->ringBuffer.ringBuffer = config->ringBuffer;
- handle->ringBuffer.ringBufferSize = config->ringBufferSize;
-#endif
-
- switch (config->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- status = Serial_UartInit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), config->portConfig);
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- if ((serial_manager_status_t)kStatus_SerialManager_Success == status)
- {
- status = Serial_UartInstallTxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_TxCallback, handle);
- if ((serial_manager_status_t)kStatus_SerialManager_Success == status)
- {
- status = Serial_UartInstallRxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_RxCallback, handle);
- }
- }
-#endif
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- status = Serial_UsbCdcInit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), config->portConfig);
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- if (kStatus_SerialManager_Success == status)
- {
- status = Serial_UsbCdcInstallTxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_TxCallback, handle);
- if (kStatus_SerialManager_Success == status)
- {
- status = Serial_UsbCdcInstallRxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_RxCallback, handle);
- }
- }
-#endif
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- status = Serial_SwoInit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), config->portConfig);
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- if (kStatus_SerialManager_Success == status)
- {
- status = Serial_SwoInstallTxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_TxCallback, handle);
- }
-#endif
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- status = Serial_UsbCdcVirtualInit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]), config->portConfig);
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- if (kStatus_SerialManager_Success == status)
- {
- status = Serial_UsbCdcVirtualInstallTxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_TxCallback, handle);
- if (kStatus_SerialManager_Success == status)
- {
- status = Serial_UsbCdcVirtualInstallRxCallback(((serial_handle_t)&handle->lowLevelhandleBuffer[0]),
- SerialManager_RxCallback, handle);
- }
- }
-#endif
- break;
-#endif
- default:
- /*MISRA rule 16.4*/
- break;
- }
-
- return status;
-}
-
-serial_manager_status_t SerialManager_Deinit(serial_handle_t serialHandle)
-{
- serial_manager_handle_t *handle;
- uint32_t primask;
-
- assert(serialHandle);
-
- handle = (serial_manager_handle_t *)serialHandle;
-
- primask = DisableGlobalIRQ();
- if ((NULL != handle->openedReadHandleHead) || (0U != handle->openedWriteHandleCount))
- {
- EnableGlobalIRQ(primask);
- return kStatus_SerialManager_Busy;
- }
- EnableGlobalIRQ(primask);
-
- switch (handle->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- (void)Serial_UartDeinit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- (void)Serial_UsbCdcDeinit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- (void)Serial_SwoDeinit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- (void)Serial_UsbCdcVirtualDeinit(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
- default:
- /*MISRA rule 16.4*/
- break;
- }
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
-#else
- OSA_EventDestroy((osa_event_handle_t)handle->event);
- OSA_TaskDestroy((osa_task_handle_t)handle->taskId);
-#endif
-
-#endif
-
-#endif
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_OpenWriteHandle(serial_handle_t serialHandle, serial_write_handle_t writeHandle)
-{
- serial_manager_handle_t *handle;
- serial_manager_write_handle_t *serialWriteHandle;
- uint32_t primask;
-
- assert(serialHandle);
- assert(writeHandle);
- assert(SERIAL_MANAGER_WRITE_HANDLE_SIZE >= sizeof(serial_manager_write_handle_t));
-
- handle = (serial_manager_handle_t *)serialHandle;
- serialWriteHandle = (serial_manager_write_handle_t *)writeHandle;
-
- (void)memset(writeHandle, 0, SERIAL_MANAGER_WRITE_HANDLE_SIZE);
-
- primask = DisableGlobalIRQ();
- handle->openedWriteHandleCount++;
- EnableGlobalIRQ(primask);
-
- serialWriteHandle->serialManagerHandle = handle;
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- serialWriteHandle->tag = SERIAL_MANAGER_WRITE_TAG;
-#endif
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_CloseWriteHandle(serial_write_handle_t writeHandle)
-{
- serial_manager_handle_t *handle;
- serial_manager_write_handle_t *serialWriteHandle;
- uint32_t primask;
-
- assert(writeHandle);
-
- serialWriteHandle = (serial_manager_write_handle_t *)writeHandle;
- handle = (serial_manager_handle_t *)(void *)serialWriteHandle->serialManagerHandle;
-
- assert(handle);
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- assert(SERIAL_MANAGER_WRITE_TAG == serialWriteHandle->tag);
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- (void)SerialManager_CancelWriting(writeHandle);
-#endif
- primask = DisableGlobalIRQ();
- if (handle->openedWriteHandleCount > 0U)
- {
- handle->openedWriteHandleCount--;
- }
- EnableGlobalIRQ(primask);
-
- (void)memset(writeHandle, 0, SERIAL_MANAGER_WRITE_HANDLE_SIZE);
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_OpenReadHandle(serial_handle_t serialHandle, serial_read_handle_t readHandle)
-{
- serial_manager_handle_t *handle;
- serial_manager_read_handle_t *serialReadHandle;
- uint32_t primask;
-
- assert(serialHandle);
- assert(readHandle);
- assert(SERIAL_MANAGER_READ_HANDLE_SIZE >= sizeof(serial_manager_read_handle_t));
-
- handle = (serial_manager_handle_t *)serialHandle;
- serialReadHandle = (serial_manager_read_handle_t *)readHandle;
-
- primask = DisableGlobalIRQ();
- if (handle->openedReadHandleHead != NULL)
- {
- EnableGlobalIRQ(primask);
- return kStatus_SerialManager_Busy;
- }
- handle->openedReadHandleHead = serialReadHandle;
- EnableGlobalIRQ(primask);
-
- (void)memset(readHandle, 0, SERIAL_MANAGER_READ_HANDLE_SIZE);
-
- serialReadHandle->serialManagerHandle = handle;
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- serialReadHandle->tag = SERIAL_MANAGER_READ_TAG;
-#endif
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_CloseReadHandle(serial_read_handle_t readHandle)
-{
- serial_manager_handle_t *handle;
- serial_manager_read_handle_t *serialReadHandle;
- uint32_t primask;
-
- assert(readHandle);
-
- serialReadHandle = (serial_manager_read_handle_t *)readHandle;
- handle = (serial_manager_handle_t *)(void *)serialReadHandle->serialManagerHandle;
-
- assert(handle && (handle->openedReadHandleHead == serialReadHandle));
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- assert(SERIAL_MANAGER_READ_TAG == serialReadHandle->tag);
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- (void)SerialManager_CancelReading(readHandle);
-#endif
-
- primask = DisableGlobalIRQ();
- handle->openedReadHandleHead = NULL;
- EnableGlobalIRQ(primask);
-
- (void)memset(readHandle, 0, SERIAL_MANAGER_READ_HANDLE_SIZE);
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_WriteBlocking(serial_write_handle_t writeHandle, uint8_t *buffer, uint32_t length)
-{
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- return SerialManager_Write(writeHandle, buffer, length, kSerialManager_TransmissionBlocking);
-#else
- return SerialManager_Write(writeHandle, buffer, length);
-#endif
-}
-
-serial_manager_status_t SerialManager_ReadBlocking(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length)
-{
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- return SerialManager_Read(readHandle, buffer, length, kSerialManager_TransmissionBlocking, NULL);
-#else
- return SerialManager_Read(readHandle, buffer, length);
-#endif
-}
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-serial_manager_status_t SerialManager_WriteNonBlocking(serial_write_handle_t writeHandle,
- uint8_t *buffer,
- uint32_t length)
-{
- return SerialManager_Write(writeHandle, buffer, length, kSerialManager_TransmissionNonBlocking);
-}
-
-serial_manager_status_t SerialManager_ReadNonBlocking(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length)
-{
- return SerialManager_Read(readHandle, buffer, length, kSerialManager_TransmissionNonBlocking, NULL);
-}
-
-serial_manager_status_t SerialManager_CancelWriting(serial_write_handle_t writeHandle)
-{
- serial_manager_write_handle_t *serialWriteHandle;
- uint32_t primask;
- uint8_t isNotUsed = 0;
-
- assert(writeHandle);
-
- serialWriteHandle = (serial_manager_write_handle_t *)writeHandle;
-
- assert(serialWriteHandle->serialManagerHandle);
- assert(SERIAL_MANAGER_WRITE_TAG == serialWriteHandle->tag);
-
- if ((NULL != serialWriteHandle->transfer.buffer) &&
- (kSerialManager_TransmissionBlocking == serialWriteHandle->transfer.mode))
- {
- return kStatus_SerialManager_Error;
- }
-
- primask = DisableGlobalIRQ();
- if (serialWriteHandle != (serial_manager_write_handle_t *)(void *)LIST_GetHead(
- &serialWriteHandle->serialManagerHandle->runningWriteHandleHead))
- {
- (void)LIST_RemoveElement(&serialWriteHandle->link);
- isNotUsed = 1;
- }
- EnableGlobalIRQ(primask);
-
- if (0U != isNotUsed)
- {
- serialWriteHandle->transfer.soFar = 0;
- serialWriteHandle->transfer.status = kStatus_SerialManager_Canceled;
-
- SerialManager_AddTail(&serialWriteHandle->serialManagerHandle->completedWriteHandleHead, serialWriteHandle);
-#if defined(OSA_USED)
-
-#if (defined(SERIAL_MANAGER_USE_COMMON_TASK) && (SERIAL_MANAGER_USE_COMMON_TASK > 0U))
- serialWriteHandle->serialManagerHandle->commontaskMsg.callback = SerialManager_Task;
- serialWriteHandle->serialManagerHandle->commontaskMsg.callbackParam = serialWriteHandle->serialManagerHandle;
- COMMON_TASK_post_message(&serialWriteHandle->serialManagerHandle->commontaskMsg);
-#else
- (void)OSA_EventSet((osa_event_handle_t)serialWriteHandle->serialManagerHandle->event, SERIAL_EVENT_DATA_SENT);
-#endif
-
-#else
- SerialManager_Task(serialWriteHandle->serialManagerHandle);
-#endif
- }
- else
- {
- switch (serialWriteHandle->serialManagerHandle->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- (void)Serial_UartCancelWrite(
- ((serial_handle_t)&serialWriteHandle->serialManagerHandle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- (void)Serial_UsbCdcCancelWrite(
- ((serial_handle_t)&serialWriteHandle->serialManagerHandle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- (void)Serial_SwoCancelWrite(
- ((serial_handle_t)&serialWriteHandle->serialManagerHandle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- (void)Serial_UsbCdcVirtualCancelWrite(
- ((serial_handle_t)&serialWriteHandle->serialManagerHandle->lowLevelhandleBuffer[0]));
- break;
-#endif
- default:
- /*MISRA rule 16.4*/
- break;
- }
- }
-
- (void)SerialManager_StartWriting(serialWriteHandle->serialManagerHandle);
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_CancelReading(serial_read_handle_t readHandle)
-{
- serial_manager_read_handle_t *serialReadHandle;
- serial_manager_callback_message_t msg;
- uint8_t *buffer;
- uint32_t primask;
-
- assert(readHandle);
-
- serialReadHandle = (serial_manager_read_handle_t *)readHandle;
-
- assert(SERIAL_MANAGER_READ_TAG == serialReadHandle->tag);
-
- if ((NULL != serialReadHandle->transfer.buffer) &&
- (kSerialManager_TransmissionBlocking == serialReadHandle->transfer.mode))
- {
- return kStatus_SerialManager_Error;
- }
-
- primask = DisableGlobalIRQ();
- buffer = serialReadHandle->transfer.buffer;
- serialReadHandle->transfer.buffer = NULL;
- serialReadHandle->transfer.length = 0;
- msg.buffer = buffer;
- msg.length = serialReadHandle->transfer.soFar;
- EnableGlobalIRQ(primask);
-
- if (NULL != buffer)
- {
- if (NULL != serialReadHandle->callback)
- {
- serialReadHandle->callback(serialReadHandle->callbackParam, &msg, kStatus_SerialManager_Canceled);
- }
- }
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_TryRead(serial_read_handle_t readHandle,
- uint8_t *buffer,
- uint32_t length,
- uint32_t *receivedLength)
-{
- assert(receivedLength);
-
- return SerialManager_Read(readHandle, buffer, length, kSerialManager_TransmissionBlocking, receivedLength);
-}
-
-serial_manager_status_t SerialManager_InstallTxCallback(serial_write_handle_t writeHandle,
- serial_manager_callback_t callback,
- void *callbackParam)
-{
- serial_manager_write_handle_t *serialWriteHandle;
-
- assert(writeHandle);
-
- serialWriteHandle = (serial_manager_write_handle_t *)writeHandle;
-
- assert(SERIAL_MANAGER_WRITE_TAG == serialWriteHandle->tag);
-
- serialWriteHandle->callbackParam = callbackParam;
- serialWriteHandle->callback = callback;
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t SerialManager_InstallRxCallback(serial_read_handle_t readHandle,
- serial_manager_callback_t callback,
- void *callbackParam)
-{
- serial_manager_read_handle_t *serialReadHandle;
-
- assert(readHandle);
-
- serialReadHandle = (serial_manager_read_handle_t *)readHandle;
-
- assert(SERIAL_MANAGER_READ_TAG == serialReadHandle->tag);
-
- serialReadHandle->callbackParam = callbackParam;
- serialReadHandle->callback = callback;
-
- return kStatus_SerialManager_Success;
-}
-#endif
-
-serial_manager_status_t SerialManager_EnterLowpower(serial_handle_t serialHandle)
-{
- serial_manager_handle_t *handle;
- serial_manager_status_t status = kStatus_SerialManager_Error;
-
- assert(serialHandle);
-
- handle = (serial_manager_handle_t *)serialHandle;
-
- switch (handle->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- status = Serial_UartEnterLowpower(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- break;
-#endif
- default:
- /*MISRA rule 16.4*/
- break;
- }
- return status;
-}
-
-serial_manager_status_t SerialManager_ExitLowpower(serial_handle_t serialHandle)
-{
- serial_manager_handle_t *handle;
- serial_manager_status_t status = kStatus_SerialManager_Error;
-
- assert(serialHandle);
-
- handle = (serial_manager_handle_t *)serialHandle;
-
- switch (handle->type)
- {
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
- case kSerialPort_Uart:
- status = Serial_UartExitLowpower(((serial_handle_t)&handle->lowLevelhandleBuffer[0]));
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
- case kSerialPort_UsbCdc:
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
- case kSerialPort_Swo:
- break;
-#endif
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
- case kSerialPort_UsbCdcVirtual:
- break;
-#endif
- default:
- /*MISRA rule 16.4*/
- break;
- }
- return status;
-}
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.h b/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.h
deleted file mode 100755
index 888ec374f..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_manager.h
+++ /dev/null
@@ -1,648 +0,0 @@
-/*
- * Copyright 2018-2020 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __SERIAL_MANAGER_H__
-#define __SERIAL_MANAGER_H__
-
-/*!
- * @addtogroup serialmanager
- * @{
- */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-/*! @brief Enable or disable serial manager non-blocking mode (1 - enable, 0 - disable) */
-#ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
-#ifndef SERIAL_MANAGER_NON_BLOCKING_MODE
-#define SERIAL_MANAGER_NON_BLOCKING_MODE (1U)
-#endif
-#else
-#ifndef SERIAL_MANAGER_NON_BLOCKING_MODE
-#define SERIAL_MANAGER_NON_BLOCKING_MODE (0U)
-#endif
-#endif
-
-/*! @brief Enable or disable uart port (1 - enable, 0 - disable) */
-#ifndef SERIAL_PORT_TYPE_UART
-#define SERIAL_PORT_TYPE_UART (0U)
-#endif
-
-/*! @brief Enable or disable USB CDC port (1 - enable, 0 - disable) */
-#ifndef SERIAL_PORT_TYPE_USBCDC
-#define SERIAL_PORT_TYPE_USBCDC (0U)
-#endif
-
-/*! @brief Enable or disable SWO port (1 - enable, 0 - disable) */
-#ifndef SERIAL_PORT_TYPE_SWO
-#define SERIAL_PORT_TYPE_SWO (0U)
-#endif
-
-/*! @brief Enable or disable USB CDC virtual port (1 - enable, 0 - disable) */
-#ifndef SERIAL_PORT_TYPE_USBCDC_VIRTUAL
-#define SERIAL_PORT_TYPE_USBCDC_VIRTUAL (0U)
-#endif
-
-/*! @brief Set serial manager write handle size */
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#define SERIAL_MANAGER_WRITE_HANDLE_SIZE (44U)
-#define SERIAL_MANAGER_READ_HANDLE_SIZE (44U)
-#else
-#define SERIAL_MANAGER_WRITE_HANDLE_SIZE (4U)
-#define SERIAL_MANAGER_READ_HANDLE_SIZE (4U)
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
-#include "serial_port_uart.h"
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
-
-#if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#error The serial manager blocking mode cannot be supported for USB CDC.
-#endif
-
-#include "serial_port_usb.h"
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
-#include "serial_port_swo.h"
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
-
-#if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#error The serial manager blocking mode cannot be supported for USB CDC.
-#endif
-
-#include "serial_port_usb_virtual.h"
-#endif
-
-#define SERIAL_MANAGER_HANDLE_SIZE_TEMP 0U
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
-
-#if (SERIAL_PORT_UART_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
-#undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
-#define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_UART_HANDLE_SIZE
-#endif
-
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
-
-#if (SERIAL_PORT_USB_CDC_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
-#undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
-#define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_USB_CDC_HANDLE_SIZE
-#endif
-
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
-
-#if (SERIAL_PORT_SWO_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
-#undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
-#define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_SWO_HANDLE_SIZE
-#endif
-
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
-
-#if (SERIAL_PORT_USB_VIRTUAL_HANDLE_SIZE > SERIAL_MANAGER_HANDLE_SIZE_TEMP)
-#undef SERIAL_MANAGER_HANDLE_SIZE_TEMP
-#define SERIAL_MANAGER_HANDLE_SIZE_TEMP SERIAL_PORT_USB_VIRTUAL_HANDLE_SIZE
-#endif
-
-#endif
-
-/*! @brief SERIAL_PORT_UART_HANDLE_SIZE/SERIAL_PORT_USB_CDC_HANDLE_SIZE + serial manager dedicated size */
-#if ((defined(SERIAL_MANAGER_HANDLE_SIZE_TEMP) && (SERIAL_MANAGER_HANDLE_SIZE_TEMP > 0U)))
-#else
-#error SERIAL_PORT_TYPE_UART, SERIAL_PORT_TYPE_USBCDC, SERIAL_PORT_TYPE_SWO and SERIAL_PORT_TYPE_USBCDC_VIRTUAL should not be cleared at same time.
-#endif
-
-/*! @brief Definition of serial manager handle size. */
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#define SERIAL_MANAGER_HANDLE_SIZE (SERIAL_MANAGER_HANDLE_SIZE_TEMP + 120U)
-#else
-#define SERIAL_MANAGER_HANDLE_SIZE (SERIAL_MANAGER_HANDLE_SIZE_TEMP + 12U)
-#endif
-
-/*!
- * @brief Defines the serial manager handle
- *
- * This macro is used to define a 4 byte aligned serial manager handle.
- * Then use "(serial_handle_t)name" to get the serial manager handle.
- *
- * The macro should be global and could be optional. You could also define serial manager handle by yourself.
- *
- * This is an example,
- * @code
- * SERIAL_MANAGER_HANDLE_DEFINE(serialManagerHandle);
- * @endcode
- *
- * @param name The name string of the serial manager handle.
- */
-#define SERIAL_MANAGER_HANDLE_DEFINE(name) \
- uint32_t name[((SERIAL_MANAGER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
-
-/*!
- * @brief Defines the serial manager write handle
- *
- * This macro is used to define a 4 byte aligned serial manager write handle.
- * Then use "(serial_write_handle_t)name" to get the serial manager write handle.
- *
- * The macro should be global and could be optional. You could also define serial manager write handle by yourself.
- *
- * This is an example,
- * @code
- * SERIAL_MANAGER_WRITE_HANDLE_DEFINE(serialManagerwriteHandle);
- * @endcode
- *
- * @param name The name string of the serial manager write handle.
- */
-#define SERIAL_MANAGER_WRITE_HANDLE_DEFINE(name) \
- uint32_t name[((SERIAL_MANAGER_WRITE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
-
-/*!
- * @brief Defines the serial manager read handle
- *
- * This macro is used to define a 4 byte aligned serial manager read handle.
- * Then use "(serial_read_handle_t)name" to get the serial manager read handle.
- *
- * The macro should be global and could be optional. You could also define serial manager read handle by yourself.
- *
- * This is an example,
- * @code
- * SERIAL_MANAGER_READ_HANDLE_DEFINE(serialManagerReadHandle);
- * @endcode
- *
- * @param name The name string of the serial manager read handle.
- */
-#define SERIAL_MANAGER_READ_HANDLE_DEFINE(name) \
- uint32_t name[((SERIAL_MANAGER_READ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
-
-/*! @brief Macro to determine whether use common task. */
-#ifndef SERIAL_MANAGER_USE_COMMON_TASK
-#define SERIAL_MANAGER_USE_COMMON_TASK (1U)
-#endif
-
-/*! @brief Macro to set serial manager task priority. */
-#ifndef SERIAL_MANAGER_TASK_PRIORITY
-#define SERIAL_MANAGER_TASK_PRIORITY (2U)
-#endif
-
-/*! @brief Macro to set serial manager task stack size. */
-#ifndef SERIAL_MANAGER_TASK_STACK_SIZE
-#define SERIAL_MANAGER_TASK_STACK_SIZE (1000U)
-#endif
-
-/*! @brief The handle of the serial manager module */
-typedef void *serial_handle_t;
-
-/*! @brief The write handle of the serial manager module */
-typedef void *serial_write_handle_t;
-
-/*! @brief The read handle of the serial manager module */
-typedef void *serial_read_handle_t;
-
-/*! @brief serial port type*/
-typedef enum _serial_port_type
-{
- kSerialPort_Uart = 1U, /*!< Serial port UART */
- kSerialPort_UsbCdc, /*!< Serial port USB CDC */
- kSerialPort_Swo, /*!< Serial port SWO */
- kSerialPort_UsbCdcVirtual, /*!< Serial port USB CDC Virtual */
-} serial_port_type_t;
-
-/*! @brief serial manager config structure*/
-typedef struct _serial_manager_config
-{
-#if defined(DEBUG_CONSOLE_TRANSFER_NON_BLOCKING)
- uint8_t *ringBuffer; /*!< Ring buffer address, it is used to buffer data received by the hardware.
- Besides, the memory space cannot be free during the lifetime of the serial
- manager module. */
- uint32_t ringBufferSize; /*!< The size of the ring buffer */
-#endif
- serial_port_type_t type; /*!< Serial port type */
- void *portConfig; /*!< Serial port configuration */
-} serial_manager_config_t;
-
-/*! @brief serial manager error code*/
-typedef enum _serial_manager_status
-{
- kStatus_SerialManager_Success = kStatus_Success, /*!< Success */
- kStatus_SerialManager_Error = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 1), /*!< Failed */
- kStatus_SerialManager_Busy = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 2), /*!< Busy */
- kStatus_SerialManager_Notify = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 3), /*!< Ring buffer is not empty */
- kStatus_SerialManager_Canceled =
- MAKE_STATUS(kStatusGroup_SERIALMANAGER, 4), /*!< the non-blocking request is canceled */
- kStatus_SerialManager_HandleConflict = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 5), /*!< The handle is opened */
- kStatus_SerialManager_RingBufferOverflow =
- MAKE_STATUS(kStatusGroup_SERIALMANAGER, 6), /*!< The ring buffer is overflowed */
- kStatus_SerialManager_NotConnected = MAKE_STATUS(kStatusGroup_SERIALMANAGER, 7), /*!< The host is not connected */
-} serial_manager_status_t;
-
-/*! @brief Callback message structure */
-typedef struct _serial_manager_callback_message
-{
- uint8_t *buffer; /*!< Transferred buffer */
- uint32_t length; /*!< Transferred data length */
-} serial_manager_callback_message_t;
-
-/*! @brief callback function */
-typedef void (*serial_manager_callback_t)(void *callbackParam,
- serial_manager_callback_message_t *message,
- serial_manager_status_t status);
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif /* _cplusplus */
-
-/*!
- * @brief Initializes a serial manager module with the serial manager handle and the user configuration structure.
- *
- * This function configures the Serial Manager module with user-defined settings.
- * The user can configure the configuration structure.
- * The parameter serialHandle is a pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE
- * allocated by the caller.
- * The Serial Manager module supports three types of serial port, UART (includes UART, USART, LPSCI, LPUART, etc), USB
- * CDC and swo.
- * Please refer to #serial_port_type_t for serial port setting.
- * These three types can be set by using #serial_manager_config_t.
- *
- * Example below shows how to use this API to configure the Serial Manager.
- * For UART,
- * @code
- * #define SERIAL_MANAGER_RING_BUFFER_SIZE (256U)
- * static SERIAL_MANAGER_HANDLE_DEFINE(s_serialHandle);
- * static uint8_t s_ringBuffer[SERIAL_MANAGER_RING_BUFFER_SIZE];
- *
- * serial_manager_config_t config;
- * serial_port_uart_config_t uartConfig;
- * config.type = kSerialPort_Uart;
- * config.ringBuffer = &s_ringBuffer[0];
- * config.ringBufferSize = SERIAL_MANAGER_RING_BUFFER_SIZE;
- * uartConfig.instance = 0;
- * uartConfig.clockRate = 24000000;
- * uartConfig.baudRate = 115200;
- * uartConfig.parityMode = kSerialManager_UartParityDisabled;
- * uartConfig.stopBitCount = kSerialManager_UartOneStopBit;
- * uartConfig.enableRx = 1;
- * uartConfig.enableTx = 1;
- * config.portConfig = &uartConfig;
- * SerialManager_Init((serial_handle_t)s_serialHandle, &config);
- * @endcode
- * For USB CDC,
- * @code
- * #define SERIAL_MANAGER_RING_BUFFER_SIZE (256U)
- * static SERIAL_MANAGER_HANDLE_DEFINE(s_serialHandle);
- * static uint8_t s_ringBuffer[SERIAL_MANAGER_RING_BUFFER_SIZE];
- *
- * serial_manager_config_t config;
- * serial_port_usb_cdc_config_t usbCdcConfig;
- * config.type = kSerialPort_UsbCdc;
- * config.ringBuffer = &s_ringBuffer[0];
- * config.ringBufferSize = SERIAL_MANAGER_RING_BUFFER_SIZE;
- * usbCdcConfig.controllerIndex = kSerialManager_UsbControllerKhci0;
- * config.portConfig = &usbCdcConfig;
- * SerialManager_Init((serial_handle_t)s_serialHandle, &config);
- * @endcode
- *
- * @param serialHandle Pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE allocated by the caller.
- * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
- * You can define the handle in the following two ways:
- * #SERIAL_MANAGER_HANDLE_DEFINE(serialHandle);
- * or
- * uint32_t serialHandle[((SERIAL_MANAGER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
- * @param config Pointer to user-defined configuration structure.
- * @retval kStatus_SerialManager_Error An error occurred.
- * @retval kStatus_SerialManager_Success The Serial Manager module initialization succeed.
- */
-serial_manager_status_t SerialManager_Init(serial_handle_t serialHandle, serial_manager_config_t *config);
-
-/*!
- * @brief De-initializes the serial manager module instance.
- *
- * This function de-initializes the serial manager module instance. If the opened writing or
- * reading handle is not closed, the function will return kStatus_SerialManager_Busy.
- *
- * @param serialHandle The serial manager module handle pointer.
- * @retval kStatus_SerialManager_Success The serial manager de-initialization succeed.
- * @retval kStatus_SerialManager_Busy Opened reading or writing handle is not closed.
- */
-serial_manager_status_t SerialManager_Deinit(serial_handle_t serialHandle);
-
-/*!
- * @brief Opens a writing handle for the serial manager module.
- *
- * This function Opens a writing handle for the serial manager module. If the serial manager needs to
- * be used in different tasks, the task should open a dedicated write handle for itself by calling
- * #SerialManager_OpenWriteHandle. Since there can only one buffer for transmission for the writing
- * handle at the same time, multiple writing handles need to be opened when the multiple transmission
- * is needed for a task.
- *
- * @param serialHandle The serial manager module handle pointer.
- * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
- * @param writeHandle The serial manager module writing handle pointer.
- * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
- * You can define the handle in the following two ways:
- * #SERIAL_MANAGER_WRITE_HANDLE_DEFINE(writeHandle);
- * or
- * uint32_t writeHandle[((SERIAL_MANAGER_WRITE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
- * @retval kStatus_SerialManager_Error An error occurred.
- * @retval kStatus_SerialManager_HandleConflict The writing handle was opened.
- * @retval kStatus_SerialManager_Success The writing handle is opened.
- *
- * Example below shows how to use this API to write data.
- * For task 1,
- * @code
- * static SERIAL_MANAGER_WRITE_HANDLE_DEFINE(s_serialWriteHandle1);
- * static uint8_t s_nonBlockingWelcome1[] = "This is non-blocking writing log for task1!\r\n";
- * SerialManager_OpenWriteHandle((serial_handle_t)serialHandle, (serial_write_handle_t)s_serialWriteHandle1);
- * SerialManager_InstallTxCallback((serial_write_handle_t)s_serialWriteHandle1,
- * Task1_SerialManagerTxCallback,
- * s_serialWriteHandle1);
- * SerialManager_WriteNonBlocking((serial_write_handle_t)s_serialWriteHandle1,
- * s_nonBlockingWelcome1,
- * sizeof(s_nonBlockingWelcome1) - 1U);
- * @endcode
- * For task 2,
- * @code
- * static SERIAL_MANAGER_WRITE_HANDLE_DEFINE(s_serialWriteHandle2);
- * static uint8_t s_nonBlockingWelcome2[] = "This is non-blocking writing log for task2!\r\n";
- * SerialManager_OpenWriteHandle((serial_handle_t)serialHandle, (serial_write_handle_t)s_serialWriteHandle2);
- * SerialManager_InstallTxCallback((serial_write_handle_t)s_serialWriteHandle2,
- * Task2_SerialManagerTxCallback,
- * s_serialWriteHandle2);
- * SerialManager_WriteNonBlocking((serial_write_handle_t)s_serialWriteHandle2,
- * s_nonBlockingWelcome2,
- * sizeof(s_nonBlockingWelcome2) - 1U);
- * @endcode
- */
-serial_manager_status_t SerialManager_OpenWriteHandle(serial_handle_t serialHandle, serial_write_handle_t writeHandle);
-
-/*!
- * @brief Closes a writing handle for the serial manager module.
- *
- * This function Closes a writing handle for the serial manager module.
- *
- * @param writeHandle The serial manager module writing handle pointer.
- * @retval kStatus_SerialManager_Success The writing handle is closed.
- */
-serial_manager_status_t SerialManager_CloseWriteHandle(serial_write_handle_t writeHandle);
-
-/*!
- * @brief Opens a reading handle for the serial manager module.
- *
- * This function Opens a reading handle for the serial manager module. The reading handle can not be
- * opened multiple at the same time. The error code kStatus_SerialManager_Busy would be returned when
- * the previous reading handle is not closed. And there can only be one buffer for receiving for the
- * reading handle at the same time.
- *
- * @param serialHandle The serial manager module handle pointer.
- * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
- * @param readHandle The serial manager module reading handle pointer.
- * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
- * You can define the handle in the following two ways:
- * #SERIAL_MANAGER_READ_HANDLE_DEFINE(readHandle);
- * or
- * uint32_t readHandle[((SERIAL_MANAGER_READ_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
- * @retval kStatus_SerialManager_Error An error occurred.
- * @retval kStatus_SerialManager_Success The reading handle is opened.
- * @retval kStatus_SerialManager_Busy Previous reading handle is not closed.
- *
- * Example below shows how to use this API to read data.
- * @code
- * static SERIAL_MANAGER_READ_HANDLE_DEFINE(s_serialReadHandle);
- * SerialManager_OpenReadHandle((serial_handle_t)serialHandle, (serial_read_handle_t)s_serialReadHandle);
- * static uint8_t s_nonBlockingBuffer[64];
- * SerialManager_InstallRxCallback((serial_read_handle_t)s_serialReadHandle,
- * APP_SerialManagerRxCallback,
- * s_serialReadHandle);
- * SerialManager_ReadNonBlocking((serial_read_handle_t)s_serialReadHandle,
- * s_nonBlockingBuffer,
- * sizeof(s_nonBlockingBuffer));
- * @endcode
- */
-serial_manager_status_t SerialManager_OpenReadHandle(serial_handle_t serialHandle, serial_read_handle_t readHandle);
-
-/*!
- * @brief Closes a reading for the serial manager module.
- *
- * This function Closes a reading for the serial manager module.
- *
- * @param readHandle The serial manager module reading handle pointer.
- * @retval kStatus_SerialManager_Success The reading handle is closed.
- */
-serial_manager_status_t SerialManager_CloseReadHandle(serial_read_handle_t readHandle);
-
-/*!
- * @brief Transmits data with the blocking mode.
- *
- * This is a blocking function, which polls the sending queue, waits for the sending queue to be empty.
- * This function sends data using an interrupt method. The interrupt of the hardware could not be disabled.
- * And There can only one buffer for transmission for the writing handle at the same time.
- *
- * @note The function #SerialManager_WriteBlocking and the function #SerialManager_WriteNonBlocking
- * cannot be used at the same time.
- * And, the function #SerialManager_CancelWriting cannot be used to abort the transmission of this function.
- *
- * @param writeHandle The serial manager module handle pointer.
- * @param buffer Start address of the data to write.
- * @param length Length of the data to write.
- * @retval kStatus_SerialManager_Success Successfully sent all data.
- * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all sent yet.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_WriteBlocking(serial_write_handle_t writeHandle,
- uint8_t *buffer,
- uint32_t length);
-
-/*!
- * @brief Reads data with the blocking mode.
- *
- * This is a blocking function, which polls the receiving buffer, waits for the receiving buffer to be full.
- * This function receives data using an interrupt method. The interrupt of the hardware could not be disabled.
- * And There can only one buffer for receiving for the reading handle at the same time.
- *
- * @note The function #SerialManager_ReadBlocking and the function #SerialManager_ReadNonBlocking
- * cannot be used at the same time.
- * And, the function #SerialManager_CancelReading cannot be used to abort the transmission of this function.
- *
- * @param readHandle The serial manager module handle pointer.
- * @param buffer Start address of the data to store the received data.
- * @param length The length of the data to be received.
- * @retval kStatus_SerialManager_Success Successfully received all data.
- * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all received yet.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_ReadBlocking(serial_read_handle_t readHandle, uint8_t *buffer, uint32_t length);
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-/*!
- * @brief Transmits data with the non-blocking mode.
- *
- * This is a non-blocking function, which returns directly without waiting for all data to be sent.
- * When all data is sent, the module notifies the upper layer through a TX callback function and passes
- * the status parameter @ref kStatus_SerialManager_Success.
- * This function sends data using an interrupt method. The interrupt of the hardware could not be disabled.
- * And There can only one buffer for transmission for the writing handle at the same time.
- *
- * @note The function #SerialManager_WriteBlocking and the function #SerialManager_WriteNonBlocking
- * cannot be used at the same time. And, the TX callback is mandatory before the function could be used.
- *
- * @param writeHandle The serial manager module handle pointer.
- * @param buffer Start address of the data to write.
- * @param length Length of the data to write.
- * @retval kStatus_SerialManager_Success Successfully sent all data.
- * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all sent yet.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_WriteNonBlocking(serial_write_handle_t writeHandle,
- uint8_t *buffer,
- uint32_t length);
-
-/*!
- * @brief Reads data with the non-blocking mode.
- *
- * This is a non-blocking function, which returns directly without waiting for all data to be received.
- * When all data is received, the module driver notifies the upper layer
- * through a RX callback function and passes the status parameter @ref kStatus_SerialManager_Success.
- * This function receives data using an interrupt method. The interrupt of the hardware could not be disabled.
- * And There can only one buffer for receiving for the reading handle at the same time.
- *
- * @note The function #SerialManager_ReadBlocking and the function #SerialManager_ReadNonBlocking
- * cannot be used at the same time. And, the RX callback is mandatory before the function could be used.
- *
- * @param readHandle The serial manager module handle pointer.
- * @param buffer Start address of the data to store the received data.
- * @param length The length of the data to be received.
- * @retval kStatus_SerialManager_Success Successfully received all data.
- * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all received yet.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_ReadNonBlocking(serial_read_handle_t readHandle,
- uint8_t *buffer,
- uint32_t length);
-
-/*!
- * @brief Tries to read data.
- *
- * The function tries to read data from internal ring buffer. If the ring buffer is not empty, the data will be
- * copied from ring buffer to up layer buffer. The copied length is the minimum of the ring buffer and up layer length.
- * After the data is copied, the actual data length is passed by the parameter length.
- * And There can only one buffer for receiving for the reading handle at the same time.
- *
- * @param readHandle The serial manager module handle pointer.
- * @param buffer Start address of the data to store the received data.
- * @param length The length of the data to be received.
- * @param receivedLength Length received from the ring buffer directly.
- * @retval kStatus_SerialManager_Success Successfully received all data.
- * @retval kStatus_SerialManager_Busy Previous transmission still not finished; data not all received yet.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_TryRead(serial_read_handle_t readHandle,
- uint8_t *buffer,
- uint32_t length,
- uint32_t *receivedLength);
-
-/*!
- * @brief Cancels unfinished send transmission.
- *
- * The function cancels unfinished send transmission. When the transfer is canceled, the module notifies the upper layer
- * through a TX callback function and passes the status parameter @ref kStatus_SerialManager_Canceled.
- *
- * @note The function #SerialManager_CancelWriting cannot be used to abort the transmission of
- * the function #SerialManager_WriteBlocking.
- *
- * @param writeHandle The serial manager module handle pointer.
- * @retval kStatus_SerialManager_Success Get successfully abort the sending.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_CancelWriting(serial_write_handle_t writeHandle);
-
-/*!
- * @brief Cancels unfinished receive transmission.
- *
- * The function cancels unfinished receive transmission. When the transfer is canceled, the module notifies the upper
- * layer
- * through a RX callback function and passes the status parameter @ref kStatus_SerialManager_Canceled.
- *
- * @note The function #SerialManager_CancelReading cannot be used to abort the transmission of
- * the function #SerialManager_ReadBlocking.
- *
- * @param readHandle The serial manager module handle pointer.
- * @retval kStatus_SerialManager_Success Get successfully abort the receiving.
- * @retval kStatus_SerialManager_Error An error occurred.
- */
-serial_manager_status_t SerialManager_CancelReading(serial_read_handle_t readHandle);
-
-/*!
- * @brief Installs a TX callback and callback parameter.
- *
- * This function is used to install the TX callback and callback parameter for the serial manager module.
- * When any status of TX transmission changed, the driver will notify the upper layer by the installed callback
- * function. And the status is also passed as status parameter when the callback is called.
- *
- * @param writeHandle The serial manager module handle pointer.
- * @param callback The callback function.
- * @param callbackParam The parameter of the callback function.
- * @retval kStatus_SerialManager_Success Successfully install the callback.
- */
-serial_manager_status_t SerialManager_InstallTxCallback(serial_write_handle_t writeHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-
-/*!
- * @brief Installs a RX callback and callback parameter.
- *
- * This function is used to install the RX callback and callback parameter for the serial manager module.
- * When any status of RX transmission changed, the driver will notify the upper layer by the installed callback
- * function. And the status is also passed as status parameter when the callback is called.
- *
- * @param readHandle The serial manager module handle pointer.
- * @param callback The callback function.
- * @param callbackParam The parameter of the callback function.
- * @retval kStatus_SerialManager_Success Successfully install the callback.
- */
-serial_manager_status_t SerialManager_InstallRxCallback(serial_read_handle_t readHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-
-#endif
-
-/*!
- * @brief Prepares to enter low power consumption.
- *
- * This function is used to prepare to enter low power consumption.
- *
- * @param serialHandle The serial manager module handle pointer.
- * @retval kStatus_SerialManager_Success Successful operation.
- */
-serial_manager_status_t SerialManager_EnterLowpower(serial_handle_t serialHandle);
-
-/*!
- * @brief Restores from low power consumption.
- *
- * This function is used to restore from low power consumption.
- *
- * @param serialHandle The serial manager module handle pointer.
- * @retval kStatus_SerialManager_Success Successful operation.
- */
-serial_manager_status_t SerialManager_ExitLowpower(serial_handle_t serialHandle);
-
-#if defined(__cplusplus)
-}
-#endif
-/*! @} */
-#endif /* __SERIAL_MANAGER_H__ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_internal.h b/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_internal.h
deleted file mode 100755
index a1a933906..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_internal.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2019 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __SERIAL_PORT_INTERNAL_H__
-#define __SERIAL_PORT_INTERNAL_H__
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif /* _cplusplus */
-
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
-serial_manager_status_t Serial_UartInit(serial_handle_t serialHandle, void *serialConfig);
-serial_manager_status_t Serial_UartDeinit(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UartWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-#if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-serial_manager_status_t Serial_UartRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-serial_manager_status_t Serial_UartCancelWrite(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UartInstallTxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-serial_manager_status_t Serial_UartInstallRxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-void Serial_UartIsrFunction(serial_handle_t serialHandle);
-#endif
-serial_manager_status_t Serial_UartEnterLowpower(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UartExitLowpower(serial_handle_t serialHandle);
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_USBCDC) && (SERIAL_PORT_TYPE_USBCDC > 0U))
-serial_manager_status_t Serial_UsbCdcInit(serial_handle_t serialHandle, void *config);
-serial_manager_status_t Serial_UsbCdcDeinit(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UsbCdcWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-serial_manager_status_t Serial_UsbCdcRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-serial_manager_status_t Serial_UsbCdcCancelWrite(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UsbCdcInstallTxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-serial_manager_status_t Serial_UsbCdcInstallRxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-void Serial_UsbCdcIsrFunction(serial_handle_t serialHandle);
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_SWO) && (SERIAL_PORT_TYPE_SWO > 0U))
-serial_manager_status_t Serial_SwoInit(serial_handle_t serialHandle, void *config);
-serial_manager_status_t Serial_SwoDeinit(serial_handle_t serialHandle);
-serial_manager_status_t Serial_SwoWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-#if !(defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-serial_manager_status_t Serial_SwoRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-#endif
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-serial_manager_status_t Serial_SwoCancelWrite(serial_handle_t serialHandle);
-serial_manager_status_t Serial_SwoInstallTxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-serial_manager_status_t Serial_SwoInstallRxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-void Serial_SwoIsrFunction(serial_handle_t serialHandle);
-#endif
-#endif
-
-#if (defined(SERIAL_PORT_TYPE_USBCDC_VIRTUAL) && (SERIAL_PORT_TYPE_USBCDC_VIRTUAL > 0U))
-serial_manager_status_t Serial_UsbCdcVirtualInit(serial_handle_t serialHandle, void *config);
-serial_manager_status_t Serial_UsbCdcVirtualDeinit(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UsbCdcVirtualWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-serial_manager_status_t Serial_UsbCdcVirtualRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length);
-serial_manager_status_t Serial_UsbCdcVirtualCancelWrite(serial_handle_t serialHandle);
-serial_manager_status_t Serial_UsbCdcVirtualInstallTxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-serial_manager_status_t Serial_UsbCdcVirtualInstallRxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam);
-void Serial_UsbCdcVirtualIsrFunction(serial_handle_t serialHandle);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __SERIAL_PORT_INTERNAL_H__ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.c b/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.c
deleted file mode 100755
index adb37e5e1..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.c
+++ /dev/null
@@ -1,403 +0,0 @@
-/*
- * Copyright 2018 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_common.h"
-#include "serial_manager.h"
-#include "serial_port_internal.h"
-
-#if (defined(SERIAL_PORT_TYPE_UART) && (SERIAL_PORT_TYPE_UART > 0U))
-#include "uart.h"
-
-#include "serial_port_uart.h"
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-#ifndef NDEBUG
-#if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
-#undef assert
-#define assert(n)
-#endif
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#define SERIAL_PORT_UART_RECEIVE_DATA_LENGTH 1U
-
-typedef struct _serial_uart_send_state
-{
- serial_manager_callback_t callback;
- void *callbackParam;
- uint8_t *buffer;
- uint32_t length;
- volatile uint8_t busy;
-} serial_uart_send_state_t;
-
-typedef struct _serial_uart_recv_state
-{
- serial_manager_callback_t callback;
- void *callbackParam;
- volatile uint8_t busy;
- uint8_t readBuffer[SERIAL_PORT_UART_RECEIVE_DATA_LENGTH];
-} serial_uart_recv_state_t;
-#endif
-
-typedef struct _serial_uart_state
-{
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- serial_uart_send_state_t tx;
- serial_uart_recv_state_t rx;
-#endif
- UART_HANDLE_DEFINE(usartHandleBuffer);
-} serial_uart_state_t;
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-/* UART user callback */
-static void Serial_UartCallback(hal_uart_handle_t handle, hal_uart_status_t status, void *userData)
-{
- serial_uart_state_t *serialUartHandle;
- serial_manager_callback_message_t msg;
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- hal_uart_transfer_t transfer;
-#endif
-
- if (NULL == userData)
- {
- return;
- }
-
- serialUartHandle = (serial_uart_state_t *)userData;
-
- if ((hal_uart_status_t)kStatus_HAL_UartRxIdle == status)
- {
- if ((NULL != serialUartHandle->rx.callback))
- {
- msg.buffer = &serialUartHandle->rx.readBuffer[0];
- msg.length = sizeof(serialUartHandle->rx.readBuffer);
- serialUartHandle->rx.callback(serialUartHandle->rx.callbackParam, &msg, kStatus_SerialManager_Success);
- }
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- transfer.data = &serialUartHandle->rx.readBuffer[0];
- transfer.dataSize = sizeof(serialUartHandle->rx.readBuffer);
- if (kStatus_HAL_UartSuccess ==
- HAL_UartTransferReceiveNonBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]), &transfer))
-#else
- if ((hal_uart_status_t)kStatus_HAL_UartSuccess ==
- HAL_UartReceiveNonBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]),
- &serialUartHandle->rx.readBuffer[0], sizeof(serialUartHandle->rx.readBuffer)))
-#endif
- {
- serialUartHandle->rx.busy = 1U;
- }
- else
- {
- serialUartHandle->rx.busy = 0U;
- }
- }
- else if ((hal_uart_status_t)kStatus_HAL_UartTxIdle == status)
- {
- if (0U != serialUartHandle->tx.busy)
- {
- serialUartHandle->tx.busy = 0U;
- if ((NULL != serialUartHandle->tx.callback))
- {
- msg.buffer = serialUartHandle->tx.buffer;
- msg.length = serialUartHandle->tx.length;
- serialUartHandle->tx.callback(serialUartHandle->tx.callbackParam, &msg, kStatus_SerialManager_Success);
- }
- }
- }
- else
- {
- }
-}
-#endif
-
-serial_manager_status_t Serial_UartInit(serial_handle_t serialHandle, void *serialConfig)
-{
- serial_uart_state_t *serialUartHandle;
- serial_port_uart_config_t *uartConfig;
- hal_uart_config_t config;
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- hal_uart_transfer_t transfer;
-#endif
-#endif
-
- assert(serialConfig);
- assert(serialHandle);
- assert(SERIAL_PORT_UART_HANDLE_SIZE >= sizeof(serial_uart_state_t));
-
- uartConfig = (serial_port_uart_config_t *)serialConfig;
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- config.baudRate_Bps = uartConfig->baudRate;
- config.parityMode = (hal_uart_parity_mode_t)uartConfig->parityMode;
- config.stopBitCount = (hal_uart_stop_bit_count_t)uartConfig->stopBitCount;
- config.enableRx = uartConfig->enableRx;
- config.enableTx = uartConfig->enableTx;
- config.srcClock_Hz = uartConfig->clockRate;
- config.instance = uartConfig->instance;
-
- if (kStatus_HAL_UartSuccess != HAL_UartInit(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]), &config))
- {
- return kStatus_SerialManager_Error;
- }
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- if (kStatus_HAL_UartSuccess !=
- HAL_UartTransferInstallCallback(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]),
- Serial_UartCallback, serialUartHandle))
-#else
- if (kStatus_HAL_UartSuccess != HAL_UartInstallCallback(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]),
- Serial_UartCallback, serialUartHandle))
-#endif
- {
- return kStatus_SerialManager_Error;
- }
-
- if (0U != uartConfig->enableRx)
- {
- serialUartHandle->rx.busy = 1U;
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- transfer.data = &serialUartHandle->rx.readBuffer[0];
- transfer.dataSize = sizeof(serialUartHandle->rx.readBuffer);
- if (kStatus_HAL_UartSuccess !=
- HAL_UartTransferReceiveNonBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]), &transfer))
-#else
- if (kStatus_HAL_UartSuccess !=
- HAL_UartReceiveNonBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]),
- &serialUartHandle->rx.readBuffer[0], sizeof(serialUartHandle->rx.readBuffer)))
-#endif
- {
- serialUartHandle->rx.busy = 0U;
- return kStatus_SerialManager_Error;
- }
- }
-#endif
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t Serial_UartDeinit(serial_handle_t serialHandle)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- (void)HAL_UartTransferAbortReceive(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]));
-#else
- (void)HAL_UartAbortReceive(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]));
-#endif
-#endif
- (void)HAL_UartDeinit(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]));
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
- serialUartHandle->tx.busy = 0U;
- serialUartHandle->rx.busy = 0U;
-#endif
-
- return kStatus_SerialManager_Success;
-}
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-
-serial_manager_status_t Serial_UartWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
-{
- serial_uart_state_t *serialUartHandle;
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- hal_uart_transfer_t transfer;
-#endif
-
- assert(serialHandle);
- assert(buffer);
- assert(length);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- if (0U != serialUartHandle->tx.busy)
- {
- return kStatus_SerialManager_Busy;
- }
- serialUartHandle->tx.busy = 1U;
-
- serialUartHandle->tx.buffer = buffer;
- serialUartHandle->tx.length = length;
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- transfer.data = buffer;
- transfer.dataSize = length;
- if (kStatus_HAL_UartSuccess !=
- HAL_UartTransferSendNonBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]), &transfer))
-#else
- if (kStatus_HAL_UartSuccess !=
- HAL_UartSendNonBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]), buffer, length))
-#endif
- {
- serialUartHandle->tx.busy = 0U;
- return kStatus_SerialManager_Error;
- }
- return kStatus_SerialManager_Success;
-}
-
-#else
-
-serial_manager_status_t Serial_UartWrite(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
- assert(buffer);
- assert(length);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- return (serial_manager_status_t)HAL_UartSendBlocking(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]),
- buffer, length);
-}
-
-serial_manager_status_t Serial_UartRead(serial_handle_t serialHandle, uint8_t *buffer, uint32_t length)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
- assert(buffer);
- assert(length);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- return (serial_manager_status_t)HAL_UartReceiveBlocking(
- ((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]), buffer, length);
-}
-
-#endif
-
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-serial_manager_status_t Serial_UartCancelWrite(serial_handle_t serialHandle)
-{
- serial_uart_state_t *serialUartHandle;
- serial_manager_callback_message_t msg;
- uint32_t primask;
- uint8_t isBusy = 0U;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- primask = DisableGlobalIRQ();
- isBusy = serialUartHandle->tx.busy;
- serialUartHandle->tx.busy = 0U;
- EnableGlobalIRQ(primask);
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- (void)HAL_UartTransferAbortSend(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]));
-#else
- (void)HAL_UartAbortSend(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]));
-#endif
- if (0U != isBusy)
- {
- if ((NULL != serialUartHandle->tx.callback))
- {
- msg.buffer = serialUartHandle->tx.buffer;
- msg.length = serialUartHandle->tx.length;
- serialUartHandle->tx.callback(serialUartHandle->tx.callbackParam, &msg, kStatus_SerialManager_Canceled);
- }
- }
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t Serial_UartInstallTxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- serialUartHandle->tx.callback = callback;
- serialUartHandle->tx.callbackParam = callbackParam;
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t Serial_UartInstallRxCallback(serial_handle_t serialHandle,
- serial_manager_callback_t callback,
- void *callbackParam)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- serialUartHandle->rx.callback = callback;
- serialUartHandle->rx.callbackParam = callbackParam;
-
- return kStatus_SerialManager_Success;
-}
-
-void Serial_UartIsrFunction(serial_handle_t serialHandle)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- HAL_UartIsrFunction(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0]));
-}
-#endif
-
-serial_manager_status_t Serial_UartEnterLowpower(serial_handle_t serialHandle)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- if (kStatus_HAL_UartSuccess != HAL_UartEnterLowpower(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0])))
- {
- return kStatus_SerialManager_Error;
- }
-
- return kStatus_SerialManager_Success;
-}
-
-serial_manager_status_t Serial_UartExitLowpower(serial_handle_t serialHandle)
-{
- serial_uart_state_t *serialUartHandle;
-
- assert(serialHandle);
-
- serialUartHandle = (serial_uart_state_t *)serialHandle;
-
- if (kStatus_HAL_UartSuccess != HAL_UartExitLowpower(((hal_uart_handle_t)&serialUartHandle->usartHandleBuffer[0])))
- {
- return kStatus_SerialManager_Error;
- }
-
- return kStatus_SerialManager_Success;
-}
-
-#endif
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.h b/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.h
deleted file mode 100755
index c099aec40..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/serial_manager/serial_port_uart.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2018 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __SERIAL_PORT_UART_H__
-#define __SERIAL_PORT_UART_H__
-
-#include "uart.h"
-
-/*!
- * @addtogroup serial_port_uart
- * @{
- */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-/*! @brief serial port uart handle size*/
-#if (defined(SERIAL_MANAGER_NON_BLOCKING_MODE) && (SERIAL_MANAGER_NON_BLOCKING_MODE > 0U))
-#define SERIAL_PORT_UART_HANDLE_SIZE (76U + HAL_UART_HANDLE_SIZE)
-#else
-#define SERIAL_PORT_UART_HANDLE_SIZE (HAL_UART_HANDLE_SIZE)
-#endif
-
-/*! @brief serial port uart parity mode*/
-typedef enum _serial_port_uart_parity_mode
-{
- kSerialManager_UartParityDisabled = 0x0U, /*!< Parity disabled */
- kSerialManager_UartParityEven = 0x1U, /*!< Parity even enabled */
- kSerialManager_UartParityOdd = 0x2U, /*!< Parity odd enabled */
-} serial_port_uart_parity_mode_t;
-
-/*! @brief serial port uart stop bit count*/
-typedef enum _serial_port_uart_stop_bit_count
-{
- kSerialManager_UartOneStopBit = 0U, /*!< One stop bit */
- kSerialManager_UartTwoStopBit = 1U, /*!< Two stop bits */
-} serial_port_uart_stop_bit_count_t;
-
-/*! @brief serial port uart config struct*/
-typedef struct _serial_port_uart_config
-{
- uint32_t clockRate; /*!< clock rate */
- uint32_t baudRate; /*!< baud rate */
- serial_port_uart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, odd */
- serial_port_uart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default) or 2 stop bits */
- uint8_t instance; /*!< Instance (0 - UART0, 1 - UART1, ...), detail information
- please refer to the SOC corresponding RM. */
- uint8_t enableRx; /*!< Enable RX */
- uint8_t enableTx; /*!< Enable TX */
-} serial_port_uart_config_t;
-/*! @} */
-#endif /* __SERIAL_PORT_UART_H__ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/uart/uart.h b/platform/ext/target/nxp/common/Native_Driver/components/uart/uart.h
deleted file mode 100755
index 4e8eed7db..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/uart/uart.h
+++ /dev/null
@@ -1,532 +0,0 @@
-/*
- * Copyright 2018-2019 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef __HAL_UART_ADAPTER_H__
-#define __HAL_UART_ADAPTER_H__
-
-#if defined(FSL_RTOS_FREE_RTOS)
-#include "FreeRTOS.h"
-#endif
-
-/*!
- * @addtogroup UART_Adapter
- * @{
- */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/*! @brief Enable or disable UART adapter non-blocking mode (1 - enable, 0 - disable) */
-#ifdef DEBUG_CONSOLE_TRANSFER_NON_BLOCKING
-#define UART_ADAPTER_NON_BLOCKING_MODE (1U)
-#else
-#ifndef SERIAL_MANAGER_NON_BLOCKING_MODE
-#define UART_ADAPTER_NON_BLOCKING_MODE (0U)
-#else
-#define UART_ADAPTER_NON_BLOCKING_MODE SERIAL_MANAGER_NON_BLOCKING_MODE
-#endif
-#endif
-
-#if defined(__GIC_PRIO_BITS)
-#ifndef HAL_UART_ISR_PRIORITY
-#define HAL_UART_ISR_PRIORITY (25U)
-#endif
-#else
-#if defined(configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY)
-#ifndef HAL_UART_ISR_PRIORITY
-#define HAL_UART_ISR_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY)
-#endif
-#else
-/* The default value 3 is used to support different ARM Core, such as CM0P, CM4, CM7, and CM33, etc.
- * The minimum number of priority bits implemented in the NVIC is 2 on these SOCs. The value of mininum
- * priority is 3 (2^2 - 1). So, the default value is 3.
- */
-#ifndef HAL_UART_ISR_PRIORITY
-#define HAL_UART_ISR_PRIORITY (3U)
-#endif
-#endif
-#endif
-
-#ifndef HAL_UART_ADAPTER_LOWPOWER
-#define HAL_UART_ADAPTER_LOWPOWER (0U)
-#endif /* HAL_UART_ADAPTER_LOWPOWER */
-
-/*! @brief Definition of uart adapter handle size. */
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-#define HAL_UART_HANDLE_SIZE (90U + HAL_UART_ADAPTER_LOWPOWER * 16U)
-#else
-#define HAL_UART_HANDLE_SIZE (4U + HAL_UART_ADAPTER_LOWPOWER * 16U)
-#endif
-
-/*!
- * @brief Defines the uart handle
- *
- * This macro is used to define a 4 byte aligned uart handle.
- * Then use "(hal_uart_handle_t)name" to get the uart handle.
- *
- * The macro should be global and could be optional. You could also define uart handle by yourself.
- *
- * This is an example,
- * @code
- * UART_HANDLE_DEFINE(uartHandle);
- * @endcode
- *
- * @param name The name string of the uart handle.
- */
-#define UART_HANDLE_DEFINE(name) uint32_t name[((HAL_UART_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
-
-/*! @brief Whether enable transactional function of the UART. (0 - disable, 1 - enable) */
-#ifndef HAL_UART_TRANSFER_MODE
-#define HAL_UART_TRANSFER_MODE (0U)
-#endif
-
-/*! @brief The handle of uart adapter. */
-typedef void *hal_uart_handle_t;
-
-/*! @brief UART status */
-typedef enum _hal_uart_status
-{
- kStatus_HAL_UartSuccess = kStatus_Success, /*!< Successfully */
- kStatus_HAL_UartTxBusy = MAKE_STATUS(kStatusGroup_HAL_UART, 1), /*!< TX busy */
- kStatus_HAL_UartRxBusy = MAKE_STATUS(kStatusGroup_HAL_UART, 2), /*!< RX busy */
- kStatus_HAL_UartTxIdle = MAKE_STATUS(kStatusGroup_HAL_UART, 3), /*!< HAL UART transmitter is idle. */
- kStatus_HAL_UartRxIdle = MAKE_STATUS(kStatusGroup_HAL_UART, 4), /*!< HAL UART receiver is idle */
- kStatus_HAL_UartBaudrateNotSupport =
- MAKE_STATUS(kStatusGroup_HAL_UART, 5), /*!< Baudrate is not support in current clock source */
- kStatus_HAL_UartProtocolError = MAKE_STATUS(
- kStatusGroup_HAL_UART,
- 6), /*!< Error occurs for Noise, Framing, Parity, etc.
- For transactional transfer, The up layer needs to abort the transfer and then starts again */
- kStatus_HAL_UartError = MAKE_STATUS(kStatusGroup_HAL_UART, 7), /*!< Error occurs on HAL UART */
-} hal_uart_status_t;
-
-/*! @brief UART parity mode. */
-typedef enum _hal_uart_parity_mode
-{
- kHAL_UartParityDisabled = 0x0U, /*!< Parity disabled */
- kHAL_UartParityEven = 0x1U, /*!< Parity even enabled */
- kHAL_UartParityOdd = 0x2U, /*!< Parity odd enabled */
-} hal_uart_parity_mode_t;
-
-/*! @brief UART stop bit count. */
-typedef enum _hal_uart_stop_bit_count
-{
- kHAL_UartOneStopBit = 0U, /*!< One stop bit */
- kHAL_UartTwoStopBit = 1U, /*!< Two stop bits */
-} hal_uart_stop_bit_count_t;
-
-/*! @brief UART configuration structure. */
-typedef struct _hal_uart_config
-{
- uint32_t srcClock_Hz; /*!< Source clock */
- uint32_t baudRate_Bps; /*!< Baud rate */
- hal_uart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, odd */
- hal_uart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default) or 2 stop bits */
- uint8_t enableRx; /*!< Enable RX */
- uint8_t enableTx; /*!< Enable TX */
- uint8_t instance; /*!< Instance (0 - UART0, 1 - UART1, ...), detail information please refer to the
- SOC corresponding RM.
- Invalid instance value will cause initialization failure. */
-} hal_uart_config_t;
-
-/*! @brief UART transfer callback function. */
-typedef void (*hal_uart_transfer_callback_t)(hal_uart_handle_t handle, hal_uart_status_t status, void *callbackParam);
-
-/*! @brief UART transfer structure. */
-typedef struct _hal_uart_transfer
-{
- uint8_t *data; /*!< The buffer of data to be transfer.*/
- size_t dataSize; /*!< The byte count to be transfer. */
-} hal_uart_transfer_t;
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif /* _cplusplus */
-
-/*!
- * @name Initialization and deinitialization
- * @{
- */
-
-/*!
- * @brief Initializes a UART instance with the UART handle and the user configuration structure.
- *
- * This function configures the UART module with user-defined settings. The user can configure the configuration
- * structure. The parameter handle is a pointer to point to a memory space of size #HAL_UART_HANDLE_SIZE allocated by
- * the caller. Example below shows how to use this API to configure the UART.
- * @code
- * UART_HANDLE_DEFINE(g_UartHandle);
- * hal_uart_config_t config;
- * config.srcClock_Hz = 48000000;
- * config.baudRate_Bps = 115200U;
- * config.parityMode = kHAL_UartParityDisabled;
- * config.stopBitCount = kHAL_UartOneStopBit;
- * config.enableRx = 1;
- * config.enableTx = 1;
- * config.instance = 0;
- * HAL_UartInit((hal_uart_handle_t)g_UartHandle, &config);
- * @endcode
- *
- * @param handle Pointer to point to a memory space of size #HAL_UART_HANDLE_SIZE allocated by the caller.
- * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices.
- * You can define the handle in the following two ways:
- * #UART_HANDLE_DEFINE(handle);
- * or
- * uint32_t handle[((HAL_UART_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
- * @param config Pointer to user-defined configuration structure.
- * @retval kStatus_HAL_UartBaudrateNotSupport Baudrate is not support in current clock source.
- * @retval kStatus_HAL_UartSuccess UART initialization succeed
- */
-hal_uart_status_t HAL_UartInit(hal_uart_handle_t handle, hal_uart_config_t *config);
-
-/*!
- * @brief Deinitializes a UART instance.
- *
- * This function waits for TX complete, disables TX and RX, and disables the UART clock.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_HAL_UartSuccess UART de-initialization succeed
- */
-hal_uart_status_t HAL_UartDeinit(hal_uart_handle_t handle);
-
-/*! @}*/
-
-/*!
- * @name Blocking bus Operations
- * @{
- */
-
-/*!
- * @brief Reads RX data register using a blocking method.
- *
- * This function polls the RX register, waits for the RX register to be full or for RX FIFO to
- * have data, and reads data from the RX register.
- *
- * @note The function #HAL_UartReceiveBlocking and the function #HAL_UartTransferReceiveNonBlocking
- * cannot be used at the same time.
- * And, the function #HAL_UartTransferAbortReceive cannot be used to abort the transmission of this function.
- *
- * @param handle UART handle pointer.
- * @param data Start address of the buffer to store the received data.
- * @param length Size of the buffer.
- * @retval kStatus_HAL_UartError An error occurred while receiving data.
- * @retval kStatus_HAL_UartParityError A parity error occurred while receiving data.
- * @retval kStatus_HAL_UartSuccess Successfully received all data.
- */
-hal_uart_status_t HAL_UartReceiveBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length);
-
-/*!
- * @brief Writes to the TX register using a blocking method.
- *
- * This function polls the TX register, waits for the TX register to be empty or for the TX FIFO
- * to have room and writes data to the TX buffer.
- *
- * @note The function #HAL_UartSendBlocking and the function #HAL_UartTransferSendNonBlocking
- * cannot be used at the same time.
- * And, the function #HAL_UartTransferAbortSend cannot be used to abort the transmission of this function.
- *
- * @param handle UART handle pointer.
- * @param data Start address of the data to write.
- * @param length Size of the data to write.
- * @retval kStatus_HAL_UartSuccess Successfully sent all data.
- */
-hal_uart_status_t HAL_UartSendBlocking(hal_uart_handle_t handle, const uint8_t *data, size_t length);
-
-/*! @}*/
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
-
-/*!
- * @name Transactional
- * @note The transactional API and the functional API cannot be used at the same time. The macro
- * #HAL_UART_TRANSFER_MODE is used to set which one will be used. If #HAL_UART_TRANSFER_MODE is zero, the
- * functional API with non-blocking mode will be used. Otherwise, transactional API will be used.
- * @{
- */
-
-/*!
- * @brief Installs a callback and callback parameter.
- *
- * This function is used to install the callback and callback parameter for UART module.
- * When any status of the UART changed, the driver will notify the upper layer by the installed callback
- * function. And the status is also passed as status parameter when the callback is called.
- *
- * @param handle UART handle pointer.
- * @param callback The callback function.
- * @param callbackParam The parameter of the callback function.
- * @retval kStatus_HAL_UartSuccess Successfully install the callback.
- */
-hal_uart_status_t HAL_UartTransferInstallCallback(hal_uart_handle_t handle,
- hal_uart_transfer_callback_t callback,
- void *callbackParam);
-
-/*!
- * @brief Receives a buffer of data using an interrupt method.
- *
- * This function receives data using an interrupt method. This is a non-blocking function, which
- * returns directly without waiting for all data to be received.
- * The receive request is saved by the UART driver.
- * When the new data arrives, the receive request is serviced first.
- * When all data is received, the UART driver notifies the upper layer
- * through a callback function and passes the status parameter @ref kStatus_UART_RxIdle.
- *
- * @note The function #HAL_UartReceiveBlocking and the function #HAL_UartTransferReceiveNonBlocking
- * cannot be used at the same time.
- *
- * @param handle UART handle pointer.
- * @param transfer UART transfer structure, see #hal_uart_transfer_t.
- * @retval kStatus_HAL_UartSuccess Successfully queue the transfer into transmit queue.
- * @retval kStatus_HAL_UartRxBusy Previous receive request is not finished.
- * @retval kStatus_HAL_UartError An error occurred.
- */
-hal_uart_status_t HAL_UartTransferReceiveNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer);
-
-/*!
- * @brief Transmits a buffer of data using the interrupt method.
- *
- * This function sends data using an interrupt method. This is a non-blocking function, which
- * returns directly without waiting for all data to be written to the TX register. When
- * all data is written to the TX register in the ISR, the UART driver calls the callback
- * function and passes the @ref kStatus_UART_TxIdle as status parameter.
- *
- * @note The function #HAL_UartSendBlocking and the function #HAL_UartTransferSendNonBlocking
- * cannot be used at the same time.
- *
- * @param handle UART handle pointer.
- * @param transfer UART transfer structure. See #hal_uart_transfer_t.
- * @retval kStatus_HAL_UartSuccess Successfully start the data transmission.
- * @retval kStatus_HAL_UartTxBusy Previous transmission still not finished; data not all written to TX register yet.
- * @retval kStatus_HAL_UartError An error occurred.
- */
-hal_uart_status_t HAL_UartTransferSendNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer);
-
-/*!
- * @brief Gets the number of bytes that have been received.
- *
- * This function gets the number of bytes that have been received.
- *
- * @param handle UART handle pointer.
- * @param count Receive bytes count.
- * @retval kStatus_HAL_UartError An error occurred.
- * @retval kStatus_Success Get successfully through the parameter \p count.
- */
-hal_uart_status_t HAL_UartTransferGetReceiveCount(hal_uart_handle_t handle, uint32_t *count);
-
-/*!
- * @brief Gets the number of bytes written to the UART TX register.
- *
- * This function gets the number of bytes written to the UART TX
- * register by using the interrupt method.
- *
- * @param handle UART handle pointer.
- * @param count Send bytes count.
- * @retval kStatus_HAL_UartError An error occurred.
- * @retval kStatus_Success Get successfully through the parameter \p count.
- */
-hal_uart_status_t HAL_UartTransferGetSendCount(hal_uart_handle_t handle, uint32_t *count);
-
-/*!
- * @brief Aborts the interrupt-driven data receiving.
- *
- * This function aborts the interrupt-driven data receiving. The user can get the remainBytes to know
- * how many bytes are not received yet.
- *
- * @note The function #HAL_UartTransferAbortReceive cannot be used to abort the transmission of
- * the function #HAL_UartReceiveBlocking.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_Success Get successfully abort the receiving.
- */
-hal_uart_status_t HAL_UartTransferAbortReceive(hal_uart_handle_t handle);
-
-/*!
- * @brief Aborts the interrupt-driven data sending.
- *
- * This function aborts the interrupt-driven data sending. The user can get the remainBytes to find out
- * how many bytes are not sent out.
- *
- * @note The function #HAL_UartTransferAbortSend cannot be used to abort the transmission of
- * the function #HAL_UartSendBlocking.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_Success Get successfully abort the sending.
- */
-hal_uart_status_t HAL_UartTransferAbortSend(hal_uart_handle_t handle);
-
-/*! @}*/
-
-#else
-
-/*!
- * @name Functional API with non-blocking mode.
- * @note The functional API and the transactional API cannot be used at the same time. The macro
- * #HAL_UART_TRANSFER_MODE is used to set which one will be used. If #HAL_UART_TRANSFER_MODE is zero, the
- * functional API with non-blocking mode will be used. Otherwise, transactional API will be used.
- * @{
- */
-
-/*!
- * @brief Installs a callback and callback parameter.
- *
- * This function is used to install the callback and callback parameter for UART module.
- * When non-blocking sending or receiving finished, the adapter will notify the upper layer by the installed callback
- * function. And the status is also passed as status parameter when the callback is called.
- *
- * @param handle UART handle pointer.
- * @param callback The callback function.
- * @param callbackParam The parameter of the callback function.
- * @retval kStatus_HAL_UartSuccess Successfully install the callback.
- */
-hal_uart_status_t HAL_UartInstallCallback(hal_uart_handle_t handle,
- hal_uart_transfer_callback_t callback,
- void *callbackParam);
-
-/*!
- * @brief Receives a buffer of data using an interrupt method.
- *
- * This function receives data using an interrupt method. This is a non-blocking function, which
- * returns directly without waiting for all data to be received.
- * The receive request is saved by the UART adapter.
- * When the new data arrives, the receive request is serviced first.
- * When all data is received, the UART adapter notifies the upper layer
- * through a callback function and passes the status parameter @ref kStatus_UART_RxIdle.
- *
- * @note The function #HAL_UartReceiveBlocking and the function #HAL_UartReceiveNonBlocking
- * cannot be used at the same time.
- *
- * @param handle UART handle pointer.
- * @param data Start address of the data to write.
- * @param length Size of the data to write.
- * @retval kStatus_HAL_UartSuccess Successfully queue the transfer into transmit queue.
- * @retval kStatus_HAL_UartRxBusy Previous receive request is not finished.
- * @retval kStatus_HAL_UartError An error occurred.
- */
-hal_uart_status_t HAL_UartReceiveNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length);
-
-/*!
- * @brief Transmits a buffer of data using the interrupt method.
- *
- * This function sends data using an interrupt method. This is a non-blocking function, which
- * returns directly without waiting for all data to be written to the TX register. When
- * all data is written to the TX register in the ISR, the UART driver calls the callback
- * function and passes the @ref kStatus_UART_TxIdle as status parameter.
- *
- * @note The function #HAL_UartSendBlocking and the function #HAL_UartSendNonBlocking
- * cannot be used at the same time.
- *
- * @param handle UART handle pointer.
- * @param data Start address of the data to write.
- * @param length Size of the data to write.
- * @retval kStatus_HAL_UartSuccess Successfully start the data transmission.
- * @retval kStatus_HAL_UartTxBusy Previous transmission still not finished; data not all written to TX register yet.
- * @retval kStatus_HAL_UartError An error occurred.
- */
-hal_uart_status_t HAL_UartSendNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length);
-
-/*!
- * @brief Gets the number of bytes that have been received.
- *
- * This function gets the number of bytes that have been received.
- *
- * @param handle UART handle pointer.
- * @param count Receive bytes count.
- * @retval kStatus_HAL_UartError An error occurred.
- * @retval kStatus_Success Get successfully through the parameter \p count.
- */
-hal_uart_status_t HAL_UartGetReceiveCount(hal_uart_handle_t handle, uint32_t *reCount);
-
-/*!
- * @brief Gets the number of bytes written to the UART TX register.
- *
- * This function gets the number of bytes written to the UART TX
- * register by using the interrupt method.
- *
- * @param handle UART handle pointer.
- * @param count Send bytes count.
- * @retval kStatus_HAL_UartError An error occurred.
- * @retval kStatus_Success Get successfully through the parameter \p count.
- */
-hal_uart_status_t HAL_UartGetSendCount(hal_uart_handle_t handle, uint32_t *seCount);
-
-/*!
- * @brief Aborts the interrupt-driven data receiving.
- *
- * This function aborts the interrupt-driven data receiving. The user can get the remainBytes to know
- * how many bytes are not received yet.
- *
- * @note The function #HAL_UartAbortReceive cannot be used to abort the transmission of
- * the function #HAL_UartReceiveBlocking.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_Success Get successfully abort the receiving.
- */
-hal_uart_status_t HAL_UartAbortReceive(hal_uart_handle_t handle);
-
-/*!
- * @brief Aborts the interrupt-driven data sending.
- *
- * This function aborts the interrupt-driven data sending. The user can get the remainBytes to find out
- * how many bytes are not sent out.
- *
- * @note The function #HAL_UartAbortSend cannot be used to abort the transmission of
- * the function #HAL_UartSendBlocking.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_Success Get successfully abort the sending.
- */
-hal_uart_status_t HAL_UartAbortSend(hal_uart_handle_t handle);
-
-/*! @}*/
-
-#endif
-#endif
-
-/*!
- * @brief Prepares to enter low power consumption.
- *
- * This function is used to prepare to enter low power consumption.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_HAL_UartSuccess Successful operation.
- * @retval kStatus_HAL_UartError An error occurred.
- */
-hal_uart_status_t HAL_UartEnterLowpower(hal_uart_handle_t handle);
-
-/*!
- * @brief Restores from low power consumption.
- *
- * This function is used to restore from low power consumption.
- *
- * @param handle UART handle pointer.
- * @retval kStatus_HAL_UartSuccess Successful operation.
- * @retval kStatus_HAL_UartError An error occurred.
- */
-hal_uart_status_t HAL_UartExitLowpower(hal_uart_handle_t handle);
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-/*!
- * @brief UART IRQ handle function.
- *
- * This function handles the UART transmit and receive IRQ request.
- *
- * @param handle UART handle pointer.
- */
-void HAL_UartIsrFunction(hal_uart_handle_t handle);
-#endif
-
-#if defined(__cplusplus)
-}
-#endif
-/*! @}*/
-#endif /* __HAL_UART_ADAPTER_H__ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/components/uart/usart_adapter.c b/platform/ext/target/nxp/common/Native_Driver/components/uart/usart_adapter.c
deleted file mode 100755
index 1628a9e6d..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/components/uart/usart_adapter.c
+++ /dev/null
@@ -1,643 +0,0 @@
-/*
- * Copyright 2018 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_common.h"
-#include "fsl_usart.h"
-#include "fsl_flexcomm.h"
-
-#include "uart.h"
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-#ifndef NDEBUG
-#if (defined(DEBUG_CONSOLE_ASSERT_DISABLE) && (DEBUG_CONSOLE_ASSERT_DISABLE > 0U))
-#undef assert
-#define assert(n)
-#endif
-#endif
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-/*! @brief uart RX state structure. */
-typedef struct _hal_uart_receive_state
-{
- volatile uint8_t *buffer;
- volatile uint32_t bufferLength;
- volatile uint32_t bufferSofar;
-} hal_uart_receive_state_t;
-
-/*! @brief uart TX state structure. */
-typedef struct _hal_uart_send_state
-{
- volatile uint8_t *buffer;
- volatile uint32_t bufferLength;
- volatile uint32_t bufferSofar;
-} hal_uart_send_state_t;
-#endif
-/*! @brief uart state structure. */
-typedef struct _hal_uart_state
-{
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
- hal_uart_transfer_callback_t callback;
- void *callbackParam;
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- usart_handle_t hardwareHandle;
-#endif
- hal_uart_receive_state_t rx;
- hal_uart_send_state_t tx;
-#endif
- uint8_t instance;
-} hal_uart_state_t;
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-static USART_Type *const s_UsartAdapterBase[] = USART_BASE_PTRS;
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-
-#if !(defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
-/* Array of USART IRQ number. */
-static const IRQn_Type s_UsartIRQ[] = USART_IRQS;
-#endif
-
-#endif
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
-static hal_uart_status_t HAL_UartGetStatus(status_t status)
-{
- hal_uart_status_t uartStatus = kStatus_HAL_UartError;
- switch (status)
- {
- case kStatus_Success:
- uartStatus = kStatus_HAL_UartSuccess;
- break;
- case kStatus_USART_TxBusy:
- uartStatus = kStatus_HAL_UartTxBusy;
- break;
- case kStatus_USART_RxBusy:
- uartStatus = kStatus_HAL_UartRxBusy;
- break;
- case kStatus_USART_TxIdle:
- uartStatus = kStatus_HAL_UartTxIdle;
- break;
- case kStatus_USART_RxIdle:
- uartStatus = kStatus_HAL_UartRxIdle;
- break;
- case kStatus_USART_BaudrateNotSupport:
- uartStatus = kStatus_HAL_UartBaudrateNotSupport;
- break;
- case kStatus_USART_NoiseError:
- case kStatus_USART_FramingError:
- case kStatus_USART_ParityError:
- uartStatus = kStatus_HAL_UartProtocolError;
- break;
- default:
- break;
- }
- return uartStatus;
-}
-#else
-static hal_uart_status_t HAL_UartGetStatus(status_t status)
-{
- if (kStatus_Success == status)
- {
- return kStatus_HAL_UartSuccess;
- }
- else
- {
- return kStatus_HAL_UartError;
- }
-}
-#endif
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
-static void HAL_UartCallback(USART_Type *base, usart_handle_t *handle, status_t status, void *callbackParam)
-{
- hal_uart_state_t *uartHandle;
- hal_uart_status_t uartStatus = HAL_UartGetStatus(status);
- assert(callbackParam);
-
- uartHandle = (hal_uart_state_t *)callbackParam;
-
- if (kStatus_HAL_UartProtocolError == uartStatus)
- {
- if (uartHandle->hardwareHandle.rxDataSize)
- {
- uartStatus = kStatus_HAL_UartError;
- }
- }
-
- if (uartHandle->callback)
- {
- uartHandle->callback(uartHandle, uartStatus, uartHandle->callbackParam);
- }
-}
-
-#else
-
-static void HAL_UartInterruptHandle(USART_Type *base, void *handle)
-{
- hal_uart_state_t *uartHandle = (hal_uart_state_t *)handle;
- uint32_t status;
- uint8_t instance;
-
- if (NULL == uartHandle)
- {
- return;
- }
- instance = uartHandle->instance;
-
- status = USART_GetStatusFlags(s_UsartAdapterBase[instance]);
-
- /* Receive data register full */
- if ((USART_FIFOSTAT_RXNOTEMPTY_MASK & status) &&
- (USART_GetEnabledInterrupts(s_UsartAdapterBase[instance]) & USART_FIFOINTENSET_RXLVL_MASK))
- {
- if (uartHandle->rx.buffer)
- {
- uartHandle->rx.buffer[uartHandle->rx.bufferSofar++] = USART_ReadByte(s_UsartAdapterBase[instance]);
- if (uartHandle->rx.bufferSofar >= uartHandle->rx.bufferLength)
- {
- USART_DisableInterrupts(s_UsartAdapterBase[instance],
- USART_FIFOINTENCLR_RXLVL_MASK | USART_FIFOINTENCLR_RXERR_MASK);
- uartHandle->rx.buffer = NULL;
- if (uartHandle->callback)
- {
- uartHandle->callback(uartHandle, kStatus_HAL_UartRxIdle, uartHandle->callbackParam);
- }
- }
- }
- }
-
- /* Send data register empty and the interrupt is enabled. */
- if ((USART_FIFOSTAT_TXNOTFULL_MASK & status) &&
- (USART_GetEnabledInterrupts(s_UsartAdapterBase[instance]) & USART_FIFOINTENSET_TXLVL_MASK))
- {
- if (uartHandle->tx.buffer)
- {
- USART_WriteByte(s_UsartAdapterBase[instance], uartHandle->tx.buffer[uartHandle->tx.bufferSofar++]);
- if (uartHandle->tx.bufferSofar >= uartHandle->tx.bufferLength)
- {
- USART_DisableInterrupts(s_UsartAdapterBase[instance], USART_FIFOINTENCLR_TXLVL_MASK);
- uartHandle->tx.buffer = NULL;
- if (uartHandle->callback)
- {
- uartHandle->callback(uartHandle, kStatus_HAL_UartTxIdle, uartHandle->callbackParam);
- }
- }
- }
- }
-
-#if 1
- USART_ClearStatusFlags(s_UsartAdapterBase[instance], status);
-#endif
-}
-#endif
-
-#endif
-
-hal_uart_status_t HAL_UartInit(hal_uart_handle_t handle, hal_uart_config_t *config)
-{
- hal_uart_state_t *uartHandle;
- usart_config_t usartConfig;
- status_t status;
- assert(handle);
- assert(config);
- assert(config->instance < (sizeof(s_UsartAdapterBase) / sizeof(USART_Type *)));
- assert(s_UsartAdapterBase[config->instance]);
-
- if (HAL_UART_HANDLE_SIZE < sizeof(hal_uart_state_t))
- {
- return kStatus_HAL_UartError;
- }
-
- USART_GetDefaultConfig(&usartConfig);
- usartConfig.baudRate_Bps = config->baudRate_Bps;
-
- if (kHAL_UartParityEven == config->parityMode)
- {
- usartConfig.parityMode = kUSART_ParityEven;
- }
- else if (kHAL_UartParityOdd == config->parityMode)
- {
- usartConfig.parityMode = kUSART_ParityOdd;
- }
- else
- {
- usartConfig.parityMode = kUSART_ParityDisabled;
- }
-
- if (kHAL_UartTwoStopBit == config->stopBitCount)
- {
- usartConfig.stopBitCount = kUSART_TwoStopBit;
- }
- else
- {
- usartConfig.stopBitCount = kUSART_OneStopBit;
- }
- usartConfig.enableRx = config->enableRx;
- usartConfig.enableTx = config->enableTx;
- usartConfig.txWatermark = kUSART_TxFifo0;
- usartConfig.rxWatermark = kUSART_RxFifo1;
-
- status = USART_Init(s_UsartAdapterBase[config->instance], &usartConfig, config->srcClock_Hz);
-
- if (kStatus_Success != status)
- {
- return HAL_UartGetStatus(status);
- }
-
- uartHandle = (hal_uart_state_t *)handle;
- uartHandle->instance = config->instance;
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
- USART_TransferCreateHandle(s_UsartAdapterBase[config->instance], &uartHandle->hardwareHandle,
- (usart_transfer_callback_t)HAL_UartCallback, handle);
-#else
- /* Enable interrupt in NVIC. */
- FLEXCOMM_SetIRQHandler(s_UsartAdapterBase[config->instance], (flexcomm_irq_handler_t)HAL_UartInterruptHandle,
- handle);
- NVIC_SetPriority((IRQn_Type)s_UsartIRQ[config->instance], HAL_UART_ISR_PRIORITY);
- EnableIRQ(s_UsartIRQ[config->instance]);
-#endif
-
-#endif
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartDeinit(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
-
- assert(handle);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- USART_Deinit(s_UsartAdapterBase[uartHandle->instance]);
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartReceiveBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
-{
- hal_uart_state_t *uartHandle;
- status_t status;
- assert(handle);
- assert(data);
- assert(length);
-
- uartHandle = (hal_uart_state_t *)handle;
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
- if (uartHandle->rx.buffer)
- {
- return kStatus_HAL_UartRxBusy;
- }
-#endif
-
- status = USART_ReadBlocking(s_UsartAdapterBase[uartHandle->instance], data, length);
-
- return HAL_UartGetStatus(status);
-}
-
-hal_uart_status_t HAL_UartSendBlocking(hal_uart_handle_t handle, const uint8_t *data, size_t length)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(data);
- assert(length);
-
- uartHandle = (hal_uart_state_t *)handle;
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
- if (uartHandle->tx.buffer)
- {
- return kStatus_HAL_UartTxBusy;
- }
-#endif
-
- USART_WriteBlocking(s_UsartAdapterBase[uartHandle->instance], data, length);
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartEnterLowpower(hal_uart_handle_t handle)
-{
- assert(handle);
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartExitLowpower(hal_uart_handle_t handle)
-{
- assert(handle);
-
- return kStatus_HAL_UartSuccess;
-}
-
-#if (defined(UART_ADAPTER_NON_BLOCKING_MODE) && (UART_ADAPTER_NON_BLOCKING_MODE > 0U))
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
-
-hal_uart_status_t HAL_UartTransferInstallCallback(hal_uart_handle_t handle,
- hal_uart_transfer_callback_t callback,
- void *callbackParam)
-{
- hal_uart_state_t *uartHandle;
-
- assert(handle);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- uartHandle->callbackParam = callbackParam;
- uartHandle->callback = callback;
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartTransferReceiveNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer)
-{
- hal_uart_state_t *uartHandle;
- status_t status;
- assert(handle);
- assert(transfer);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- status = USART_TransferReceiveNonBlocking(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle,
- (usart_transfer_t *)transfer, NULL);
-
- return HAL_UartGetStatus(status);
-}
-
-hal_uart_status_t HAL_UartTransferSendNonBlocking(hal_uart_handle_t handle, hal_uart_transfer_t *transfer)
-{
- hal_uart_state_t *uartHandle;
- status_t status;
- assert(handle);
- assert(transfer);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- status = USART_TransferSendNonBlocking(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle,
- (usart_transfer_t *)transfer);
-
- return HAL_UartGetStatus(status);
-}
-
-hal_uart_status_t HAL_UartTransferGetReceiveCount(hal_uart_handle_t handle, uint32_t *count)
-{
- hal_uart_state_t *uartHandle;
- status_t status;
- assert(handle);
- assert(count);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- status =
- USART_TransferGetReceiveCount(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle, count);
-
- return HAL_UartGetStatus(status);
-}
-
-hal_uart_status_t HAL_UartTransferGetSendCount(hal_uart_handle_t handle, uint32_t *count)
-{
- hal_uart_state_t *uartHandle;
- status_t status;
- assert(handle);
- assert(count);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- status = USART_TransferGetSendCount(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle, count);
-
- return HAL_UartGetStatus(status);
-}
-
-hal_uart_status_t HAL_UartTransferAbortReceive(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- USART_TransferAbortReceive(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle);
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartTransferAbortSend(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- USART_TransferAbortSend(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle);
-
- return kStatus_HAL_UartSuccess;
-}
-
-#else
-
-/* None transactional API with non-blocking mode. */
-hal_uart_status_t HAL_UartInstallCallback(hal_uart_handle_t handle,
- hal_uart_transfer_callback_t callback,
- void *callbackParam)
-{
- hal_uart_state_t *uartHandle;
-
- assert(handle);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- uartHandle->callbackParam = callbackParam;
- uartHandle->callback = callback;
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartReceiveNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(data);
- assert(length);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- if (uartHandle->rx.buffer)
- {
- return kStatus_HAL_UartRxBusy;
- }
-
- uartHandle->rx.bufferLength = length;
- uartHandle->rx.bufferSofar = 0;
- uartHandle->rx.buffer = data;
- USART_EnableInterrupts(s_UsartAdapterBase[uartHandle->instance], USART_FIFOINTENSET_RXLVL_MASK);
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartSendNonBlocking(hal_uart_handle_t handle, uint8_t *data, size_t length)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(data);
- assert(length);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- if (uartHandle->tx.buffer)
- {
- return kStatus_HAL_UartTxBusy;
- }
- uartHandle->tx.bufferLength = length;
- uartHandle->tx.bufferSofar = 0;
- uartHandle->tx.buffer = (volatile uint8_t *)data;
- USART_EnableInterrupts(s_UsartAdapterBase[uartHandle->instance], USART_FIFOINTENSET_TXLVL_MASK);
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartGetReceiveCount(hal_uart_handle_t handle, uint32_t *reCount)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(reCount);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- if (uartHandle->rx.buffer)
- {
- *reCount = uartHandle->rx.bufferSofar;
- return kStatus_HAL_UartSuccess;
- }
- return kStatus_HAL_UartError;
-}
-
-hal_uart_status_t HAL_UartGetSendCount(hal_uart_handle_t handle, uint32_t *seCount)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(seCount);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- if (uartHandle->tx.buffer)
- {
- *seCount = uartHandle->tx.bufferSofar;
- return kStatus_HAL_UartSuccess;
- }
- return kStatus_HAL_UartError;
-}
-
-hal_uart_status_t HAL_UartAbortReceive(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- if (uartHandle->rx.buffer)
- {
- USART_DisableInterrupts(s_UsartAdapterBase[uartHandle->instance],
- USART_FIFOINTENCLR_RXLVL_MASK | USART_FIFOINTENCLR_RXERR_MASK);
- uartHandle->rx.buffer = NULL;
- }
-
- return kStatus_HAL_UartSuccess;
-}
-
-hal_uart_status_t HAL_UartAbortSend(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
- if (uartHandle->tx.buffer)
- {
- USART_DisableInterrupts(s_UsartAdapterBase[uartHandle->instance], USART_FIFOINTENCLR_TXLVL_MASK);
- uartHandle->tx.buffer = NULL;
- }
-
- return kStatus_HAL_UartSuccess;
-}
-
-#endif
-
-#if (defined(HAL_UART_TRANSFER_MODE) && (HAL_UART_TRANSFER_MODE > 0U))
-
-void HAL_UartIsrFunction(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
-#if 0
- DisableIRQ(s_UsartIRQ[uartHandle->instance]);
-#endif
- USART_TransferHandleIRQ(s_UsartAdapterBase[uartHandle->instance], &uartHandle->hardwareHandle);
-#if 0
- NVIC_SetPriority((IRQn_Type)s_UsartIRQ[uartHandle->instance], HAL_UART_ISR_PRIORITY);
- EnableIRQ(s_UsartIRQ[uartHandle->instance]);
-#endif
-}
-
-#else
-
-void HAL_UartIsrFunction(hal_uart_handle_t handle)
-{
- hal_uart_state_t *uartHandle;
- assert(handle);
- assert(!HAL_UART_TRANSFER_MODE);
-
- uartHandle = (hal_uart_state_t *)handle;
-
-#if 0
- DisableIRQ(s_UsartIRQ[uartHandle->instance]);
-#endif
- HAL_UartInterruptHandle(s_UsartAdapterBase[uartHandle->instance], (void *)uartHandle);
-#if 0
- NVIC_SetPriority((IRQn_Type)s_UsartIRQ[uartHandle->instance], HAL_UART_ISR_PRIORITY);
- EnableIRQ(s_UsartIRQ[uartHandle->instance]);
-#endif
-}
-
-#endif
-
-#endif
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.c
deleted file mode 100755
index 34c3c2a94..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.c
+++ /dev/null
@@ -1,2668 +0,0 @@
-/*
- * Copyright 2018-2019 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_casper.h"
-#include <math.h> /* ceil TODO check if really need it */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.casper"
-#endif
-
-#if defined(__GNUC__)
-/* Enforce O1 optimize level, specifically to remove strict-aliasing option.
- (-fno-strict-aliasing is required for this driver). */
-#pragma GCC push_options
-#pragma GCC optimize("-O1")
-#endif
-
-#define CASPER_RAM_BASE_NS (FSL_FEATURE_CASPER_RAM_BASE_ADDRESS)
-
-#if defined(FSL_FEATURE_CASPER_RAM_IS_INTERLEAVED) && FSL_FEATURE_CASPER_RAM_IS_INTERLEAVED
-#define CASPER_RAM_OFFSET (0xE)
-#define INTERLEAVE(addr) \
- (((((((addr) >> 2) & 0x00000001) << CASPER_RAM_OFFSET) + (((addr) >> 3) << 2) + ((addr)&0x00000003)) & 0xFFFF) | \
- s_casperRamBase)
-#define DEINTERLEAVE(addr) INTERLEAVE(addr)
-#define GET_WORD(addr) (*((uint32_t *)DEINTERLEAVE((uint32_t)(addr))))
-#define GET_DWORD(addr) (((uint64_t)GET_WORD(addr)) | (((uint64_t)GET_WORD(((uint32_t)(addr)) + 4)) << 32))
-#define SET_WORD(addr, value) *((uint32_t *)INTERLEAVE((uint32_t)(addr))) = ((uint32_t)(value))
-#define SET_DWORD(addr, value) \
- do \
- { \
- SET_WORD(addr, (uint32_t)(value & 0xFFFFFFFF)); \
- SET_WORD(((uint32_t)(addr)) + 4, (uint32_t)((value & 0xFFFFFFFF00000000) >> 32)); \
- } while (0)
-
-/* memcopy is always word aligned */
-/* interleaved to interleaved
- static void CASPER_MEMCPY_I2I(void *dst, const void *src, size_t siz)
- */
-#define CASPER_MEMCPY_I2I(dst, src, siz) \
- \
- { \
- uint32_t *dst32 = (uint32_t *)dst, *src32 = (uint32_t *)src; \
- uint32_t i; \
- for (i = 0; i < siz / 4; i++) \
- { \
- SET_WORD(&dst32[i], GET_WORD(&src32[i])); \
- } \
- }
-
-/* interleaved to non-interleaved
- static void CASPER_MEMCPY_I2N(void *dst, const void *src, size_t siz)
- */
-#define CASPER_MEMCPY_I2N(dst, src, siz) \
- \
- { \
- uint32_t *dst32 = (uint32_t *)dst, *src32 = (uint32_t *)src; \
- uint32_t i; \
- for (i = 0; i < siz / 4; i++) \
- { \
- dst32[i] = GET_WORD(&src32[i]); \
- } \
- }
-
-/* non-interleaved to interleaved
- static void CASPER_MEMCPY_N2I(void *dst, const void *src, size_t siz)
- */
-#define CASPER_MEMCPY_N2I(dst, src, siz) \
- \
- { \
- volatile uint32_t *dst32 = (uint32_t *)dst, *src32 = (uint32_t *)src; \
- volatile uint32_t i; \
- for (i = 0; i < siz / 4; i++) \
- { \
- SET_WORD(&dst32[i], src32[i]); \
- } \
- }
-#else
-#define GET_WORD(addr) (*((uint32_t *)(addr)))
-#define GET_DWORD(addr) (*((uint64_t *)(addr)))
-#define SET_WORD(addr, value) *((uint32_t *)(addr)) = ((uint32_t)(value))
-#define SET_DWORD(addr, value) *((uint64_t *)(addr)) = ((uint64_t)(value))
-
-#define CASPER_MEMCPY_I2I(dst, src, siz) memcpy(dst, src, siz)
-#define CASPER_MEMCPY_I2N(dst, src, siz) memcpy(dst, src, siz)
-#define CASPER_MEMCPY_N2I(dst, src, siz) memcpy(dst, src, siz)
-#endif
-
-#define WORK_BUFF_MUL4 (N_wordlen_max * 4 + 2) /* ! working buffer is 4xN_wordlen to allow in place math */
-#define N_bytelen (N_wordlen * 4) /* for memory copy and the like */
-#define N_dwordlen (N_wordlen / 2)
-
-#define PreZeroW(i, w_out) \
- for (i = 0; i < N_wordlen; i += 4) \
- { \
- SET_WORD(&w_out[i + 0], 0); \
- SET_WORD(&w_out[i + 1], 0); \
- SET_WORD(&w_out[i + 2], 0); \
- SET_WORD(&w_out[i + 3], 0); \
- } /* unrolled partly */
-#define PreZeroW2up(i, w_out) \
- for (i = N_wordlen; i <= N_wordlen * 2; i += 4) \
- { \
- SET_WORD(&w_out[i + 0], 0); \
- SET_WORD(&w_out[i + 1], 0); \
- SET_WORD(&w_out[i + 2], 0); \
- SET_WORD(&w_out[i + 3], 0); \
- } /* unrolled partly */
-
-/* Macros for the ECC component in Casper */
-
-/* CASPER memory layout for ECC */
-#define CASPER_NUM_LIMBS (NUM_LIMBS + 4) // number of limbs needed by CASPER is 2 double words longer
-
-#define CASPER_MEM ((uint32_t *)msg_ret)
-#define CASPER_OFFSET CASPER_NUM_LIMBS // offset in the CASPER memory where we can start writing
-
-#define MOD_SCRATCH_START (CASPER_OFFSET)
-#define MOD_SCRATCH_SIZE (1 * CASPER_NUM_LIMBS)
-
-#define INOUT_SCRATCH_START (MOD_SCRATCH_START + MOD_SCRATCH_SIZE)
-#define INOUT_SCRATCH_SIZE ((3 * 3) * CASPER_NUM_LIMBS)
-
-#define ECC_SCRATCH_START (INOUT_SCRATCH_START + INOUT_SCRATCH_SIZE)
-#define ECC_SCRATCH_SIZE (9 * CASPER_NUM_LIMBS)
-
-#define LUT_SCRATCH_START (ECC_SCRATCH_START + ECC_SCRATCH_SIZE)
-#define LUT_SCRATCH_SIZE (48 * NUM_LIMBS + 3 * CASPER_NUM_LIMBS)
-
-/* Currently these macros work on 32-bit platforms */
-
-#define add(c1, c0, a, b) \
- \
- do \
- { \
- uint32_t _t; \
- _t = a + b; \
- c1 = (_t < a); \
- c0 = _t; \
- \
- } while (0)
-
-#define add_cout(carry, c, a, b) add(carry, c, a, b)
-
-#define add_cout_cin(carryout, c, a, b, carryin) \
- do \
- { \
- uint64_t _t = (uint64_t)a + b + carryin; \
- c = (uint32_t)_t; \
- carryout = (uint32_t)(_t >> 32); \
- } while (0)
-
-#define sub_borrowout(borrow, c, a, b) \
- do \
- { \
- uint32_t _b = (b > a); \
- c = a - b; \
- borrow = _b; \
- } while (0)
-
-#define sub_borrowin_borrowout(borrowout, c, a, b, borrowin) \
- do \
- { \
- uint32_t _t, _borrow1, _borrow2; \
- sub_borrowout(_borrow1, _t, a, b); \
- sub_borrowout(_borrow2, c, _t, borrowin); \
- borrowout = _borrow1 + _borrow2; \
- } while (0)
-
-#define sub_borrowout_1(borrow, c, a) \
- do \
- { \
- uint32_t _b = 0; \
- c = a - b; \
- borrow = _b; \
- } while (0)
-
-#define sub_borrowin_borrowout_1(borrowout, c, a, borrowin) \
- do \
- { \
- uint32_t _t, _borrow1, _borrow2; \
- sub_borrowout_1(_borrow1, _t, a); \
- sub_borrowout(_borrow2, c, _t, borrowin); \
- borrowout = _borrow1 + _borrow2; \
- } while (0)
-
-/* 32 x 32 --> 64-bit multiplication
- * (c1,c0) = a * b
- */
-#define mul(c1, c0, a, b) \
- \
- do \
- { \
- uint64_t __m; \
- __m = (uint64_t)a * (uint64_t)b; \
- c0 = (uint32_t)__m; \
- c1 = (uint32_t)(__m >> (uint64_t)32); \
- \
- } while (0)
-
-/* Multiply-and-accumulate
- * (c1,c0) = a*b+c0
- */
-#define muladd(c1, c0, a, b) \
- \
- do \
- { \
- uint32_t __ma = c0; \
- mul(c1, c0, a, b); \
- c0 = c0 + __ma; \
- c1 = c1 + (c0 < __ma); \
- \
- } while (0)
-
-/* Multiply-and-accumulate-accumulate
- * (c1,c0) = a*b+c0+c1
- */
-#define muladdadd(c1, c0, a, b) \
- \
- do \
- { \
- uint32_t __maa0 = c0, __maa1 = c1; \
- mul(c1, c0, a, b); \
- c0 = c0 + __maa0; \
- c1 = c1 + (c0 < __maa0); \
- c0 = c0 + __maa1; \
- c1 = c1 + (c0 < __maa1); \
- \
- } while (0)
-
-#if CASPER_ECC_P256
-
-/* Recoding length for the secure scalar multiplication:
- * Use n=256 and w=4 --> compute ciel(384/3) = 86 + 1 digits
- */
-#define CASPER_RECODE_LENGTH 87
-#define invert(c, a) invert_mod_p256(c, a)
-#define ONE NISTr256
-
-/* Shift right by 1 <= c <= 31. z[] and x[] in system RAM, no interleaving macros used. */
-#define shiftrightSysram(z, x, c) \
- do \
- { \
- z[0] = (x[1] << (32 - (c))) | (x[0] >> (c)); \
- z[1] = (x[2] << (32 - (c))) | (x[1] >> (c)); \
- z[2] = (x[3] << (32 - (c))) | (x[2] >> (c)); \
- z[3] = (x[4] << (32 - (c))) | (x[3] >> (c)); \
- z[4] = (x[5] << (32 - (c))) | (x[4] >> (c)); \
- z[5] = (x[6] << (32 - (c))) | (x[5] >> (c)); \
- z[6] = (x[7] << (32 - (c))) | (x[6] >> (c)); \
- z[7] = (x[7] >> (c)); \
- } while (0)
-
-#elif CASPER_ECC_P384
-
-/* Recoding length for the secure scalar multiplication:
- * Use n=384 and w=4 --> compute ciel(384/3) = 128 + 1 digits
- */
-#define CASPER_RECODE_LENGTH 129
-#define invert(c, a) invert_mod_p384(c, a)
-#define ONE NISTr384
-
-/* Shift right by 1 <= c <= 31. z[] and x[] in system RAM, no interleaving macros used. */
-#define shiftrightSysram(z, x, c) \
- do \
- { \
- z[0] = (x[1] << (32 - (c))) | (x[0] >> (c)); \
- z[1] = (x[2] << (32 - (c))) | (x[1] >> (c)); \
- z[2] = (x[3] << (32 - (c))) | (x[2] >> (c)); \
- z[3] = (x[4] << (32 - (c))) | (x[3] >> (c)); \
- z[4] = (x[5] << (32 - (c))) | (x[4] >> (c)); \
- z[5] = (x[6] << (32 - (c))) | (x[5] >> (c)); \
- z[6] = (x[7] << (32 - (c))) | (x[6] >> (c)); \
- z[7] = (x[8] << (32 - (c))) | (x[7] >> (c)); \
- z[8] = (x[9] << (32 - (c))) | (x[8] >> (c)); \
- z[9] = (x[10] << (32 - (c))) | (x[9] >> (c)); \
- z[10] = (x[11] << (32 - (c))) | (x[10] >> (c)); \
- z[11] = (x[11] >> (c)); \
- } while (0)
-
-#else
-#error "Define proper NIST curve"
-#endif
-
-#define multiply_casper(c, a, b) MultprecCiosMul_ct(c, a, b, &CASPER_MEM[MOD_SCRATCH_START], Np)
-#define square_casper(c, a) multiply_casper(c, a, a)
-#define sub_casper(c, a, b) CASPER_montsub(c, a, b, &CASPER_MEM[MOD_SCRATCH_START])
-#define add_casper(c, a, b) CASPER_montadd(c, a, b, &CASPER_MEM[MOD_SCRATCH_START])
-#define mul2_casper(c, a) add_casper(c, a, a)
-#define half(c, a, b) CASPER_half(c, a, b)
-#define copy(c, a) CASPER_MEMCPY(c, a, NUM_LIMBS * sizeof(uint32_t))
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-
-/* The model for this algo is that it can be implemented for a fixed size RSA key */
-/* for max speed. If this is made into a variable (to allow varying size), then */
-/* it will be slower by a bit. */
-/* The file is compiled with N_bitlen passed in as number of bits of the RSA key */
-/* #define N_bitlen 2048 */
-static size_t N_wordlen = 0; /* ! number of words (e.g. 4096/32 is 128 words) */
-
-static uint32_t s_casperRamBase = CASPER_RAM_BASE_NS;
-static unsigned *msg_ret = (unsigned *)CASPER_RAM_BASE_NS;
-
-#if CASPER_ECC_P256
-/* NISTp-256 = 2^256-2^224+2^192+2^96-1 */
-static uint32_t NISTp256[NUM_LIMBS] = {0xffffffff, 0xffffffff, 0xffffffff, 0x00000000,
- 0x00000000, 0x00000000, 0x00000001, 0xffffffff};
-
-/* The cardinality of the curve E(F_p) */
-static uint32_t NISTp256_q[NUM_LIMBS] = {0xfc632551, 0xf3b9cac2, 0xa7179e84, 0xbce6faad,
- 0xffffffff, 0xffffffff, 0x00000000, 0xffffffff};
-
-/* R = 2^256 mod p, the value "1" in Montgomery form. */
-static uint32_t NISTr256[NUM_LIMBS] = {0x00000001, 0x00000000, 0x00000000, 0xffffffff,
- 0xffffffff, 0xffffffff, 0xfffffffe, 0x00000000};
-
-static uint32_t Np[2] = {1, 0};
-#endif /* CASPER_ECC_P256 */
-
-#if CASPER_ECC_P384
-/* NISTp-384 = 2^384 - 2^128 - 2^96 + 2^32 - 1 */
-static uint32_t NISTp384[NUM_LIMBS] = {0xffffffff, 0x00000000, 0x00000000, 0xffffffff, 0xfffffffe, 0xffffffff,
- 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};
-
-/* The cardinality of the curve E(F_p) */
-static uint32_t NISTp384_q[NUM_LIMBS] = {0xccc52973, 0xecec196a, 0x48b0a77a, 0x581a0db2, 0xf4372ddf, 0xc7634d81,
- 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff};
-
-/* R = 2^256 mod p, the value "1" in Montgomery form. */
-static uint32_t NISTr384[NUM_LIMBS] = {0x00000001, 0xffffffff, 0xffffffff, 0x00000000, 0x1, 0, 0, 0, 0, 0, 0, 0};
-
-// -p^-1 mod 2^64 = 0x100000001
-static uint32_t Np[2] = {1, 1};
-#endif /* CASPER_ECC_P384 */
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-
-/* Convert a projective point (X1 : Y1 : Z1)
- * to the affine point (X3, Y3) = (X1/Z1^2,Y1/Z1^3)
- * The memory of (X3, Y3) and (X1 : Y1 : Z1) should not overlap
- */
-void Jac_toAffine(uint32_t *X3, uint32_t *Y3, uint32_t *X1, uint32_t *Y1, uint32_t *Z1);
-
-/* Return 1 if (X1: Y1: Z1) is on the curve
- * Y^2 = X^3 -3XZ^4 + bZ^6
- * and return 0 otherwise.
- */
-int Jac_oncurve(uint32_t *X1, uint32_t *Y1, uint32_t *Z1, uint32_t *b);
-
-/* Compute (X3 : Y3: Z3) = (X1: Y1: Z1) + (X2 : Y2 : Z2)
- * where (X1: Y1: Z1) != (X2 : Y2 : Z2)
- * (X3 : Y3: Z3) may be the same as one of the inputs.
- */
-void Jac_addition(uint32_t *X3,
- uint32_t *Y3,
- uint32_t *Z3,
- uint32_t *X1,
- uint32_t *Y1,
- uint32_t *Z1,
- uint32_t *X2,
- uint32_t *Y2,
- uint32_t *Z2);
-
-/* Compute (X3 : Y3: Z3) = (X1: Y1: Z1) + (X2, Y2)
- * where (X1: Y1: Z1) != (X2, Y2)
- * (X3 : Y3: Z3) may not overlap with (X1: Y1: Z1).
- * Source: 2004 Hankerson–Menezes–Vanstone, page 91.
- */
-void Jac_add_affine(
- uint32_t *X3, uint32_t *Y3, uint32_t *Z3, uint32_t *X1, uint32_t *Y1, uint32_t *Z1, uint32_t *X2, uint32_t *Y2);
-
-/* Point doubling from: 2004 Hankerson–Menezes–Vanstone, page 91.
- * Compute (X3 : Y3: Z3) = (X1: Y1: Z1) + (X1 : Y1 : Z1)
- * (X3 : Y3: Z3) may be the same as the input.
- */
-void Jac_double(uint32_t *X3, uint32_t *Y3, uint32_t *Z3, uint32_t *X1, uint32_t *Y1, uint32_t *Z1);
-
-/* Constant time elliptic curve scalar multiplication.
- * Source: https://eprint.iacr.org/2014/130.pdf
- * when using w = 4.
- * Computes (X3 : Y3 : Z3) = k * (X1, Y1) \in E(F_p)
- * p is the prime used to define the finite field F_p
- * q is the (prime) order of the curve
- */
-void Jac_scalar_multiplication(
- uint32_t *X3, uint32_t *Y3, uint32_t *Z3, uint32_t *X1, uint32_t *Y1, uint32_t *k, uint32_t *p, uint32_t *q);
-
-/* Compute the double scalar multiplication
- * (X3 : Y3 : Z3) = k1 * (X1, Y1) + k2 * (X2, Y2)
- * Using Shamir's trick and precomputing 16 points.
- * This code is *not* constant time since this is used
- * for verification only.
- */
-void double_scalar_multiplication(uint32_t *X3,
- uint32_t *Y3,
- uint32_t *Z3,
- uint32_t *X1,
- uint32_t *Y1,
- uint32_t *k1,
- uint32_t *X2,
- uint32_t *Y2,
- uint32_t *k2);
-
-#if CASPER_ECC_P384
-/* Compute inversion modulo NIST-p384 using Fermats little theorem.
- * Using c = a^(p-2) = a^(-1) mod p.
- * This computes the modular inversion if all arithmetic is "regular"
- * modular arithmetic or computes automatically the Montgomery inverse
- * if all arithmetic is Montgomery arithmetic.
- */
-static void invert_mod_p384(uint32_t *c, uint32_t *a);
-#endif /* CASPER_ECC_P384 */
-
-#if CASPER_ECC_P256
-/* Modular inversion for NIST-P256 */
-static void invert_mod_p256(uint32_t *c, uint32_t *a);
-#endif /* CASPER_ECC_P256 */
-
-// A and C do not need to be in Casper memory
-static void toMontgomery(uint32_t *C, uint32_t *A);
-
-static void CASPER_montsub(uint32_t *C, uint32_t *A, uint32_t *B, uint32_t *mod);
-static void CASPER_montadd(uint32_t *C, uint32_t *A, uint32_t *B, uint32_t *mod);
-
-/* Compute c = a/2 mod p where b is scratch space. */
-static void CASPER_half(uint32_t *c, uint32_t *a, uint32_t *b);
-
-static uint8_t int8abs(int8_t v);
-
-/* Constant time select c = a if m = 0 or
- * c = b if m = 1
- * a, b, c are n words
- */
-static void casper_select(uint32_t *c, uint32_t *a, uint32_t *b, int m, int n);
-
-/* Dumb n-limb addition of c=a+b, return carry. */
-static uint32_t add_n_1(uint32_t *c, uint32_t *a, uint32_t b, int n);
-
-#if 0
-/* Dumb n-limb addition of c=a+b, return carry. */
-static uint32_t add_n(uint32_t *c, uint32_t *a, uint32_t *b, int n);
-
-/* Dumb n-limb subtraction of c=a-b, return borrow. */
-static uint32_t sub_n_1(uint32_t *c, uint32_t *a, uint32_t b, int n);
-#endif
-
-/* Dumb n-limb subtraction of c=a-b, return borrow. */
-static uint32_t sub_n(uint32_t *c, uint32_t *a, uint32_t *b, int n);
-
-static void MultprecCiosMul_ct(
- uint32_t w_out[], const uint32_t a[], const uint32_t b[], const uint32_t Nmod[], const uint32_t *Np);
-
-static void shiftright(uint32_t *z, uint32_t *x, int c);
-static void shiftleft(uint32_t *z, uint32_t *x, int c);
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-__STATIC_FORCEINLINE uint32_t CA_MK_OFF(const void *addr)
-{
- return ((uint32_t)addr - s_casperRamBase);
-}
-
-#if 1
-__STATIC_FORCEINLINE void Accel_done(void)
-{
- register uint32_t status;
- do
- {
- status = CASPER->STATUS;
- } while (0 == (status & CASPER_STATUS_DONE_MASK));
-}
-
-__STATIC_FORCEINLINE void Accel_SetABCD_Addr(uint32_t ab, uint32_t cd)
-{
- CASPER->CTRL0 = ab | (cd << 16); /* CDoffset << 16 | ABoffset */
-}
-
-__STATIC_FORCEINLINE void Accel_crypto_mul(uint32_t ctrl1)
-{
- CASPER->CTRL1 = ctrl1;
-}
-#else
-#include "intrinsics.h"
-#define Accel_done() \
- { \
- register uint32_t status; \
- do \
- { \
- status = CASPER_Rd32b(CASPER_CP_STATUS); \
- } while (0 == (status & CASPER_STATUS_DONE_MASK)); \
- }
-#if 0
-__STATIC_FORCEINLINE void Accel_done(void)
-{
- register uint32_t status;
- do
- {
- status = CASPER->STATUS;
- } while (0 == (status & CASPER_STATUS_DONE_MASK));
-}
-#endif
-#define Accel_SetABCD_Addr(ab, cd) CASPER_Wr32b((uint32_t)ab | ((uint32_t)cd << 16), CASPER_CP_CTRL0);
-#define Accel_crypto_mul(ctrl1) CASPER_Wr32b((uint32_t)ctrl1, CASPER_CP_CTRL1);
-#endif
-
-__STATIC_FORCEINLINE uint32_t Accel_IterOpcodeResaddr(uint32_t iter, uint32_t opcode, uint32_t resAddr)
-{
- return CASPER_CTRL1_ITER(iter) | CASPER_CTRL1_MODE(opcode) | (resAddr << 16);
-}
-
-void CASPER_MEMCPY(void *dst, const void *src, size_t siz)
-{
- bool bdst = ((((uint32_t)dst) | 0x10000000u) >= (FSL_FEATURE_CASPER_RAM_BASE_ADDRESS | 0x10000000u) &&
- (((uint32_t)dst) | 0x10000000u) < (FSL_FEATURE_CASPER_RAM_BASE_ADDRESS | 0x10000000u) + 8u * 1024u);
-
- bool bsrc = ((((uint32_t)src) | 0x10000000u) >= (FSL_FEATURE_CASPER_RAM_BASE_ADDRESS | 0x10000000u) &&
- (((uint32_t)src) | 0x10000000u) < (FSL_FEATURE_CASPER_RAM_BASE_ADDRESS | 0x10000000u) + 8u * 1024u);
-
- if (bdst && bsrc)
- {
- CASPER_MEMCPY_I2I(dst, src, siz);
- }
- else if (bdst && !bsrc)
- {
- CASPER_MEMCPY_N2I(dst, src, siz);
- }
- else if (!bdst && bsrc)
- {
- CASPER_MEMCPY_I2N(dst, src, siz);
- }
- else
- {
- memcpy(dst, src, siz);
- }
-}
-
-/* Constant time select c = a if m = 0 or
- * c = b if m = 1
- * a, b, c are n words
- */
-static void casper_select(uint32_t *c, uint32_t *a, uint32_t *b, int m, int n)
-{
- uint32_t m1 = 0 - m, m2 = ~m1;
- int i;
-
- for (i = 0; i < n; i++)
- {
- SET_WORD(&c[i], (GET_WORD(&a[i]) & m2) | (GET_WORD(&b[i]) & m1));
- }
-}
-
-/* Compute R`, which is R mod N. This is done using subtraction */
-/* R has 1 in N_wordlen, but we do not fill it in since borrowed. */
-/* Exp-pubkey only used to optimize for exp=3 */
-void MultprecMontCalcRp(unsigned Rp[], const unsigned exp_pubkey, const unsigned Nmod[])
-{
- uint32_t i;
-
- /* R is 2^n where n is 1 bit longer than Nmod, so 1 followed by 32 or 64 0 words for example */
- /* Note that Nmod's upper most bit has to be 1 by definition, so one subtract is enough. We */
- /* do not set the 1 since it is "borrowed" so no point */
- PreZeroW(i, Rp);
- Accel_SetABCD_Addr(CA_MK_OFF(Nmod), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpSub64, CA_MK_OFF(Rp)));
- Accel_done();
- /* final borrow cannot happen since we know we started with a larger number */
-}
-
-/* MultprecMultiply - multiple w=u*v (per Knuth) */
-/* w_out is 2x the size of u and v */
-void MultprecMultiply(unsigned w_out[], const unsigned u[], const unsigned v[])
-{
- uint32_t i, j;
-
- /* Knuth 4.3.1 - Algorithm M */
- /* Compute w = u * v */
- /* u and v are N bits long in 32 bit word form */
- /* w is 2*N bits long in 32 bit word form */
- /* Note: We just multiply in place */
-
- /* Step 1. Fill w[t-1:0] with 0s, the upper half will be written as we go */
- PreZeroW(i, w_out);
-
- /* We do 1st pass NOSUM so we do not have to 0 output */
- Accel_SetABCD_Addr(CA_MK_OFF(&v[0]), CA_MK_OFF(u));
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_wordlen / 2 - 1, kCASPER_OpMul6464NoSum, CA_MK_OFF(&w_out[0])));
- Accel_done();
- /* Step 2. iterate over N words of v using j */
- for (j = 2; j < N_wordlen; j += 2)
- {
- /* Step 2b. Check for 0 on v word - skip if so since we 0ed already */
- /* Step 3. Iterate over N words of u using i - perform Multiply-accumulate */
- if (GET_WORD(&v[j]) || GET_WORD(&v[j + 1]))
- {
- Accel_SetABCD_Addr(CA_MK_OFF(&v[j]), CA_MK_OFF(u));
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_wordlen / 2 - 1, kCASPER_OpMul6464Sum, CA_MK_OFF(&w_out[j])));
- Accel_done();
- }
- }
-}
-
-/* MultprecModulo performs divide to get remainer as needed for RSA */
-/* This performs (q,r) = u/v, but we do not keep q */
-/* r_out is module (remainder) and is 2*N */
-/* u is in r_out (1st N) at start (passed in) */
-/* v is N long */
-void MultprecModulo(unsigned r_out[], const unsigned v[], int top)
-{
- uint64_t u64; /* use 64 bit math mixed with 32 bit */
- unsigned u32; /* allows us to work on U in 32 bit */
- unsigned u_n, ul16, uh16, *u_shft; /* u_shft is because r_out is u initially */
- unsigned vl16, vh16, v_Nm1;
- unsigned q_hat, r_hat, q_over;
- unsigned borrow, carry;
- uint32_t i;
- int j, tmp;
-
- /* Knuth 4.3.1 - Algorithm D */
- /* Compute q = u / v giving remainder r = u mod v */
- /* -- we only want r, so we build qhat but do not store the Qs */
- /* v is N long, with u,q,r 2N long because u is slowly replavced by r. */
- /* We normalize/unnormlize per Knuth in the buffer (not copied) */
-
- /* Step 1. Normalize value so MSb is in v[n-1]. Remember that v is */
- /* the public key - to call it a 2048 bit number, they cannot have 0 */
- /* in the MSb (or it would be less than 2048 bits) and so we know we */
- /* are normalized already. Therefore, u is effectively shifted already. */
- /* For u, we have it in r_out. u[n] holds any overflow */
- /* Since divide on CM3/4 is 32/32=32, we break into 16 bit halves, but */
- /* multiply can be 32x32=64. */
- u_n = 0;
- u_shft = r_out; /* u (shifted) is in r_out */
-
- v_Nm1 = GET_WORD(&v[N_wordlen - 1]); /* MSw of public key */
- vl16 = v_Nm1 & 0xFFFF; /* lower 16 */
- vh16 = v_Nm1 >> 16; /* upper 16 */
- /* Step 2. Iterate j from m-n down to 0 (M selected per Knuth as 2*N) */
- for (j = top; j >= 0; j--)
- {
- /* Step 3. estimate q_hat as (U[j+n]*B + U[j+n-1]) / V[n-1] */
- /* Note: using subset of Knuth algo since v is 1/2 len of u (which is */
- /* from multiply or x^2 leading into this). */
- u32 = u_n; /* pickup u4u3u2, knowing u4 is 0 */
- u64 = ((uint64_t)u_n << 32) | GET_WORD(&u_shft[j + N_wordlen - 1]);
- ul16 = u64 & 0xFFFF; /* lower 16 */
- uh16 = (u64 >> 16) & 0xFFFF; /* upper 16 */
-
- /* we see if even possible (u large enough relative to v) */
- if ((u32 - v_Nm1) <= u32)
- {
- u32 -= v_Nm1;
- q_over = 1; /* overflow from the sub */
- }
- else
- q_over = 0;
-
- /* q_hat = u32 / vh16 -- is the upper partial value */
- /* estimate; if too much, then back down by 1 or 2 */
- q_hat = u32 / vh16;
- r_hat = u32 - (q_hat * vh16);
- /* see if Q is more than 16 bits or remainder is too large (over div) */
- if ((q_hat == 0x10000) || ((q_hat * vl16) > ((r_hat << 16) | uh16)))
- {
- /* too much - undo a division */
- q_hat--;
- r_hat += vh16;
- /* check if still too much */
- if ((r_hat < 0x10000) && ((q_hat * vl16) > ((r_hat << 16) | uh16)))
- q_hat--; /* yes, so undo a 2nd */
- }
-
- /* compose u3u2uh16, then sub q_hat*v if OK */
- u64 = (((uint64_t)u32 << 16) | uh16) - ((uint64_t)q_hat * v_Nm1);
- if (u64 >> 48)
- {
- /* no, so add v back */
- u32 = (unsigned)(u64 + v_Nm1);
- q_hat--;
- }
- else
- u32 = (unsigned)u64;
-
- tmp = q_hat << 16; /* quotient upper part */
-
- /* divide lower part: q = u2uh16ul16 / v. */
- /* estimate and add back if over divdied */
- q_hat = u32 / vh16;
- r_hat = u32 - (q_hat * vh16);
- if ((q_hat == 0x10000) || ((q_hat * vl16) > ((r_hat << 16) | ul16)))
- {
- /* too much - undo a division */
- q_hat--;
- r_hat += vh16;
- /* check if still too much */
- if ((r_hat < 0x10000) && ((q_hat * vl16) > ((r_hat << 16) | ul16)))
- q_hat--; /* yes, so undo a 2nd */
- }
-
- /* compose u2uh16ul16, then sub q_hat*v if OK */
- u64 = (((uint64_t)u32 << 16) | ul16) - ((uint64_t)q_hat * v_Nm1);
- if (u64 >> 48)
- {
- /* no, so add v back */
- r_hat = (unsigned)(u64 + v_Nm1);
- q_hat--;
- }
- else
- r_hat = (unsigned)u64;
-
- q_hat |= tmp; /* other half of the quotient */
- while (q_over || ((uint64_t)q_hat * GET_WORD(&v[N_wordlen - 2])) >
- ((1LL << 32) * r_hat) + (uint64_t)GET_WORD(&u_shft[j + N_wordlen - 2]))
- { /* if Qhat>b, then reduce to b-1, then adjust up Rhat */
- q_hat--;
- r_hat += v_Nm1;
- if (r_hat < v_Nm1)
- break; /* no overflow */
- /* else repeat since Rhat >= b */
- }
-
- /* Step 4. Multiply and subtract. We know the amount, */
- /* so we do the schoolboy math. Have to do on */
- /* the large value. */
- if (q_hat)
- {
- borrow = 0;
- for (i = 0; i < N_wordlen; i++)
- {
- u64 = (uint64_t)q_hat * GET_WORD(&v[i]) + borrow;
- borrow = (unsigned)(u64 >> 32);
- if (GET_WORD(&u_shft[i + j]) < (unsigned)u64)
- borrow++; /* carry the overflow */
- SET_WORD(&u_shft[i + j], GET_WORD(&u_shft[i + j]) - (unsigned)u64);
- }
- u_n -= borrow; /* overflow from shift left does not fit otherwise */
- }
-
- /* Store 5. (update Q - we don't), and add back V to remainder if we over-subtracted */
- /* That restores remainder to correct (we could only be off by 1) */
- /* This should happen very rarely. */
- if (u_n)
- {
- carry = 0;
- for (i = 0; i < N_wordlen; i++)
- {
- SET_WORD(&u_shft[i + j], GET_WORD(&u_shft[i + j]) + carry);
- carry = (GET_WORD(&u_shft[i + j]) < carry) ? 1 : 0;
- SET_WORD(&u_shft[i + j], GET_WORD(&u_shft[i + j]) + GET_WORD(&v[i]));
- if (GET_WORD(&u_shft[i + j]) < GET_WORD(&v[i]))
- carry++;
- }
- }
- u_n = GET_WORD(&u_shft[j + N_wordlen - 1]); /* hold upper part of u to catch overflow (to borrow from) */
- }
- /* low N bits of r are valid as remainder */
-}
-
-/* We convert X into a Mont form number. Note length of arrays: */
-/* x is N_wordlen, Nmod is N_wordlen */
-/* Rp is N_wordlen (it is R` which is R mod N) */
-/* Xmont_out is N_wordlen*2+1 */
-void MultprecMontPrepareX(unsigned Xmont_out[], const unsigned x[], const unsigned Rp[], const unsigned Nmod[])
-{
- MultprecMultiply(Xmont_out, x, Rp);
- MultprecModulo(Xmont_out, Nmod, N_wordlen);
-}
-
-void MultprecGenNp64(const unsigned *Nmod, unsigned *np64_ret) /* only pass the low order double word */
-{
- uint64_t nprime, Nmod_0;
- Nmod_0 = GET_WORD(&Nmod[0]) | ((uint64_t)GET_WORD(&Nmod[1]) << 32);
-
-#define COMP_NPN_1 ((2 - Nmod_0 * nprime) * nprime) /* computes N`*N0=1 mod 2^P where P is the partial built up */
- nprime = (((2 + Nmod_0) & 4) << 1) + Nmod_0; /* mod 2^4 */
- nprime = COMP_NPN_1;
- nprime = COMP_NPN_1;
- nprime = COMP_NPN_1;
- nprime = COMP_NPN_1;
- /* 8 multiplies of uint64_t */
- *((uint64_t *)np64_ret) = (~0LL - nprime) + 1LL;
-}
-
-/* CIOS Multiply. This is the Coarse Integrated form where the values are */
-/* multiplied and reduced for each step of "i". This uses less memory and */
-/* is faster as a result. Note that this is used to square as well as mul, */
-/* so not as fast as pure squaring could be. */
-void MultprecCiosMul(
- unsigned w_out[], const unsigned a[], const unsigned b[], const unsigned Nmod[], const unsigned *Np)
-{
- int j;
- uint32_t i;
- uint64_t *m64 = (uint64_t *)&msg_ret[kCASPER_RamOffset_M64];
- uint64_t Np64;
- uint64_t carry;
- uint64_t *a64, *b64, *w64, *N64;
-
- Np64 = *(uint64_t *)Np;
-
- a64 = (uint64_t *)a;
- b64 = (uint64_t *)b;
- w64 = (uint64_t *)w_out;
- N64 = (uint64_t *)Nmod;
-
- if (a)
- { /* if !a, we are reducing only */
- PreZeroW(i, w_out);
- }
- SET_DWORD(&w64[N_dwordlen], 0);
- SET_DWORD(&w64[N_dwordlen + 1], 0);
- /* with accelerator */
-
- /* loop i and then reduce after each j round */
- for (i = 0; i < N_dwordlen; i++)
- {
- /* Step 3. Iterate over N words of u using i - perform Multiply-accumulate */
- /* push-pull: we do a*b and then separately m*n (reduce) */
- if (a)
- { /* if mul&reduce vs. reduce only */
- carry = GET_DWORD(&w64[N_dwordlen]);
- Accel_SetABCD_Addr(CA_MK_OFF(&b64[i]), CA_MK_OFF(a64));
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpMul6464FullSum, CA_MK_OFF(w64)));
- Accel_done();
- /* max carry is contained since ~0*~0=0xFFFE0001+0xFFFF=0xFFFF0000, */
- /* so max carry is 0xFFFF and 0xFFFF0000+0xFFFF=0xFFFFFFFF */
- /* accel took care of w_out[N_wordlen] & +1, so we just take care of the next double word if carry=1 */
- /* w64[N_dwordlen+1] = g_carry; */
- carry = (GET_DWORD(&w64[N_dwordlen]) < carry);
- SET_DWORD(&w64[N_dwordlen + 1], carry);
- }
- SET_DWORD(&m64[0], GET_DWORD(&w64[0]) * Np64); /* prime for 1st; modulo a double-word */
-
- /* we are reducing, so the 1st [0th] 64 bit value product is tossed, but we */
- /* need its carry. We let the accel do this separately - really need a mode to */
- /* do this "reduce" since it is natural */
- carry = GET_DWORD(&w64[N_dwordlen]);
- Accel_SetABCD_Addr(CA_MK_OFF(m64), CA_MK_OFF(&N64[0]));
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpMul6464FullSum, CA_MK_OFF(&w64[0])));
- Accel_done();
- carry = (GET_DWORD(&w64[N_dwordlen]) < carry);
-
- Accel_SetABCD_Addr(CA_MK_OFF(&w64[1]), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpCopy, CA_MK_OFF(&w64[0])));
-
- Accel_done();
- SET_DWORD(&w64[N_dwordlen], (GET_DWORD(&w64[N_dwordlen + 1]) + carry));
- }
-
- /* now check if need to subtract Nmod */
- if (GET_WORD(&w_out[N_wordlen]))
- j = 1; /* we have to subtract for sure if carry up */
- else
- {
- j = 0;
- for (i = N_wordlen - 1; i > 0; i--)
- if (GET_WORD(&w_out[i]) != GET_WORD(&Nmod[i]))
- {
- j = GET_WORD(&w_out[i]) > GET_WORD(&Nmod[i]); /* if larger sub */
- break; /* we would remove the break if worrying about side channel */
- }
- }
- if (!j)
- return; /* Is smaller than Nmod, so done. */
- Accel_SetABCD_Addr(CA_MK_OFF(Nmod), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpSub64, CA_MK_OFF(w_out)));
- Accel_done();
- /* last borrow is OK since we know it could only be <2N and */
-}
-
-/* RSA_MontSignatureToPlaintextFast: */
-/* MsgRet[] = Message return buffer - must be large enough to hold input and output (4*N+2) */
-/* exp_pubkey = the "e" that the value is raised to. Usually 3 or 0x10001. */
-/* signature = N bitpos len long "message" to process in Montgomery form - so saving conversion (divide) */
-/* pubkey = N bitpos len long public key to process signature with */
-/* returns: 0 */
-/* */
-/* Algo: compute M = signaturen^e mod public_key */
-/* where M is original plaintext, signature is signed value */
-/* note: e is usually either 0x3 or 0x10001 */
-int RSA_MontSignatureToPlaintextFast(const unsigned mont_signature[N_wordlen_max],
- const unsigned exp_pubkey,
- const unsigned pubkey[N_wordlen_max],
- unsigned MsgRet[WORK_BUFF_MUL4])
-{
- int bidx = 0;
- int bitpos;
- unsigned np64[2];
-
- /* MsgRet working area: */
- /* 0..N = RESULT, starting with S` */
- /* N..N*2 = S` and then working BASE during math. */
- /* N*2..N*4+2 = temp working area for Mont mul */
-
- /* 1. Copy sig into MsgRet so we have one working result buffer */
- CASPER_MEMCPY_I2I(&MsgRet[kCASPER_RamOffset_Result], mont_signature, N_bytelen);
- MultprecGenNp64(pubkey, np64); /* Generate N` from LSW of N (LSW being lowest 64b word) */
- bitpos = 31 - __CLZ(exp_pubkey); /* count of bits after the left most 1 */
- while (--bitpos >= 0)
- {
- /* This operates on: */
- /* result = 1; */
- /* base = signature */
- /* loop while exponent bits from MSb to LSb */
- /* if (exp bit is 1) */
- /* result = result * base */
- /* base = base^2 */
- /* Because the MSb of exp is always 1 by definition, we can invert this a bit: */
- /* base = signature` */
- /* result = base; equivalent to result = 1*base from 1st pass, but now square is needed 1st */
- /* loop while exponent bits from MSb-1 to LSb */
- /* base = base^2 */
- /* if (exp bit is 1) */
- /* result = result * base */
- /* This ends up doing the same thing but skips two wasteful steps of multiplying by 1 and */
- /* a final squaring never used. */
- /* */
- /* Next we have the problem that CIOS mul needs a separate dest buffer. So, we bounce */
- /* base between base and temp, and likewise for result. */
- MultprecCiosMul(&MsgRet[bidx ? kCASPER_RamOffset_Base : kCASPER_RamOffset_TempBase],
- &MsgRet[bidx ? kCASPER_RamOffset_TempBase : kCASPER_RamOffset_Base],
- &MsgRet[bidx ? kCASPER_RamOffset_TempBase : kCASPER_RamOffset_Base], pubkey, np64);
- if (exp_pubkey & (1 << bitpos)) /* where e is 1 */
- {
- /* result has result, so we need to work into other temp area */
- MultprecCiosMul(&MsgRet[bidx ? kCASPER_RamOffset_TempBase : kCASPER_RamOffset_Base],
- &MsgRet[kCASPER_RamOffset_Result],
- &MsgRet[bidx ? kCASPER_RamOffset_Base : kCASPER_RamOffset_TempBase], pubkey, np64);
- /* we have to copy back to result */
-
- // CASPER_MEMCPY_I2I(&MsgRet[kCASPER_RamOffset_Result],
- // &MsgRet[bidx ? kCASPER_RamOffset_TempBase : kCASPER_RamOffset_Base], N_bytelen);
- }
- else
- bidx = ~bidx;
- }
-
- CASPER_MEMCPY_I2I(&MsgRet[kCASPER_RamOffset_Result],
- &MsgRet[bidx ? kCASPER_RamOffset_TempBase : kCASPER_RamOffset_Base], N_bytelen);
-
- /* final step is one more reduction to get back to normal form (ie. divide R out) */
- MultprecCiosMul(&MsgRet[kCASPER_RamOffset_Result], NULL, NULL, pubkey, np64);
- return (0); /* always 0 */
-}
-
-/* RSA_SignatureToPlaintextFast: */
-/* MsgRet[] = Message return buffer - must be large enough to hold input and output (4*N+2) */
-/* exp_pubkey = the "e" that the value is raised to. Usually 3 or 0x10001. */
-/* signature = N bitpos len long "message" to process in normal form - so converted to Mont form */
-/* pubkey = N bitpos len long public key to process signature with */
-/* returns: 0 */
-/* */
-/* Algo: compute M = signaturen^e mod public_key */
-/* where M is original plaintext, signature is signed value */
-/* note: e is usually either 0x3 or 0x10001 */
-int RSA_SignatureToPlaintextFast(const unsigned signature[N_wordlen_max],
- const unsigned exp_pubkey,
- const unsigned pubkey[N_wordlen_max],
- unsigned MsgRet[WORK_BUFF_MUL4])
-{
- /* MsgRet working area: */
- /* 0..N = RESULT, starting with S`; it is used for R` just during creation of S` */
- /* N..N*2 = S` and then working BASE during math. Note overflow beyond N*2 when making S` */
- /* N*2..N*4+2 = temp working area for Mont mul */
-
- MultprecMontCalcRp(&MsgRet[kCASPER_RamOffset_Result], exp_pubkey, pubkey); /* calculate R` (=R mod N) */
- MultprecMontPrepareX(&MsgRet[kCASPER_RamOffset_Base], signature, &MsgRet[kCASPER_RamOffset_Result],
- pubkey); /* X*R1` mod N */
- return (RSA_MontSignatureToPlaintextFast(&MsgRet[kCASPER_RamOffset_Base], exp_pubkey, pubkey, MsgRet));
-}
-
-/*!
- * brief Performs modular exponentiation - (A^E) mod N.
- *
- * This function performs modular exponentiation.
- *
- * param base CASPER base address
- * param signature first addend (in little endian format)
- * param pubN modulus (in little endian format)
- * param wordLen Size of pubN in bytes
- * param pubE exponent
- * param[out] plaintext Output array to store result of operation (in little endian format)
- */
-void CASPER_ModExp(
- CASPER_Type *base, const uint8_t *signature, const uint8_t *pubN, size_t wordLen, uint32_t pubE, uint8_t *plaintext)
-{
-#define PK_LOC &msg_ret[kCASPER_RamOffset_Modulus]
-#define SIG_LOC &msg_ret[kCASPER_RamOffset_Modulus + N_wordlen_max]
-
- N_wordlen = wordLen; /* set global variable for key length - used by RSA_SignatureToPlaintextFast() */
- CASPER_MEMCPY_N2I(PK_LOC, pubN, N_bytelen);
- CASPER_MEMCPY_N2I(SIG_LOC, signature, N_bytelen);
- RSA_SignatureToPlaintextFast((const unsigned *)(SIG_LOC), pubE, (const unsigned *)(PK_LOC), msg_ret);
-
- CASPER_MEMCPY_I2N(plaintext, msg_ret, N_bytelen);
-}
-
-/*!
- * brief Enables clock and disables reset for CASPER peripheral.
- *
- * Enable clock and disable reset for CASPER.
- *
- * param base CASPER base address
- */
-void CASPER_Init(CASPER_Type *base)
-{
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- CLOCK_EnableClock(kCLOCK_Casper);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
- RESET_PeripheralReset(kCASPER_RST_SHIFT_RSTn);
- /* If Casper init is called with secure address, use secure addres also for accessing Casper RAM. */
- s_casperRamBase = CASPER_RAM_BASE_NS | ((uint32_t)base & 0x10000000u);
- msg_ret = (unsigned *)s_casperRamBase;
-}
-
-/*!
- * brief Disables clock for CASPER peripheral.
- *
- * Disable clock and enable reset.
- *
- * param base CASPER base address
- */
-void CASPER_Deinit(CASPER_Type *base)
-{
- RESET_SetPeripheralReset(kCASPER_RST_SHIFT_RSTn);
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- CLOCK_DisableClock(kCLOCK_Casper);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-}
-
-/* New ECC code which uses Casper. */
-
-/* Set the prime modulus mod in Casper memory.
- */
-void CASPER_ecc_init(void)
-{
-#if CASPER_ECC_P256
- N_wordlen = 256 / 32;
- uint32_t *mod = NISTp256;
-#elif CASPER_ECC_P384
- N_wordlen = 384 / 32;
- uint32_t *mod = NISTp384;
-#endif
- CASPER_MEMCPY(&CASPER_MEM[MOD_SCRATCH_START], mod, NUM_LIMBS * sizeof(uint32_t));
- uint8_t a[(CASPER_NUM_LIMBS - NUM_LIMBS) * sizeof(uint32_t)] = {0};
- CASPER_MEMCPY(&CASPER_MEM[MOD_SCRATCH_START + NUM_LIMBS], a, (CASPER_NUM_LIMBS - NUM_LIMBS) * sizeof(uint32_t));
-}
-
-void CASPER_ECC_equal(int *res, uint32_t *op1, uint32_t *op2)
-{
- uint32_t a[NUM_LIMBS];
- uint32_t b[NUM_LIMBS];
- int c = 0;
- CASPER_MEMCPY(a, op1, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(b, op2, NUM_LIMBS * sizeof(uint32_t));
-
- do
- {
- int _i;
- c = a[0] ^ b[0];
- for (_i = 1; _i < NUM_LIMBS; _i++)
- {
- c |= (a[_i] ^ b[_i]);
- }
- } while (0);
-
- *res = c;
-}
-
-void CASPER_ECC_equal_to_zero(int *res, uint32_t *op1)
-{
- uint32_t a[NUM_LIMBS];
- int c = 0;
- CASPER_MEMCPY(a, op1, NUM_LIMBS * sizeof(uint32_t));
-
- do
- {
- int _i;
- c = a[0];
- for (_i = 1; _i < NUM_LIMBS; _i++)
- {
- c |= a[_i];
- }
- } while (0);
-
- *res = c;
-}
-
-#if CASPER_ECC_P256
-void CASPER_ECC_SECP256R1_Mul(
- CASPER_Type *base, uint32_t resX[8], uint32_t resY[8], uint32_t X[8], uint32_t Y[8], uint32_t scalar[8])
-{
- uint32_t X1[8] = {0};
- uint32_t Y1[8] = {0};
- toMontgomery(X1, X);
- toMontgomery(Y1, Y);
-
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], X1, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], Y1, NUM_LIMBS * sizeof(uint32_t));
-
- Jac_scalar_multiplication(&CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 7 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 8 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], scalar, NISTp256, NISTp256_q);
-
- Jac_toAffine(&CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 7 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 8 * CASPER_NUM_LIMBS]);
-
- /* Montgomery to Normal */
- /* X_normal = 1 * X_montgomery; Y_normal = 1 * Y_montgomery */
- uint32_t one[CASPER_NUM_LIMBS] = {0x0};
- one[0] = 0x1u;
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], one, CASPER_NUM_LIMBS * sizeof(uint32_t));
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
-
- /* copy out to result */
- CASPER_MEMCPY(resX, &CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS], NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(resY, &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS], NUM_LIMBS * sizeof(uint32_t));
-}
-
-void CASPER_ECC_SECP256R1_MulAdd(CASPER_Type *base,
- uint32_t resX[8],
- uint32_t resY[8],
- uint32_t X1[8],
- uint32_t Y1[8],
- uint32_t scalar1[8],
- uint32_t X2[8],
- uint32_t Y2[8],
- uint32_t scalar2[8])
-{
- uint32_t zeroes[CASPER_NUM_LIMBS] = {0};
-
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], X1, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], Y1, NUM_LIMBS * sizeof(uint32_t));
-
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS], X2, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS], Y2, NUM_LIMBS * sizeof(uint32_t));
-
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS]);
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS]);
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS]);
-
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS], zeroes, CASPER_NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS], zeroes, CASPER_NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS], zeroes, CASPER_NUM_LIMBS * sizeof(uint32_t));
- double_scalar_multiplication(&CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], scalar1,
- &CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS], scalar2);
-
- Jac_toAffine(&CASPER_MEM[LUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[LUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS]);
-
- uint32_t one[CASPER_NUM_LIMBS] = {0x0};
- one[0] = 0x1u;
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], one, CASPER_NUM_LIMBS * sizeof(uint32_t));
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[LUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS],
- &CASPER_MEM[LUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
-
- CASPER_MEMCPY(resX, (&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS]), NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(resY, (&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS]), NUM_LIMBS * sizeof(uint32_t));
-}
-#endif /* CASPER_ECC_P256 */
-
-#if CASPER_ECC_P384
-void CASPER_ECC_SECP384R1_Mul(
- CASPER_Type *base, uint32_t resX[12], uint32_t resY[12], uint32_t X[12], uint32_t Y[12], uint32_t scalar[12])
-{
- uint32_t X1[12] = {0};
- uint32_t Y1[12] = {0};
- toMontgomery(X1, X);
- toMontgomery(Y1, Y);
-
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], X1, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], Y1, NUM_LIMBS * sizeof(uint32_t));
-
- Jac_scalar_multiplication(&CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 7 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 8 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], scalar, NISTp384, NISTp384_q);
-
- Jac_toAffine(&CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 7 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 8 * CASPER_NUM_LIMBS]);
-
- /* Montgomery to Normal */
- /* X_normal = 1 * X_montgomery; Y_normal = 1 * Y_montgomery */
- uint32_t one[12] = {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], one, NUM_LIMBS * sizeof(uint32_t));
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
-
- /* copy out to result */
- CASPER_MEMCPY(resX, &CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS], NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(resY, &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS], NUM_LIMBS * sizeof(uint32_t));
-}
-
-void CASPER_ECC_SECP384R1_MulAdd(CASPER_Type *base,
- uint32_t resX[12],
- uint32_t resY[12],
- uint32_t X1[12],
- uint32_t Y1[12],
- uint32_t scalar1[12],
- uint32_t X2[12],
- uint32_t Y2[12],
- uint32_t scalar2[12])
-{
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], X1, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], Y1, NUM_LIMBS * sizeof(uint32_t));
-
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS], X2, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS], Y2, NUM_LIMBS * sizeof(uint32_t));
-
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS]);
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS]);
- toMontgomery(&CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS]);
-
- double_scalar_multiplication(&CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS], scalar1,
- &CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS], scalar2);
-
- Jac_toAffine(&CASPER_MEM[LUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[LUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS]);
-
- uint32_t one[12] = {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
- CASPER_MEMCPY(&CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS], one, NUM_LIMBS * sizeof(uint32_t));
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[LUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
- multiply_casper(&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS],
- &CASPER_MEM[LUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS],
- &CASPER_MEM[INOUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS]);
-
- CASPER_MEMCPY(resX, (&CASPER_MEM[INOUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS]), NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(resY, (&CASPER_MEM[INOUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS]), NUM_LIMBS * sizeof(uint32_t));
-}
-#endif /* CASPER_ECC_P384 */
-
-// CIOS Multiply. This is the Coarse Integrated form where the values are
-// multiplied and reduced for each step of "i". This uses less memory and
-// is faster as a result. Note that this is used to square as well as mul,
-// so not as fast as pure squaring could be.
-static void MultprecCiosMul_ct(
- uint32_t w_out[], const uint32_t a[], const uint32_t b[], const uint32_t Nmod[], const uint32_t *Np)
-{
- uint32_t i;
- uint64_t *m64 = (uint64_t *)&msg_ret[kCASPER_RamOffset_M64];
- uint64_t Np64;
- uint64_t carry;
- uint64_t *a64, *b64, *w64, *N64;
- uint32_t *T1 = &CASPER_MEM[0], borrow;
-
- Np64 = *(uint64_t *)Np;
-
- a64 = (uint64_t *)a;
- b64 = (uint64_t *)b;
- w64 = (uint64_t *)w_out;
- N64 = (uint64_t *)Nmod;
-
- if (a)
- { /* if !a, we are reducing only */
- PreZeroW(i, w_out);
- }
- SET_DWORD(&w64[N_dwordlen], 0);
- SET_DWORD(&w64[N_dwordlen + 1], 0);
- /* with accelerator */
-
- /* loop i and then reduce after each j round */
- for (i = 0; i < N_dwordlen; i++)
- {
- /* Step 3. Iterate over N words of u using i - perform Multiply-accumulate */
- /* push-pull: we do a*b and then separately m*n (reduce) */
- if (a)
- { /* if mul&reduce vs. reduce only */
- carry = GET_DWORD(&w64[N_dwordlen]);
- Accel_SetABCD_Addr(CA_MK_OFF(&b64[i]), CA_MK_OFF(a64));
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpMul6464FullSum, CA_MK_OFF(w64)));
- Accel_done();
- /* max carry is contained since ~0*~0=0xFFFE0001+0xFFFF=0xFFFF0000, */
- /* so max carry is 0xFFFF and 0xFFFF0000+0xFFFF=0xFFFFFFFF */
- /* accel took care of w_out[N_wordlen] & +1, so we just take care of the next double word if carry=1 */
- /* w64[N_dwordlen+1] = g_carry; */
- carry = (GET_DWORD(&w64[N_dwordlen]) < carry);
- SET_DWORD(&w64[N_dwordlen + 1], carry);
- }
- SET_DWORD(&m64[0], GET_DWORD(&w64[0]) * Np64); /* prime for 1st; modulo a double-word */
-
- /* we are reducing, so the 1st [0th] 64 bit value product is tossed, but we */
- /* need its carry. We let the accel do this separately - really need a mode to */
- /* do this "reduce" since it is natural */
- carry = GET_DWORD(&w64[N_dwordlen]);
- Accel_SetABCD_Addr(CA_MK_OFF(m64), CA_MK_OFF(&N64[0]));
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpMul6464FullSum, CA_MK_OFF(&w64[0])));
- Accel_done();
- carry = (GET_DWORD(&w64[N_dwordlen]) < carry);
-
- Accel_SetABCD_Addr(CA_MK_OFF(&w64[1]), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen - 1, kCASPER_OpCopy, CA_MK_OFF(&w64[0])));
-
- Accel_done();
- SET_DWORD(&w64[N_dwordlen], (GET_DWORD(&w64[N_dwordlen + 1]) + carry));
- }
-
- /* now check if need to subtract Nmod */
- CASPER_MEMCPY_I2I(T1, w_out, (NUM_LIMBS + 1) * sizeof(uint32_t));
-
- /* Compute w = w - N */
- Accel_SetABCD_Addr(CA_MK_OFF(Nmod), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(N_dwordlen, kCASPER_OpSub64, CA_MK_OFF(w_out)));
- Accel_done();
-
- // if w_out > T1 then there was a borrow
- borrow = (GET_WORD(&((uint32_t *)w_out)[NUM_LIMBS]) > GET_WORD(&T1[NUM_LIMBS]));
-
- SET_WORD(&w_out[NUM_LIMBS + 1], 0);
- SET_WORD(&w_out[NUM_LIMBS], 0);
- casper_select(w_out, w_out, T1, borrow, NUM_LIMBS);
-}
-
-/* Compute C = A - B % mod
- * Assumes all operand have two extra limbs to store carry.
- */
-void CASPER_montsub(uint32_t *C, uint32_t *A, uint32_t *B, uint32_t *mod)
-{
- uint64_t *b64, *c64, *m64, *tmp;
- int borrow;
-
- b64 = (uint64_t *)B;
- c64 = (uint64_t *)C;
- m64 = (uint64_t *)mod;
-
- tmp = (uint64_t *)&CASPER_MEM[0];
-
- CASPER_MEMCPY(tmp, A, NUM_LIMBS * sizeof(uint32_t));
- // uint32_t temp32 = GET_WORD(&tmp[NUM_LIMBS - 1]);
-
- /* Compute tmp = A - B. */
- Accel_SetABCD_Addr(CA_MK_OFF(b64), 0);
-
- Accel_crypto_mul(Accel_IterOpcodeResaddr(NUM_LIMBS / 2 - 1, kCASPER_OpSub64, CA_MK_OFF(tmp)));
- Accel_done();
-
- // borrow = (GET_WORD(&((uint32_t*)tmp)[NUM_LIMBS - 1]) > temp32);
- borrow = ((GET_WORD(&((uint32_t *)tmp)[NUM_LIMBS - 1])) > GET_WORD(&A[NUM_LIMBS - 1]));
- CASPER_MEMCPY(c64, tmp, NUM_LIMBS * sizeof(uint32_t));
-
- /* Compute C = Mod + tmp */
- Accel_SetABCD_Addr(CA_MK_OFF(m64), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(NUM_LIMBS / 2 - 1, kCASPER_OpAdd64, CA_MK_OFF(c64)));
- Accel_done();
-
- casper_select(C, (uint32_t *)tmp, C, borrow, NUM_LIMBS);
-}
-
-/* Compute C = A + B % mod
- * Assumes all operand have two extra limbs to store carry.
- */
-void CASPER_montadd(uint32_t *C, uint32_t *A, uint32_t *B, uint32_t *mod)
-{
- uint64_t *b64, *c64, *m64, *tmp;
- int borrow;
-
- b64 = (uint64_t *)B;
- c64 = (uint64_t *)C;
- m64 = (uint64_t *)mod;
-
- tmp = (uint64_t *)&CASPER_MEM[0];
-
- CASPER_MEMCPY(tmp, A, NUM_LIMBS * sizeof(uint32_t));
- SET_DWORD(&tmp[NUM_LIMBS / 2], 0);
- SET_DWORD(&b64[NUM_LIMBS / 2], 0);
- SET_DWORD(&m64[NUM_LIMBS / 2], 0);
-
- /* Compute tmp = A + B using one additonal double-length limb. */
- Accel_SetABCD_Addr(CA_MK_OFF(b64), 0);
-
- Accel_crypto_mul(Accel_IterOpcodeResaddr(NUM_LIMBS / 2, kCASPER_OpAdd64, CA_MK_OFF(tmp)));
- Accel_done();
-
- CASPER_MEMCPY(c64, tmp, (NUM_LIMBS + 2) * sizeof(uint32_t));
-
- /* Compute C = Mod - tmp */
- Accel_SetABCD_Addr(CA_MK_OFF(m64), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(NUM_LIMBS / 2, kCASPER_OpSub64, CA_MK_OFF(c64)));
- Accel_done();
-
- // borrow = g_carry;
- borrow = (GET_WORD(&C[NUM_LIMBS]) > GET_WORD(&(((uint32_t *)tmp)[NUM_LIMBS])));
- casper_select(C, C, (uint32_t *)tmp, borrow, NUM_LIMBS);
-}
-
-/* Compute c = a/2 mod p where b is scratch space. */
-void CASPER_half(uint32_t *c, uint32_t *a, uint32_t *b)
-{
- shiftright(b, a, 1); /* Compute a/2 and (a+p)/2 */
-
- /* Compute tmp = a + p using one additonal double-length limb. */
- CASPER_MEMCPY(c, a, NUM_LIMBS * sizeof(uint32_t));
- SET_WORD(&c[NUM_LIMBS], 0);
- SET_WORD(&c[NUM_LIMBS + 1], 0);
-
- Accel_SetABCD_Addr(CA_MK_OFF(((uint64_t *)&CASPER_MEM[MOD_SCRATCH_START])), 0);
- Accel_crypto_mul(Accel_IterOpcodeResaddr(NUM_LIMBS / 2, kCASPER_OpAdd64, CA_MK_OFF(((uint64_t *)c))));
- Accel_done();
-
- shiftright(c, c, 1);
- SET_WORD(&c[NUM_LIMBS - 1], GET_WORD(&c[NUM_LIMBS - 1]) | (GET_WORD(&c[NUM_LIMBS]) << 31));
- SET_WORD(&c[NUM_LIMBS], 0);
- casper_select(c, b, c, (GET_WORD(&a[0]) & 1), NUM_LIMBS);
-}
-
-static uint32_t casper_get_word(uint32_t *addr)
-{
- return GET_WORD(addr);
-}
-
-#if CASPER_ECC_P256
-/* Shift right by 1 <= c <= 31. */
-static void shiftright(uint32_t *z, uint32_t *x, int c)
-{
- do
- {
- SET_WORD((&z[0]), (GET_WORD(&x[1]) << (32 - (c))) | (GET_WORD(&x[0]) >> (c)));
- SET_WORD((&z[1]), (GET_WORD(&x[2]) << (32 - (c))) | (GET_WORD(&x[1]) >> (c)));
- SET_WORD((&z[2]), (GET_WORD(&x[3]) << (32 - (c))) | (GET_WORD(&x[2]) >> (c)));
- SET_WORD((&z[3]), (GET_WORD(&x[4]) << (32 - (c))) | (GET_WORD(&x[3]) >> (c)));
- SET_WORD((&z[4]), (GET_WORD(&x[5]) << (32 - (c))) | (GET_WORD(&x[4]) >> (c)));
- SET_WORD((&z[5]), (GET_WORD(&x[6]) << (32 - (c))) | (GET_WORD(&x[5]) >> (c)));
- SET_WORD((&z[6]), (GET_WORD(&x[7]) << (32 - (c))) | (GET_WORD(&x[6]) >> (c)));
- SET_WORD((&z[7]), (GET_WORD(&x[7]) >> (c)));
-
- } while (0);
-}
-
-/* Shift left by 1 <= c <= 31. */
-static void shiftleft(uint32_t *z, uint32_t *x, int c)
-{
- do
- {
- SET_WORD(&z[7], (GET_WORD(&x[7]) << (c)) | GET_WORD(&z[6]) >> (32 - (c)));
- SET_WORD(&z[6], (GET_WORD(&x[6]) << (c)) | GET_WORD(&z[5]) >> (32 - (c)));
- SET_WORD(&z[5], (GET_WORD(&x[5]) << (c)) | GET_WORD(&z[4]) >> (32 - (c)));
- SET_WORD(&z[4], (GET_WORD(&x[4]) << (c)) | GET_WORD(&z[3]) >> (32 - (c)));
- SET_WORD(&z[3], (GET_WORD(&x[3]) << (c)) | GET_WORD(&z[2]) >> (32 - (c)));
- SET_WORD(&z[2], (GET_WORD(&x[2]) << (c)) | GET_WORD(&z[1]) >> (32 - (c)));
- SET_WORD(&z[1], (GET_WORD(&x[1]) << (c)) | GET_WORD(&z[0]) >> (32 - (c)));
- SET_WORD(&z[0], (GET_WORD(&x[0]) << (c)));
- } while (0);
-}
-#else
-/* Shift right by 1 <= c <= 31. */
-static void shiftright(uint32_t *z, uint32_t *x, int c)
-{
- do
- {
- SET_WORD(&z[0], (GET_WORD(&x[1]) << (32 - (c))) | (GET_WORD(&x[0]) >> (c)));
- SET_WORD(&z[1], (GET_WORD(&x[2]) << (32 - (c))) | (GET_WORD(&x[1]) >> (c)));
- SET_WORD(&z[2], (GET_WORD(&x[3]) << (32 - (c))) | (GET_WORD(&x[2]) >> (c)));
- SET_WORD(&z[3], (GET_WORD(&x[4]) << (32 - (c))) | (GET_WORD(&x[3]) >> (c)));
- SET_WORD(&z[4], (GET_WORD(&x[5]) << (32 - (c))) | (GET_WORD(&x[4]) >> (c)));
- SET_WORD(&z[5], (GET_WORD(&x[6]) << (32 - (c))) | (GET_WORD(&x[5]) >> (c)));
- SET_WORD(&z[6], (GET_WORD(&x[7]) << (32 - (c))) | (GET_WORD(&x[6]) >> (c)));
- SET_WORD(&z[7], (GET_WORD(&x[8]) << (32 - (c))) | (GET_WORD(&x[7]) >> (c)));
- SET_WORD(&z[8], (GET_WORD(&x[9]) << (32 - (c))) | (GET_WORD(&x[8]) >> (c)));
- SET_WORD(&z[9], (GET_WORD(&x[10]) << (32 - (c))) | (GET_WORD(&x[9]) >> (c)));
- SET_WORD(&z[10], (GET_WORD(&x[11]) << (32 - (c))) | (GET_WORD(&x[10]) >> (c)));
- SET_WORD(&z[11], (GET_WORD(&x[11]) >> (c)));
- } while (0);
-}
-
-/* Shift left by 1 <= c <= 31. */
-static void shiftleft(uint32_t *z, uint32_t *x, int c)
-{
- do
- {
- SET_WORD(&z[11], (GET_WORD(&x[11]) << (c)) | GET_WORD(&z[10]) >> (32 - (c)));
- SET_WORD(&z[10], (GET_WORD(&x[10]) << (c)) | GET_WORD(&z[9]) >> (32 - (c)));
- SET_WORD(&z[9], (GET_WORD(&x[9]) << (c)) | GET_WORD(&z[8]) >> (32 - (c)));
- SET_WORD(&z[8], (GET_WORD(&x[8]) << (c)) | GET_WORD(&z[7]) >> (32 - (c)));
- SET_WORD(&z[7], (GET_WORD(&x[7]) << (c)) | GET_WORD(&z[6]) >> (32 - (c)));
- SET_WORD(&z[6], (GET_WORD(&x[6]) << (c)) | GET_WORD(&z[5]) >> (32 - (c)));
- SET_WORD(&z[5], (GET_WORD(&x[5]) << (c)) | GET_WORD(&z[4]) >> (32 - (c)));
- SET_WORD(&z[4], (GET_WORD(&x[4]) << (c)) | GET_WORD(&z[3]) >> (32 - (c)));
- SET_WORD(&z[3], (GET_WORD(&x[3]) << (c)) | GET_WORD(&z[2]) >> (32 - (c)));
- SET_WORD(&z[2], (GET_WORD(&x[2]) << (c)) | GET_WORD(&z[1]) >> (32 - (c)));
- SET_WORD(&z[1], (GET_WORD(&x[1]) << (c)) | GET_WORD(&z[0]) >> (32 - (c)));
- SET_WORD(&z[0], (GET_WORD(&x[0]) << (c)));
- } while (0);
-}
-#endif
-
-/* Convert a projective point (X1 : Y1 : Z1)
- * to the affine point (X3, Y3) = (X1/Z1^2,Y1/Z1^3)
- * The memory of (X3, Y3) and (X1 : Y1 : Z1) should not overlap
- */
-void Jac_toAffine(uint32_t *X3, uint32_t *Y3, uint32_t *X1, uint32_t *Y1, uint32_t *Z1)
-{
- uint32_t *T1, *T2;
-
- T1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- T2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
-
- square_casper(T1, Z1); // Z^2
- multiply_casper(T2, T1, Z1); // Z^3
-
- // Montgomery inverse
- invert(T1, T2); // Z^-3
-
- multiply_casper(Y3, Y1, T1); // Y3 = Y/Z^3
- multiply_casper(T2, T1, Z1); // Z^-2
- multiply_casper(X3, X1, T2); // X3 = X/Z^2
-}
-
-/* Return 1 if (X1: Y1: Z1) is on the curve
- * Y^2 = X^3 -3XZ^4 + bZ^6
- * and return 0 otherwise.
- */
-int Jac_oncurve(uint32_t *X1, uint32_t *Y1, uint32_t *Z1, uint32_t *b)
-{
- uint32_t *T1, *T2, *T3, *T4, *T5, *T6;
- int m;
-
- T1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- T2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- T3 = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
- T4 = &CASPER_MEM[ECC_SCRATCH_START + 3 * CASPER_NUM_LIMBS];
- T5 = &CASPER_MEM[ECC_SCRATCH_START + 4 * CASPER_NUM_LIMBS];
- T6 = &CASPER_MEM[ECC_SCRATCH_START + 5 * CASPER_NUM_LIMBS];
-
- square_casper(T1, Y1); // Y^2
- square_casper(T6, X1); // X^2
- multiply_casper(T2, T6, X1); // X^3
-
- square_casper(T3, Z1); // Z^2
- square_casper(T4, T3); // Z^4
- multiply_casper(T6, T4, T3); // Z^6
- multiply_casper(T3, b, T6); // bZ^6
-
- multiply_casper(T6, T4, X1); // XZ^4
-
- mul2_casper(T5, T6);
- add_casper(T4, T5, T6); // 3XZ^4
-
- sub_casper(T2, T2, T4); // X^3-3XZ^4
- add_casper(T2, T2, T3); // X^3-3XZ^4+bZ^6
-
- CASPER_ECC_equal(&m, T1, T2);
- if (m != 0)
- {
- return 0;
- }
- return 1;
-}
-
-/* Compute (X3 : Y3: Z3) = (X1: Y1: Z1) + (X2 : Y2 : Z2)
- * where (X1: Y1: Z1) != (X2 : Y2 : Z2)
- * (X3 : Y3: Z3) may be the same as one of the inputs.
- */
-void Jac_addition(uint32_t *X3,
- uint32_t *Y3,
- uint32_t *Z3,
- uint32_t *X1,
- uint32_t *Y1,
- uint32_t *Z1,
- uint32_t *X2,
- uint32_t *Y2,
- uint32_t *Z2)
-{
- uint32_t *Z1Z1, *Z2Z2, *U1, *S1, *J, *H, *V, *t0, *t1;
- int m1, m2;
-
- Z1Z1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- Z2Z2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- U1 = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
- S1 = &CASPER_MEM[ECC_SCRATCH_START + 3 * CASPER_NUM_LIMBS];
- J = &CASPER_MEM[ECC_SCRATCH_START + 4 * CASPER_NUM_LIMBS];
- H = &CASPER_MEM[ECC_SCRATCH_START + 5 * CASPER_NUM_LIMBS];
- V = &CASPER_MEM[ECC_SCRATCH_START + 6 * CASPER_NUM_LIMBS];
- t0 = &CASPER_MEM[ECC_SCRATCH_START + 7 * CASPER_NUM_LIMBS];
- t1 = &CASPER_MEM[ECC_SCRATCH_START + 8 * CASPER_NUM_LIMBS];
-
- CASPER_ECC_equal_to_zero(&m1, Z1);
- CASPER_ECC_equal_to_zero(&m2, Z2);
- if (m1 == 0)
- {
- CASPER_MEMCPY(X3, X2, NUM_LIMBS * 4);
- CASPER_MEMCPY(Y3, Y2, NUM_LIMBS * 4);
- CASPER_MEMCPY(Z3, Z2, NUM_LIMBS * 4);
- return;
- }
- if (m2 == 0)
- {
- CASPER_MEMCPY(X3, X1, NUM_LIMBS * 4);
- CASPER_MEMCPY(Y3, Y1, NUM_LIMBS * 4);
- CASPER_MEMCPY(Z3, Z1, NUM_LIMBS * 4);
- return;
- }
-
- square_casper(Z1Z1, Z1);
- square_casper(Z2Z2, Z2);
- multiply_casper(U1, X1, Z2Z2);
- multiply_casper(H, X2, Z1Z1); /* if H equals U1 then X's are the same */
- multiply_casper(t0, Z2, Z2Z2);
- multiply_casper(S1, Y1, t0);
- multiply_casper(t0, Z1, Z1Z1);
- multiply_casper(J, Y2, t0); /* if (S1 == J) then Y's are the same */
-
- CASPER_ECC_equal(&m1, H, U1); /* If H and U1 match then the X-coordinates are the same. */
- CASPER_ECC_equal(&m2, S1, J); /* If S1 and J match then the Y-coordinates are the same. */
- if (m1 == 0)
- {
- if (m2 == 0)
- {
- Jac_double(X3, Y3, Z3, X1, Y1, Z1);
- return;
- }
- /* else {
- We work with the point at infinity.
- The Z-coordinate will be set to zero in this function.
- } */
- }
-
- sub_casper(H, H, U1);
- mul2_casper(t0, H);
- square_casper(t1, t0);
- sub_casper(t0, J, S1);
- multiply_casper(J, H, t1);
- multiply_casper(V, U1, t1);
- mul2_casper(U1, t0);
- square_casper(t0, U1);
- mul2_casper(t1, V);
- sub_casper(t0, t0, J);
- sub_casper(X3, t0, t1);
- sub_casper(t0, V, X3);
- multiply_casper(t1, S1, J);
- mul2_casper(t1, t1);
- multiply_casper(V, U1, t0);
- sub_casper(Y3, V, t1);
- add_casper(V, Z1, Z2);
- square_casper(t1, V);
- sub_casper(t1, t1, Z1Z1);
- sub_casper(t1, t1, Z2Z2);
- multiply_casper(Z3, t1, H);
-}
-
-/* Compute (X3 : Y3: Z3) = (X1: Y1: Z1) + (X2, Y2)
- * where (X1: Y1: Z1) != (X2, Y2)
- * (X3 : Y3: Z3) may not overlap with (X1: Y1: Z1).
- * Source: 2004 Hankerson–Menezes–Vanstone, page 91.
- */
-void Jac_add_affine(
- uint32_t *X3, uint32_t *Y3, uint32_t *Z3, uint32_t *X1, uint32_t *Y1, uint32_t *Z1, uint32_t *X2, uint32_t *Y2)
-{
- uint32_t *T1, *T2, *T3, *T4, *T5;
- int m1, m2;
-
- T1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- T2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- T3 = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
- T4 = &CASPER_MEM[ECC_SCRATCH_START + 3 * CASPER_NUM_LIMBS];
- T5 = &CASPER_MEM[ECC_SCRATCH_START + 4 * CASPER_NUM_LIMBS];
-
- CASPER_ECC_equal_to_zero(&m1, Z1);
- if (m1 == 0)
- {
- CASPER_MEMCPY(X3, X2, NUM_LIMBS * 4);
- CASPER_MEMCPY(Y3, Y2, NUM_LIMBS * 4);
- CASPER_MEMCPY(Z3, ONE, NUM_LIMBS * 4);
- return;
- }
-
- copy(T5, Z1);
- square_casper(T3, Z1);
- multiply_casper(T2, T3, Z1);
- multiply_casper(T4, T3, X2);
- multiply_casper(T3, T2, Y2);
-
- CASPER_ECC_equal(&m1, T4, X1);
- CASPER_ECC_equal(&m2, T3, Y1);
- if (m1 == 0)
- {
- if (m2 == 0)
- {
- Jac_double(X3, Y3, Z3, X1, Y1, Z1);
- return;
- }
- /* else {
- We work with the point at infinity.
- The Z-coordinate will be set to zero in this function.
- } */
- }
-
- sub_casper(T1, T4, X1);
- sub_casper(T2, T3, Y1);
- multiply_casper(Z3, T5, T1);
- square_casper(T3, T1);
- multiply_casper(T4, T3, T1);
- multiply_casper(T5, T3, X1);
- mul2_casper(T1, T5);
- square_casper(X3, T2);
- sub_casper(X3, X3, T1);
- sub_casper(X3, X3, T4);
- sub_casper(T3, T5, X3);
- multiply_casper(T1, T3, T2);
- multiply_casper(T2, T4, Y1);
- sub_casper(Y3, T1, T2);
-}
-
-extern uint32_t casper_get_word(uint32_t *addr);
-
-/* Point doubling from: 2004 Hankerson–Menezes–Vanstone, page 91.
- * Compute (X3 : Y3: Z3) = (X1: Y1: Z1) + (X1 : Y1 : Z1)
- * (X3 : Y3: Z3) may be the same as the input.
- */
-void Jac_double(uint32_t *X3, uint32_t *Y3, uint32_t *Z3, uint32_t *X1, uint32_t *Y1, uint32_t *Z1)
-{
- uint32_t *T1, *T2, *T3, *T4, *T5;
-
- T1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- T2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- T3 = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
- T4 = &CASPER_MEM[ECC_SCRATCH_START + 3 * CASPER_NUM_LIMBS];
- T5 = &CASPER_MEM[ECC_SCRATCH_START + 4 * CASPER_NUM_LIMBS];
-
- square_casper(T1, Z1);
- sub_casper(T3, X1, T1);
- add_casper(T1, X1, T1);
- multiply_casper(T4, T3, T1);
-
- mul2_casper(T3, T4);
-
- add_casper(T2, T3, T4);
-
- mul2_casper(Y3, Y1);
-
- copy(T5, Z1);
- multiply_casper(Z3, Y3, T5);
-
- square_casper(T5, Y3);
-
- multiply_casper(T3, T5, X1);
-
- square_casper(Y3, T5);
-
- half(T5, Y3, T4);
-
- square_casper(X3, T2);
-
- mul2_casper(T1, T3);
-
- sub_casper(X3, X3, T1);
-
- sub_casper(T1, T3, X3);
-
- multiply_casper(T3, T1, T2);
-
- sub_casper(Y3, T3, T5);
-}
-
-/* Recoding for a signed fixed window.
- * Source: https://eprint.iacr.org/2014/130.pdf, Algorithm 6
- * Recode the n-bit integer k into ciel(log2(n)/(w-1)) digits
- * where each digit is in
- * { +/- 1, +/- 3, ..., +/- 2^(w-1)-1 }
- * and put the result in c.
- */
-static void recode(int8_t *c, uint32_t *k, int n, int w)
-{
- int i, t;
- uint32_t K[NUM_LIMBS] = {0};
- memcpy(K, k, (size_t)ceil(n / 8.));
- t = (n + (w - 2)) / (w - 1);
- for (i = 0; i < t; i++)
- {
- c[i] = (K[0] & ((1 << w) - 1)) - (1 << (w - 1));
- shiftrightSysram(K, K, w - 1);
- add_n_1(K, K, (uint32_t)c[i] >> 31, NUM_LIMBS);
- }
- c[t] = K[0];
-}
-
-static uint32_t sub_n(uint32_t *c, uint32_t *a, uint32_t *b, int n)
-{
- int i;
- uint32_t borrow;
- sub_borrowout(borrow, GET_WORD(&c[0]), a[0], GET_WORD(&b[0]));
- for (i = 1; i < n; i++)
- {
- sub_borrowin_borrowout(borrow, GET_WORD(&c[i]), a[i], GET_WORD(&b[i]), borrow);
- }
- return borrow;
-}
-
-#if 0
-/* Dumb n-limb subtraction of c=a-b, return borrow. */
-static uint32_t sub_n_1(uint32_t *c, uint32_t *a, uint32_t b, int n) {
- int i;
- uint32_t borrow;
- sub_borrowout(borrow, c[0], a[0], b);
- for (i = 1; i < n; i++) {
- sub_borrowin_borrowout_1(borrow, c[i], a[i], borrow);
- }
- return borrow;
-}
-
-/* Dumb n-limb addition of c=a+b, return carry. */
-static uint32_t add_n(uint32_t *c, uint32_t *a, uint32_t *b, int n) {
- int i;
- uint32_t carry;
- add_cout(carry, c[0], a[0], b[0]);
- for (i = 1; i < n; i++) {
- add_cout_cin(carry, c[i], a[i], b[i], carry);
- }
- return carry;
-}
-#endif
-
-/* Dumb n-limb addition of c=a+b, return carry. */
-static uint32_t add_n_1(uint32_t *c, uint32_t *a, uint32_t b, int n)
-{
- int i;
- uint32_t carry;
- add_cout(carry, c[0], a[0], b);
- for (i = 1; i < n; i++)
- {
- add_cout_cin(carry, c[i], a[i], 0, carry);
- }
- return carry;
-}
-
-// http://graphics.stanford.edu/~seander/bithacks.html#IntegerAbs
-static uint8_t int8abs(int8_t v)
-{
- int8_t const mask = v >> 7;
- return (v + mask) ^ mask;
-}
-
-/* Constant time elliptic curve scalar multiplication.
- * Source: https://eprint.iacr.org/2014/130.pdf
- * when using w = 4.
- * Computes (X3 : Y3 : Z3) = k * (X1, Y1) \in E(F_p)
- * p is the prime used to define the finite field F_p
- * q is the (prime) order of the curve
- */
-void Jac_scalar_multiplication(
- uint32_t *X3, uint32_t *Y3, uint32_t *Z3, uint32_t *X1, uint32_t *Y1, uint32_t *k, uint32_t *p, uint32_t *q)
-{
- uint32_t *scalar, *M, *X, *Y, *Z, *mem;
- int i, sign, odd;
- // int8_t *rec;
- uint8_t index;
-
- /* Point to the start of the LUT table space. */
- mem = &CASPER_MEM[LUT_SCRATCH_START];
-
- scalar = &CASPER_MEM[LUT_SCRATCH_START + 12 * CASPER_NUM_LIMBS];
- X = &CASPER_MEM[LUT_SCRATCH_START + 13 * CASPER_NUM_LIMBS];
- Y = &CASPER_MEM[LUT_SCRATCH_START + 14 * CASPER_NUM_LIMBS];
- Z = &CASPER_MEM[LUT_SCRATCH_START + 15 * CASPER_NUM_LIMBS];
- M = &CASPER_MEM[LUT_SCRATCH_START + 16 * CASPER_NUM_LIMBS];
-
- /* Point to memory the recoded scalar.
- * CASPER_RECODE_LENGTH bytes is needed.
- */
- // rec = (int8_t*)&CASPER_MEM[LUT_SCRATCH_START + 17 * CASPER_NUM_LIMBS];
- int8_t rec[CASPER_RECODE_LENGTH];
-
- CASPER_MEMCPY(scalar, k, sizeof(uint32_t) * NUM_LIMBS);
-
-/* Precomputation: compute 1*P, 3*P, 5*P, and 7*P */
-#define LUT(P, x) (mem + (3 * ((P)-1) / 2 + (x)) * CASPER_NUM_LIMBS)
-
- /* Set 1*P */
- copy(Z3, ONE);
- copy(LUT(1, 0), X1);
- copy(LUT(1, 1), Y1);
- copy(LUT(1, 2), Z3);
-
- /* Compute 2*P */
- Jac_double(X3, Y3, Z3, X1, Y1, Z3);
-
- /* Compute 3*P = 2P + P */
- Jac_add_affine(LUT(3, 0), LUT(3, 1), LUT(3, 2), X3, Y3, Z3, X1, Y1);
-
- /* Compute 5*P = 3P + 2P */
- Jac_addition(LUT(5, 0), LUT(5, 1), LUT(5, 2), LUT(3, 0), LUT(3, 1), LUT(3, 2), X3, Y3, Z3);
-
- /* Compute 7*P = 5P + 2P */
- Jac_addition(LUT(7, 0), LUT(7, 1), LUT(7, 2), LUT(5, 0), LUT(5, 1), LUT(5, 2), X3, Y3, Z3);
-
- /* Recode the scalar */
- odd = casper_get_word(&scalar[0]) & 1u;
- sub_n(M, q, scalar, NUM_LIMBS); // todo!!!
- casper_select(scalar, M, scalar, odd, NUM_LIMBS);
-
- /* Use n=384 and w=4 --> compute ciel(384/3) = 128 + 1 digits */
- uint32_t scalarSysram[/*CASPER_*/ NUM_LIMBS];
- CASPER_MEMCPY(scalarSysram, scalar, /*CASPER_*/ NUM_LIMBS * sizeof(uint32_t));
- recode(rec, scalarSysram, N_bitlen, 4);
-
- /* Set the first value. */
- index = int8abs(rec[CASPER_RECODE_LENGTH - 1]);
- sign = ((uint8_t)rec[CASPER_RECODE_LENGTH - 1]) >> 7;
- copy(X3, LUT(index, 0));
- copy(Y3, LUT(index, 1));
- copy(Z3, LUT(index, 2));
-
- /* Get the correct LUT element in constant time by touching
- * all elements and masking out the correct one.
- */
-
-#define GET_LUT(x, y, z, index) \
- do \
- { \
- int m; \
- copy(x, LUT(1, 0)); \
- copy(y, LUT(1, 1)); \
- copy(z, LUT(1, 2)); \
- m = (index == 3); \
- casper_select(x, x, LUT(3, 0), m, NUM_LIMBS); \
- casper_select(y, y, LUT(3, 1), m, NUM_LIMBS); \
- casper_select(z, z, LUT(3, 2), m, NUM_LIMBS); \
- m = (index == 5); \
- casper_select(x, x, LUT(5, 0), m, NUM_LIMBS); \
- casper_select(y, y, LUT(5, 1), m, NUM_LIMBS); \
- casper_select(z, z, LUT(5, 2), m, NUM_LIMBS); \
- m = (index == 7); \
- casper_select(x, x, LUT(7, 0), m, NUM_LIMBS); \
- casper_select(y, y, LUT(7, 1), m, NUM_LIMBS); \
- casper_select(z, z, LUT(7, 2), m, NUM_LIMBS); \
- } while (0)
-
- GET_LUT(X3, Y3, Z3, index);
-
- /* Compute -y and select the positive or negative point. */
- sub_n(M, p, Y3, NUM_LIMBS); // todo!!!
- casper_select(Y3, Y3, M, sign, NUM_LIMBS);
-
- for (i = CASPER_RECODE_LENGTH - 2; i >= 0; i--)
- {
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
-
- index = int8abs(rec[i]);
- sign = ((uint8_t)rec[i]) >> 7;
-
- GET_LUT(X, Y, Z, index);
-
- /* Compute -y and select the positive or negative point. */
- sub_n(scalar, p, Y, NUM_LIMBS); // todo!!!
- casper_select(scalar, Y, scalar, sign, NUM_LIMBS);
-
- Jac_addition(X3, Y3, Z3, X3, Y3, Z3, X, scalar, Z);
- }
-
- sub_n(M, p, Y3, NUM_LIMBS); // todo!!!
-
- casper_select(Y3, M, Y3, odd, NUM_LIMBS);
-}
-
-#undef LUT
-#undef GET_LUT
-
-/*
- * Pre-compute the following 16 points:
- * 00 00 = 0*P + 0*Q <-- Not needed when using sliding windows
- * 00 01 = 0*P + 1*Q <-- Not needed when using sliding windows
- * 00 10 = 0*P + 2*Q
- * 00 11 = 0*P + 3*Q
- *
- * 01 00 = 1*P + 0*Q <-- Not needed when using sliding windows
- * 01 01 = 1*P + 1*Q <-- Not needed when using sliding windows
- * 01 10 = 1*P + 2*Q
- * 01 11 = 1*P + 3*Q
- *
- * 10 00 = 2*P + 0*Q
- * 10 01 = 2*P + 1*Q
- * 10 10 = 2*P + 2*Q
- * 10 11 = 2*P + 3*Q
- *
- * 11 00 = 3*P + 0*Q
- * 11 01 = 3*P + 1*Q
- * 11 10 = 3*P + 2*Q
- * 11 11 = 3*P + 3*Q
- *
- * index = (bitsi||bitsj)-2 - (biti != 0)*2
- *
- * Input: P = (X1 : Y1 : Z1) and
- * Q = (X2 : Y2 : Z2)
- * Output: mem, memory location for the LUT.
- */
-
-#define LUT_LIMBS NUM_LIMBS
-
-static void precompute_double_scalar_LUT(uint32_t *Px, uint32_t *Py, uint32_t *Qx, uint32_t *Qy)
-{
- uint32_t *Q2x, *Q2y, *Q2z, *P2x, *P2y, *P2z, *Z, *mem;
- int index = 0;
-
- Q2x = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 0 * CASPER_NUM_LIMBS];
- Q2y = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 1 * CASPER_NUM_LIMBS];
- Q2z = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 2 * CASPER_NUM_LIMBS];
-
- /* Re-use memory from different scratch space since no
- * projective point addition is used below. */
- P2x = &CASPER_MEM[ECC_SCRATCH_START + 5 * CASPER_NUM_LIMBS];
- P2z = &CASPER_MEM[ECC_SCRATCH_START + 6 * CASPER_NUM_LIMBS];
- P2y = &CASPER_MEM[ECC_SCRATCH_START + 7 * CASPER_NUM_LIMBS];
- Z = &CASPER_MEM[ECC_SCRATCH_START + 8 * CASPER_NUM_LIMBS];
-
- mem = &CASPER_MEM[LUT_SCRATCH_START];
-
- copy(Z, ONE);
-
- // 00 10 = 0*P + 2*Q
- Jac_double(Q2x, Q2y, Q2z, Qx, Qy, Z);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-
- // 00 11 = 0*P + 3*Q
- Jac_add_affine(P2x, P2y, P2z, Q2x, Q2y, Q2z, Qx, Qy);
- copy(&mem[index], P2x);
- index += LUT_LIMBS;
- copy(&mem[index], P2y);
- index += LUT_LIMBS;
- copy(&mem[index], P2z);
- index += LUT_LIMBS;
-
- // 01 10 = 1*P + 2*Q
- Jac_add_affine(P2x, P2y, P2z, Q2x, Q2y, Q2z, Px, Py);
- copy(&mem[index], P2x);
- index += LUT_LIMBS;
- copy(&mem[index], P2y);
- index += LUT_LIMBS;
- copy(&mem[index], P2z);
- index += LUT_LIMBS;
-
- // 01 11 = 1*P + 3*Q
- Jac_add_affine(P2x, P2y, P2z, P2x, P2y, P2z, Qx, Qy);
- copy(&mem[index], P2x);
- index += LUT_LIMBS;
- copy(&mem[index], P2y);
- index += LUT_LIMBS;
- copy(&mem[index], P2z);
- index += LUT_LIMBS;
-
- // 10 00 = 2*P + 0*Q
- Jac_double(P2x, P2y, P2z, Px, Py, Z);
- copy(&mem[index], P2x);
- index += LUT_LIMBS;
- copy(&mem[index], P2y);
- index += LUT_LIMBS;
- copy(&mem[index], P2z);
- index += LUT_LIMBS;
-
- // 10 01 = 2*P + 1*Q
- Jac_add_affine(Q2x, Q2y, Q2z, P2x, P2y, P2z, Qx, Qy);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-
- // 10 10 = 2*P + 2*Q
- Jac_add_affine(Q2x, Q2y, Q2z, Q2x, Q2y, Q2z, Qx, Qy);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-
- // 10 11 = 2*P + 3*Q
- Jac_add_affine(Q2x, Q2y, Q2z, Q2x, Q2y, Q2z, Qx, Qy);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-
- // 11 00 = 3*P + 0*Q
- Jac_add_affine(P2x, P2y, P2z, P2x, P2y, P2z, Px, Py);
- copy(&mem[index], P2x);
- index += LUT_LIMBS;
- copy(&mem[index], P2y);
- index += LUT_LIMBS;
- copy(&mem[index], P2z);
- index += LUT_LIMBS;
-
- // 11 01 = 3*P + 1*Q
- Jac_add_affine(Q2x, Q2y, Q2z, P2x, P2y, P2z, Qx, Qy);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-
- // 11 10 = 3*P + 2*Q
- Jac_add_affine(Q2x, Q2y, Q2z, Q2x, Q2y, Q2z, Qx, Qy);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-
- // 11 11 = 3*P + 3*Q
- Jac_add_affine(Q2x, Q2y, Q2z, Q2x, Q2y, Q2z, Qx, Qy);
- copy(&mem[index], Q2x);
- index += LUT_LIMBS;
- copy(&mem[index], Q2y);
- index += LUT_LIMBS;
- copy(&mem[index], Q2z);
- index += LUT_LIMBS;
-}
-
-#define GETLUTX(x) (3 * (x)*LUT_LIMBS)
-#define GETLUTY(x) (3 * (x)*LUT_LIMBS + 1 * LUT_LIMBS)
-#define GETLUTZ(x) (3 * (x)*LUT_LIMBS + 2 * LUT_LIMBS)
-
-/* Compute the double scalar multiplication
- * (X3 : Y3 : Z3) = k1 * (X1, Y1) + k2 * (X2, Y2)
- * Using Shamir's trick and precomputing 16 points.
- * This code is *not* constant time since this is used
- * for verification only.
- */
-void double_scalar_multiplication(uint32_t *X3,
- uint32_t *Y3,
- uint32_t *Z3,
- uint32_t *X1,
- uint32_t *Y1,
- uint32_t *k1,
- uint32_t *X2,
- uint32_t *Y2,
- uint32_t *k2)
-{
- uint32_t index, c = 0;
- uint32_t *p1, *p2, x1, x2, *lut, *Tx, *Ty, *Tz;
-
- precompute_double_scalar_LUT(X1, Y1, X2, Y2);
-
- lut = &CASPER_MEM[LUT_SCRATCH_START];
- p1 = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS];
- p2 = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 1 * CASPER_NUM_LIMBS];
-
- Tx = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 2 * CASPER_NUM_LIMBS];
- Ty = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 3 * CASPER_NUM_LIMBS];
- Tz = &CASPER_MEM[LUT_SCRATCH_START + 48 * LUT_LIMBS + 4 * CASPER_NUM_LIMBS];
-
- CASPER_MEMCPY(p1, k1, sizeof(uint32_t) * NUM_LIMBS);
- CASPER_MEMCPY(p2, k2, sizeof(uint32_t) * NUM_LIMBS);
-
- /* Check if we can slide. */
- while (((casper_get_word(&p1[NUM_LIMBS - 1]) | casper_get_word(&p2[NUM_LIMBS - 1])) >> 31) == 0 && c < 256)
- {
- shiftleft(p1, p1, 1);
- shiftleft(p2, p2, 1);
- c++;
- /* No doubling needed. */
- }
-
- /* Set the first value. */
- x1 = casper_get_word(&p1[NUM_LIMBS - 1]) >> 30;
- x2 = casper_get_word(&p2[NUM_LIMBS - 1]) >> 30;
- index = (x2 | (x1 << 2)) - 2 - (x1 != 0) * 2;
- shiftleft(p1, p1, 2);
- shiftleft(p2, p2, 2);
-
- copy(X3, &lut[GETLUTX(index)]);
- copy(Y3, &lut[GETLUTY(index)]);
- copy(Z3, &lut[GETLUTZ(index)]);
- c += 2;
-
-// todo: create an is_zero function
-#if CASPER_ECC_P256
- while ((casper_get_word(&p1[0]) | casper_get_word(&p1[1]) | casper_get_word(&p1[2]) | casper_get_word(&p1[3]) |
- casper_get_word(&p1[4]) | casper_get_word(&p1[5]) | casper_get_word(&p1[6]) | casper_get_word(&p1[7]) |
- casper_get_word(&p2[0]) | casper_get_word(&p2[1]) | casper_get_word(&p2[2]) | casper_get_word(&p2[3]) |
- casper_get_word(&p2[4]) | casper_get_word(&p2[5]) | casper_get_word(&p2[6]) | casper_get_word(&p2[7])) != 0)
- {
-#elif CASPER_ECC_P384
- while ((casper_get_word(&p1[0]) | casper_get_word(&p1[1]) | casper_get_word(&p1[2]) | casper_get_word(&p1[3]) |
- casper_get_word(&p1[4]) | casper_get_word(&p1[5]) | casper_get_word(&p1[6]) | casper_get_word(&p1[7]) |
- casper_get_word(&p1[8]) | casper_get_word(&p1[9]) | casper_get_word(&p1[10]) | casper_get_word(&p1[11]) |
- casper_get_word(&p2[0]) | casper_get_word(&p2[1]) | casper_get_word(&p2[2]) | casper_get_word(&p2[3]) |
- casper_get_word(&p2[4]) | casper_get_word(&p2[5]) | casper_get_word(&p2[6]) | casper_get_word(&p2[7]) |
- casper_get_word(&p2[8]) | casper_get_word(&p2[9]) | casper_get_word(&p2[10]) | casper_get_word(&p2[11])) !=
- 0)
- {
-#endif
- /* Check if we can slide. */
- while (((casper_get_word(&p1[NUM_LIMBS - 1]) | casper_get_word(&p2[NUM_LIMBS - 1])) >> 31) == 0 && c < N_bitlen)
- {
- shiftleft(p1, p1, 1);
- shiftleft(p2, p2, 1);
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
- c++;
- }
-
- if (c >= (N_bitlen - 1))
- break;
-
- /* Double twice. */
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
-
- /* Add in the correct value. */
- x1 = casper_get_word(&p1[NUM_LIMBS - 1]) >> 30;
- x2 = casper_get_word(&p2[NUM_LIMBS - 1]) >> 30;
- index = (x2 | (x1 << 2)) - 2 - (x1 != 0) * 2;
-
- shiftleft(p1, p1, 2);
- shiftleft(p2, p2, 2);
-
- copy(Tx, &lut[GETLUTX(index)]);
- copy(Ty, &lut[GETLUTY(index)]);
- copy(Tz, &lut[GETLUTZ(index)]);
-
- Jac_addition(X3, Y3, Z3, X3, Y3, Z3, Tx, Ty,
- Tz); //&lut[GETLUTX(index)], &lut[GETLUTY(index)], &lut[GETLUTZ(index)]);
- c += 2;
- }
-
- /* Special case in the end. */
- if (c == (N_bitlen - 1))
- {
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
- x1 = casper_get_word(&p1[NUM_LIMBS - 1]) >> 31;
- x2 = casper_get_word(&p2[NUM_LIMBS - 1]) >> 31;
- if (x1)
- {
- Jac_add_affine(X3, Y3, Z3, X3, Y3, Z3, X1, Y1);
- }
- if (x2)
- {
- Jac_add_affine(X3, Y3, Z3, X3, Y3, Z3, X2, Y2);
- }
- c++;
- }
-
- while (c < N_bitlen)
- {
- Jac_double(X3, Y3, Z3, X3, Y3, Z3);
- c++;
- }
-}
-
-#if CASPER_ECC_P256
-static void invert_mod_p256(uint32_t *c, uint32_t *a)
-{
- int i;
- uint32_t *t, *t2, *s1, *s2, *s4, *s8, *tmp;
-
- /* Assuming it is safe to use the ECC scratch size. */
- t = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
- t2 = &CASPER_MEM[ECC_SCRATCH_START + 3 * CASPER_NUM_LIMBS];
- s1 = &CASPER_MEM[ECC_SCRATCH_START + 4 * CASPER_NUM_LIMBS];
- s2 = &CASPER_MEM[ECC_SCRATCH_START + 5 * CASPER_NUM_LIMBS];
- s4 = &CASPER_MEM[ECC_SCRATCH_START + 6 * CASPER_NUM_LIMBS];
- s8 = &CASPER_MEM[ECC_SCRATCH_START + 7 * CASPER_NUM_LIMBS];
- tmp = &CASPER_MEM[ECC_SCRATCH_START + 8 * CASPER_NUM_LIMBS];
-
- // t2 = n^(2^1)*n # 11
- square_casper(tmp, a);
- multiply_casper(t2, tmp, a);
-
- // s1 = t2^(2^2)*t2 # F
- square_casper(s1, t2);
- square_casper(tmp, s1);
- multiply_casper(s1, tmp, t2);
-
- // s2 = s1^(2^4)*s1 # FF
- square_casper(s2, s1);
- // for (i = 1; i < 4; i++) square(s2, s2);
- square_casper(tmp, s2);
- square_casper(s2, tmp);
- square_casper(tmp, s2);
- multiply_casper(s2, tmp, s1);
-
- // s4 = s2^(2^8)*s2 # FFFF
- square_casper(s4, s2);
- for (i = 1; i < 7; i += 2)
- {
- square_casper(tmp, s4);
- square_casper(s4, tmp);
- }
- square_casper(tmp, s4);
- multiply_casper(s4, tmp, s2);
-
- // s8 = s4^(2^16)*s4 # FFFFFFFF
- square_casper(s8, s4);
- for (i = 1; i < 15; i += 2)
- {
- square_casper(tmp, s8);
- square_casper(s8, tmp);
- }
- square_casper(tmp, s8);
- multiply_casper(s8, tmp, s4);
-
- // t = s8^(2^32)*n # ffffffff00000001
- square_casper(tmp, s8);
- for (i = 1; i < 31; i += 2)
- {
- square_casper(t, tmp);
- square_casper(tmp, t);
- }
- square_casper(t, tmp);
- multiply_casper(tmp, t, a);
-
- // t = t^(2^128)*s8 # ffffffff00000001000000000000000000000000ffffffff
- for (i = 0; i < 128; i += 2)
- {
- square_casper(t, tmp);
- square_casper(tmp, t);
- }
- multiply_casper(t, tmp, s8);
-
- // t = t^(2^32)*s8 # ffffffff00000001000000000000000000000000ffffffffffffffff
- for (i = 0; i < 32; i += 2)
- {
- square_casper(tmp, t);
- square_casper(t, tmp);
- }
- multiply_casper(tmp, t, s8);
-
- // t = t^(2^16)*s4 # ffffffff00000001000000000000000000000000ffffffffffffffffffff
- for (i = 0; i < 16; i += 2)
- {
- square_casper(t, tmp);
- square_casper(tmp, t);
- }
- multiply_casper(t, tmp, s4);
-
- // t = t^(2^8)*s2 # ffffffff00000001000000000000000000000000ffffffffffffffffffffff
- for (i = 0; i < 8; i += 2)
- {
- square_casper(tmp, t);
- square_casper(t, tmp);
- }
- multiply_casper(tmp, t, s2);
-
- // t = t^(2^4)*s1 # ffffffff00000001000000000000000000000000fffffffffffffffffffffff
- for (i = 0; i < 4; i += 2)
- {
- square_casper(t, tmp);
- square_casper(tmp, t);
- }
- multiply_casper(t, tmp, s1);
-
- // t = t^(2^2)*t2
- square_casper(tmp, t);
- square_casper(t, tmp);
- multiply_casper(tmp, t, t2);
-
- // t = t^(2^2)*n # ffffffff00000001000000000000000000000000fffffffffffffffffffffffd
- square_casper(t, tmp);
- square_casper(tmp, t);
- multiply_casper(c, tmp, a);
-}
-
-// A and C do not need to be in Casper memory
-static void toMontgomery(uint32_t *C, uint32_t *A)
-{
- /* R^2 = 2^512 mod p, used to convert values to Montgomery form. */
- uint32_t R2[NUM_LIMBS] = {0x00000003, 0x00000000, 0xffffffff, 0xfffffffb, 0xfffffffe, 0xffffffff, 0xfffffffd, 0x4};
- uint32_t *T1, *T2, *T3;
- T1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- T2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- T3 = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
-
- CASPER_MEMCPY(T1, R2, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(T2, A, NUM_LIMBS * sizeof(uint32_t));
-
- multiply_casper(T3, T2, T1);
- CASPER_MEMCPY(C, T3, NUM_LIMBS * sizeof(uint32_t));
-}
-#endif /* CASPER_ECC_P256 */
-
-/* Compute inversion modulo NIST-p384 using Fermats little theorem.
- * Using c = a^(p-2) = a^(-1) mod p.
- * This computes the modular inversion if all arithmetic is "regular"
- * modular arithmetic or computes automatically the Montgomery inverse
- * if all arithmetic is Montgomery arithmetic.
- */
-#if CASPER_ECC_P384
-static void invert_mod_p384(uint32_t *c, uint32_t *a)
-{
- int i;
- uint32_t *e, *d, *tmp, *t0, *t1, *t2, *t3, *t4, *t5, *t6; // 10 residues needed
-
- /* Assuming it is safe to use the LUT scratch size.
- * Hence, do not invert while elements in the LUT are needed.
- */
- e = &CASPER_MEM[LUT_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- d = &CASPER_MEM[LUT_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- tmp = &CASPER_MEM[LUT_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
- t0 = &CASPER_MEM[LUT_SCRATCH_START + 3 * CASPER_NUM_LIMBS];
- t1 = &CASPER_MEM[LUT_SCRATCH_START + 4 * CASPER_NUM_LIMBS];
- t2 = &CASPER_MEM[LUT_SCRATCH_START + 5 * CASPER_NUM_LIMBS];
- t3 = &CASPER_MEM[LUT_SCRATCH_START + 6 * CASPER_NUM_LIMBS];
- t4 = &CASPER_MEM[LUT_SCRATCH_START + 7 * CASPER_NUM_LIMBS];
- t5 = &CASPER_MEM[LUT_SCRATCH_START + 8 * CASPER_NUM_LIMBS];
- t6 = &CASPER_MEM[LUT_SCRATCH_START + 9 * CASPER_NUM_LIMBS];
-
- square_casper(tmp, a); // 2
- square_casper(t1, tmp); // 4
- square_casper(tmp, t1); // 8
- multiply_casper(t2, tmp, t1); // 12
- multiply_casper(d, a, t2); // 13
- multiply_casper(e, d, a); // 14
- multiply_casper(t0, e, a); // 15
-
- // t1 = t0^(2^4)*t0 # ff
- square_casper(tmp, t0);
- square_casper(t1, tmp);
- square_casper(tmp, t1);
- square_casper(t2, tmp);
- multiply_casper(t1, t2, t0);
-
- // t2 = t1^(2^8)*t1 # 4f
- square_casper(tmp, t1);
- for (i = 0; i < 3; i++)
- {
- square_casper(t3, tmp);
- square_casper(tmp, t3);
- }
- square_casper(t3, tmp);
- multiply_casper(t2, t3, t1);
-
- // t3 = t2^(2^16)*t2 # 8f
- square_casper(tmp, t2);
- for (i = 0; i < 7; i++)
- {
- square_casper(t4, tmp);
- square_casper(tmp, t4);
- }
- square_casper(t4, tmp);
- multiply_casper(t3, t4, t2);
-
- // t4 = t3^(2^32)*t3 # 16f
- square_casper(tmp, t3);
- for (i = 0; i < 15; i++)
- {
- square_casper(t5, tmp);
- square_casper(tmp, t5);
- }
- square_casper(t5, tmp);
- multiply_casper(t4, t5, t3);
-
- // t5 = t4^(2^64)*t4 # 32f
- square_casper(tmp, t4);
- for (i = 0; i < 31; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t4);
-
- // t5 = t5^(2^64)*t4 # 48f
- square_casper(tmp, t5);
- for (i = 0; i < 31; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t4);
-
- // t5 = t5^(2^32)*t3 # 56f
- square_casper(tmp, t5);
- for (i = 0; i < 15; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t3);
-
- // t5 = t5^(2^16)*t2 # 60f
- square_casper(tmp, t5);
- for (i = 0; i < 7; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t2);
-
- // t5 = t5^(2^8)*t1 # 62f
- square_casper(tmp, t5);
- for (i = 0; i < 3; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t1);
-
- // n = t5^(2^4)*t0 # 63f
- square_casper(tmp, t5);
- for (i = 0; i < 1; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t0);
-
- // n = n^(2^4)*e
- square_casper(tmp, t5);
- for (i = 0; i < 1; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, e);
-
- // n = n^(2^32)*t3
- square_casper(tmp, t5);
- for (i = 0; i < 15; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t3);
-
- // n = n^(2^64)
- square_casper(tmp, t5);
- for (i = 0; i < 31; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t5, tmp);
-
- // n = n^(2^16)*t2
- square_casper(tmp, t5);
- for (i = 0; i < 7; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t2);
-
- // n = n^(2^8)*t1
- square_casper(tmp, t5);
- for (i = 0; i < 3; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t1);
-
- // n = n^(2^4)*t0
- square_casper(tmp, t5);
- for (i = 0; i < 1; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(t5, t6, t0);
-
- // n = n^(2^4)*d
- square_casper(tmp, t5);
- for (i = 0; i < 1; i++)
- {
- square_casper(t6, tmp);
- square_casper(tmp, t6);
- }
- square_casper(t6, tmp);
- multiply_casper(c, t6, d);
-}
-
-// A and C do not need to be in Casper memory
-static void toMontgomery(uint32_t *C, uint32_t *A)
-{
- /* R^2 = 2^768 mod p, used to convert values to Montgomery form. */
- uint32_t R2[NUM_LIMBS] = {0x00000001, 0xfffffffe, 0x00000000, 0x00000002, 0x00000000, 0xfffffffe,
- 0x00000000, 0x00000002, 0x1, 0x0, 0x0, 0x0};
- uint32_t *T1, *T2, *T3;
- T1 = &CASPER_MEM[ECC_SCRATCH_START + 0 * CASPER_NUM_LIMBS];
- T2 = &CASPER_MEM[ECC_SCRATCH_START + 1 * CASPER_NUM_LIMBS];
- T3 = &CASPER_MEM[ECC_SCRATCH_START + 2 * CASPER_NUM_LIMBS];
-
- CASPER_MEMCPY(T1, R2, NUM_LIMBS * sizeof(uint32_t));
- CASPER_MEMCPY(T2, A, NUM_LIMBS * sizeof(uint32_t));
-
- multiply_casper(T3, T2, T1);
- CASPER_MEMCPY(C, T3, NUM_LIMBS * sizeof(uint32_t));
-}
-#endif /* CASPER_ECC_P384 */
-
-#if defined(__GNUC__)
-/* End of enforcing O1 optimize level */
-#pragma GCC pop_options
-#endif
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.h
deleted file mode 100755
index 6191b585b..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_casper.h
+++ /dev/null
@@ -1,312 +0,0 @@
-/*
- * Copyright 2018-2019 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _FSL_CASPER_H_
-#define _FSL_CASPER_H_
-
-#include "fsl_common.h"
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- *******************************************************************************/
-
-/*!
- * @addtogroup casper_driver
- * @{
- */
-/*! @name Driver version */
-/*@{*/
-/*! @brief CASPER driver version. Version 2.0.5.
- *
- * Current version: 2.0.5
- *
- * Change log:
- * - Version 2.0.0
- * - Initial version
- * - Version 2.0.1
- * - Bug fix KPSDK-24531 double_scalar_multiplication() result may be all zeroes for some specific input
- * - Version 2.0.2
- * - Bug fix KPSDK-25015 CASPER_MEMCPY hard-fault on LPC55xx when both source and destination buffers are outside of
- * CASPER_RAM
- * - Version 2.0.3
- * - Bug fix KPSDK-28107 RSUB, FILL and ZERO operations not implemented in enum _casper_operation.
- * - Version 2.0.4
- * - For GCC compiler, enforce O1 optimize level, specifically to remove strict-aliasing option.
- * This driver is very specific and requires -fno-strict-aliasing.
- * - Version 2.0.5
- * - Fix sign-compare warning.
- */
-#define FSL_CASPER_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
-/*@}*/
-
-/*! @brief CASPER operation
- *
- */
-typedef enum _casper_operation
-{
- kCASPER_OpMul6464NoSum = 0x01, /*! Walking 1 or more of J loop, doing r=a*b using 64x64=128*/
- kCASPER_OpMul6464Sum =
- 0x02, /*! Walking 1 or more of J loop, doing c,r=r+a*b using 64x64=128, but assume inner j loop*/
- kCASPER_OpMul6464FullSum =
- 0x03, /*! Walking 1 or more of J loop, doing c,r=r+a*b using 64x64=128, but sum all of w. */
- kCASPER_OpMul6464Reduce =
- 0x04, /*! Walking 1 or more of J loop, doing c,r[-1]=r+a*b using 64x64=128, but skip 1st write*/
- kCASPER_OpAdd64 = 0x08, /*! Walking add with off_AB, and in/out off_RES doing c,r=r+a+c using 64+64=65*/
- kCASPER_OpSub64 = 0x09, /*! Walking subtract with off_AB, and in/out off_RES doing r=r-a using 64-64=64, with last
- borrow implicit if any*/
- kCASPER_OpDouble64 = 0x0A, /*! Walking add to self with off_RES doing c,r=r+r+c using 64+64=65*/
- kCASPER_OpXor64 = 0x0B, /*! Walking XOR with off_AB, and in/out off_RES doing r=r^a using 64^64=64*/
- kCASPER_OpRSub64 = 0x0C, /*! Walking subtract with off_AB, and in/out off_RES using r=a-r */
- kCASPER_OpShiftLeft32 =
- 0x10, /*! Walking shift left doing r1,r=(b*D)|r1, where D is 2^amt and is loaded by app (off_CD not used)*/
- kCASPER_OpShiftRight32 = 0x11, /*! Walking shift right doing r,r1=(b*D)|r1, where D is 2^(32-amt) and is loaded by
- app (off_CD not used) and off_RES starts at MSW*/
- kCASPER_OpCopy = 0x14, /*! Copy from ABoff to resoff, 64b at a time*/
- kCASPER_OpRemask = 0x15, /*! Copy and mask from ABoff to resoff, 64b at a time*/
- kCASPER_OpFill = 0x16, /*! Fill RESOFF using 64 bits at a time with value in A and B */
- kCASPER_OpZero = 0x17, /*! Fill RESOFF using 64 bits at a time of 0s */
- kCASPER_OpCompare = 0x18, /*! Compare two arrays, running all the way to the end*/
- kCASPER_OpCompareFast = 0x19, /*! Compare two arrays, stopping on 1st !=*/
-} casper_operation_t;
-
-#define CASPER_CP 1
-#define CASPER_CP_CTRL0 (0x0 >> 2)
-#define CASPER_CP_CTRL1 (0x4 >> 2)
-#define CASPER_CP_LOADER (0x8 >> 2)
-#define CASPER_CP_STATUS (0xC >> 2)
-#define CASPER_CP_INTENSET (0x10 >> 2)
-#define CASPER_CP_INTENCLR (0x14 >> 2)
-#define CASPER_CP_INTSTAT (0x18 >> 2)
-#define CASPER_CP_AREG (0x20 >> 2)
-#define CASPER_CP_BREG (0x24 >> 2)
-#define CASPER_CP_CREG (0x28 >> 2)
-#define CASPER_CP_DREG (0x2C >> 2)
-#define CASPER_CP_RES0 (0x30 >> 2)
-#define CASPER_CP_RES1 (0x34 >> 2)
-#define CASPER_CP_RES2 (0x38 >> 2)
-#define CASPER_CP_RES3 (0x3C >> 2)
-#define CASPER_CP_MASK (0x60 >> 2)
-#define CASPER_CP_REMASK (0x64 >> 2)
-#define CASPER_CP_LOCK (0x80 >> 2)
-#define CASPER_CP_ID (0xFFC >> 2)
-/* mcr (cp, opc1, value, CRn, CRm, opc2) */
-#define CASPER_Wr32b(value, off) __arm_mcr(CASPER_CP, 0, value, ((off >> 4)), (off), 0)
-/* mcrr(coproc, opc1, value, CRm) */
-#define CASPER_Wr64b(value, off) __arm_mcrr(CASPER_CP, 0, value, off)
-/* mrc(coproc, opc1, CRn, CRm, opc2) */
-#define CASPER_Rd32b(off) __arm_mrc(CASPER_CP, 0, ((off >> 4)), (off), 0)
-
-/* The model for this algo is that it can be implemented for a fixed size RSA key */
-/* for max speed. If this is made into a variable (to allow varying size), then */
-/* it will be slower by a bit. */
-/* The file is compiled with N_bitlen passed in as number of bits of the RSA key */
-/* #define N_bitlen 2048 */
-#define N_wordlen_max (4096 / 32)
-
-#define CASPER_ECC_P256 1
-#define CASPER_ECC_P384 0
-
-#if CASPER_ECC_P256
-#define N_bitlen 256
-#endif /* CASPER_ECC_P256 */
-
-#if CASPER_ECC_P384
-#define N_bitlen 384
-#endif /* CASPER_ECC_P256 */
-
-#define NUM_LIMBS (N_bitlen / 32)
-
-enum
-{
- kCASPER_RamOffset_Result = 0x0u,
- kCASPER_RamOffset_Base = (N_wordlen_max + 8u),
- kCASPER_RamOffset_TempBase = (2u * N_wordlen_max + 16u),
- kCASPER_RamOffset_Modulus = (kCASPER_RamOffset_TempBase + N_wordlen_max + 4u),
- kCASPER_RamOffset_M64 = 1022,
-};
-
-/*! @} */
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*!
- * @addtogroup casper_driver
- * @{
- */
-
-/*!
- * @brief Enables clock and disables reset for CASPER peripheral.
- *
- * Enable clock and disable reset for CASPER.
- *
- * @param base CASPER base address
- */
-void CASPER_Init(CASPER_Type *base);
-
-/*!
- * @brief Disables clock for CASPER peripheral.
- *
- * Disable clock and enable reset.
- *
- * @param base CASPER base address
- */
-void CASPER_Deinit(CASPER_Type *base);
-
-/*!
- *@}
- */ /* end of casper_driver */
-
-/*******************************************************************************
- * PKHA API
- ******************************************************************************/
-
-/*!
- * @addtogroup casper_driver_pkha
- * @{
- */
-
-/*!
- * @brief Performs modular exponentiation - (A^E) mod N.
- *
- * This function performs modular exponentiation.
- *
- * @param base CASPER base address
- * @param signature first addend (in little endian format)
- * @param pubN modulus (in little endian format)
- * @param wordLen Size of pubN in bytes
- * @param pubE exponent
- * @param[out] plaintext Output array to store result of operation (in little endian format)
- */
-void CASPER_ModExp(CASPER_Type *base,
- const uint8_t *signature,
- const uint8_t *pubN,
- size_t wordLen,
- uint32_t pubE,
- uint8_t *plaintext);
-
-void CASPER_ecc_init(void);
-
-/*!
- * @brief Performs ECC secp256r1 point single scalar multiplication
- *
- * This function performs ECC secp256r1 point single scalar multiplication
- * [resX; resY] = scalar * [X; Y]
- * Coordinates are affine in normal form, little endian.
- * Scalars are little endian.
- * All arrays are little endian byte arrays, uint32_t type is used
- * only to enforce the 32-bit alignment (0-mod-4 address).
- *
- * @param base CASPER base address
- * @param[out] resX Output X affine coordinate in normal form, little endian.
- * @param[out] resY Output Y affine coordinate in normal form, little endian.
- * @param X Input X affine coordinate in normal form, little endian.
- * @param Y Input Y affine coordinate in normal form, little endian.
- * @param scalar Input scalar integer, in normal form, little endian.
- */
-void CASPER_ECC_SECP256R1_Mul(
- CASPER_Type *base, uint32_t resX[8], uint32_t resY[8], uint32_t X[8], uint32_t Y[8], uint32_t scalar[8]);
-
-/*!
- * @brief Performs ECC secp256r1 point double scalar multiplication
- *
- * This function performs ECC secp256r1 point double scalar multiplication
- * [resX; resY] = scalar1 * [X1; Y1] + scalar2 * [X2; Y2]
- * Coordinates are affine in normal form, little endian.
- * Scalars are little endian.
- * All arrays are little endian byte arrays, uint32_t type is used
- * only to enforce the 32-bit alignment (0-mod-4 address).
- *
- * @param base CASPER base address
- * @param[out] resX Output X affine coordinate.
- * @param[out] resY Output Y affine coordinate.
- * @param X1 Input X1 affine coordinate.
- * @param Y1 Input Y1 affine coordinate.
- * @param scalar1 Input scalar1 integer.
- * @param X2 Input X2 affine coordinate.
- * @param Y2 Input Y2 affine coordinate.
- * @param scalar2 Input scalar2 integer.
- */
-void CASPER_ECC_SECP256R1_MulAdd(CASPER_Type *base,
- uint32_t resX[8],
- uint32_t resY[8],
- uint32_t X1[8],
- uint32_t Y1[8],
- uint32_t scalar1[8],
- uint32_t X2[8],
- uint32_t Y2[8],
- uint32_t scalar2[8]);
-
-/*!
- * @brief Performs ECC secp384r1 point single scalar multiplication
- *
- * This function performs ECC secp384r1 point single scalar multiplication
- * [resX; resY] = scalar * [X; Y]
- * Coordinates are affine in normal form, little endian.
- * Scalars are little endian.
- * All arrays are little endian byte arrays, uint32_t type is used
- * only to enforce the 32-bit alignment (0-mod-4 address).
- *
- * @param base CASPER base address
- * @param[out] resX Output X affine coordinate in normal form, little endian.
- * @param[out] resY Output Y affine coordinate in normal form, little endian.
- * @param X Input X affine coordinate in normal form, little endian.
- * @param Y Input Y affine coordinate in normal form, little endian.
- * @param scalar Input scalar integer, in normal form, little endian.
- */
-void CASPER_ECC_SECP384R1_Mul(
- CASPER_Type *base, uint32_t resX[12], uint32_t resY[12], uint32_t X[12], uint32_t Y[12], uint32_t scalar[12]);
-
-/*!
- * @brief Performs ECC secp384r1 point double scalar multiplication
- *
- * This function performs ECC secp384r1 point double scalar multiplication
- * [resX; resY] = scalar1 * [X1; Y1] + scalar2 * [X2; Y2]
- * Coordinates are affine in normal form, little endian.
- * Scalars are little endian.
- * All arrays are little endian byte arrays, uint32_t type is used
- * only to enforce the 32-bit alignment (0-mod-4 address).
- *
- * @param base CASPER base address
- * @param[out] resX Output X affine coordinate.
- * @param[out] resY Output Y affine coordinate.
- * @param X1 Input X1 affine coordinate.
- * @param Y1 Input Y1 affine coordinate.
- * @param scalar1 Input scalar1 integer.
- * @param X2 Input X2 affine coordinate.
- * @param Y2 Input Y2 affine coordinate.
- * @param scalar2 Input scalar2 integer.
- */
-void CASPER_ECC_SECP384R1_MulAdd(CASPER_Type *base,
- uint32_t resX[12],
- uint32_t resY[12],
- uint32_t X1[12],
- uint32_t Y1[12],
- uint32_t scalar1[12],
- uint32_t X2[12],
- uint32_t Y2[12],
- uint32_t scalar2[12]);
-
-void CASPER_ECC_equal(int *res, uint32_t *op1, uint32_t *op2);
-void CASPER_ECC_equal_to_zero(int *res, uint32_t *op1);
-
-/*!
- *@}
- */ /* end of casper_driver_pkha */
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* _FSL_CASPER_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.c
deleted file mode 100755
index 63d8ceb55..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.c
+++ /dev/null
@@ -1,2031 +0,0 @@
-/*
- * Copyright 2017 - 2020 , NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_clock.h"
-#include "fsl_power.h"
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.clock"
-#endif
-#define NVALMAX (0x100U)
-#define PVALMAX (0x20U)
-#define MVALMAX (0x10000U)
-
-#define PLL_MAX_N_DIV 0x100U
-
-/*--------------------------------------------------------------------------
-!!! If required these #defines can be moved to chip library file
-----------------------------------------------------------------------------*/
-
-#define PLL_SSCG1_MDEC_VAL_P (10U) /* MDEC is in bits 25 downto 10 */
-#define PLL_SSCG1_MDEC_VAL_M (0xFFFFULL << PLL_SSCG1_MDEC_VAL_P)
-#define PLL_NDEC_VAL_P (0U) /* NDEC is in bits 9:0 */
-#define PLL_NDEC_VAL_M (0xFFUL << PLL_NDEC_VAL_P)
-#define PLL_PDEC_VAL_P (0U) /*!< PDEC is in bits 6:0 */
-#define PLL_PDEC_VAL_M (0x1FUL << PLL_PDEC_VAL_P)
-
-#define PLL_MIN_CCO_FREQ_MHZ (275000000U)
-#define PLL_MAX_CCO_FREQ_MHZ (550000000U)
-#define PLL_LOWER_IN_LIMIT (2000U) /*!< Minimum PLL input rate */
-#define PLL_HIGHER_IN_LIMIT (150000000U) /*!< Maximum PLL input rate */
-#define PLL_MIN_IN_SSMODE (3000000U)
-#define PLL_MAX_IN_SSMODE \
- (100000000U) /*!< Not find the value in UM, Just use the maximum frequency which device support */
-
-/* PLL NDEC reg */
-#define PLL_NDEC_VAL_SET(value) (((unsigned long)(value) << PLL_NDEC_VAL_P) & PLL_NDEC_VAL_M)
-/* PLL PDEC reg */
-#define PLL_PDEC_VAL_SET(value) (((unsigned long)(value) << PLL_PDEC_VAL_P) & PLL_PDEC_VAL_M)
-/* SSCG control1 */
-#define PLL_SSCG1_MDEC_VAL_SET(value) (((uint64_t)(value) << PLL_SSCG1_MDEC_VAL_P) & PLL_SSCG1_MDEC_VAL_M)
-
-/* PLL0 SSCG control1 */
-#define PLL0_SSCG_MD_FRACT_P 0U
-#define PLL0_SSCG_MD_INT_P 25U
-#define PLL0_SSCG_MD_FRACT_M (0x1FFFFFFUL << PLL0_SSCG_MD_FRACT_P)
-#define PLL0_SSCG_MD_INT_M ((uint64_t)0xFFUL << PLL0_SSCG_MD_INT_P)
-
-#define PLL0_SSCG_MD_FRACT_SET(value) (((uint64_t)(value) << PLL0_SSCG_MD_FRACT_P) & PLL0_SSCG_MD_FRACT_M)
-#define PLL0_SSCG_MD_INT_SET(value) (((uint64_t)(value) << PLL0_SSCG_MD_INT_P) & PLL0_SSCG_MD_INT_M)
-
-/* Saved value of PLL output rate, computed whenever needed to save run-time
- computation on each call to retrive the PLL rate. */
-static uint32_t s_Pll0_Freq;
-static uint32_t s_Pll1_Freq;
-
-/** External clock rate on the CLKIN pin in Hz. If not used,
- set this to 0. Otherwise, set it to the exact rate in Hz this pin is
- being driven at. */
-static uint32_t s_Ext_Clk_Freq = 16000000U;
-static uint32_t s_I2S_Mclk_Freq = 0U;
-static uint32_t s_PLU_ClkIn_Freq = 0U;
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-/* Find SELP, SELI, and SELR values for raw M value, max M = MVALMAX */
-static void pllFindSel(uint32_t M, uint32_t *pSelP, uint32_t *pSelI, uint32_t *pSelR);
-/* Get predivider (N) from PLL0 NDEC setting */
-static uint32_t findPll0PreDiv(void);
-/* Get predivider (N) from PLL1 NDEC setting */
-static uint32_t findPll1PreDiv(void);
-/* Get postdivider (P) from PLL0 PDEC setting */
-static uint32_t findPll0PostDiv(void);
-/* Get multiplier (M) from PLL0 MDEC and SSCG settings */
-static float findPll0MMult(void);
-/* Get the greatest common divisor */
-static uint32_t FindGreatestCommonDivisor(uint32_t m, uint32_t n);
-/* Set PLL output based on desired output rate */
-static pll_error_t CLOCK_GetPll0Config(uint32_t finHz, uint32_t foutHz, pll_setup_t *pSetup, bool useSS);
-/* Update local PLL rate variable */
-static void CLOCK_GetPLL0OutFromSetupUpdate(pll_setup_t *pSetup);
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-/* Clock Selection for IP */
-/**
- * brief Configure the clock selection muxes.
- * param connection : Clock to be configured.
- * return Nothing
- */
-void CLOCK_AttachClk(clock_attach_id_t connection)
-{
- uint8_t mux;
- uint8_t sel;
- uint16_t item;
- uint32_t tmp32 = (uint32_t)connection;
- uint32_t i;
- volatile uint32_t *pClkSel;
-
- pClkSel = &(SYSCON->SYSTICKCLKSELX[0]);
-
- if (kNONE_to_NONE != connection)
- {
- for (i = 0U; i < 2U; i++)
- {
- if (tmp32 == 0U)
- {
- break;
- }
- item = (uint16_t)GET_ID_ITEM(tmp32);
- if (item != 0U)
- {
- mux = GET_ID_ITEM_MUX(item);
- sel = GET_ID_ITEM_SEL(item);
- if (mux == CM_RTCOSC32KCLKSEL)
- {
- PMC->RTCOSC32K |= sel;
- }
- else
- {
- pClkSel[mux] = sel;
- }
- }
- tmp32 = GET_ID_NEXT_ITEM(tmp32); /* pick up next descriptor */
- }
- }
-}
-
-/* Return the actual clock attach id */
-/**
- * brief Get the actual clock attach id.
- * This fuction uses the offset in input attach id, then it reads the actual source value in
- * the register and combine the offset to obtain an actual attach id.
- * param attachId : Clock attach id to get.
- * return Clock source value.
- */
-clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId)
-{
- uint8_t mux;
- uint8_t actualSel;
- uint32_t tmp32 = (uint32_t)attachId;
- uint32_t i;
- uint32_t actualAttachId = 0U;
- uint32_t selector = GET_ID_SELECTOR(tmp32);
- volatile uint32_t *pClkSel;
-
- pClkSel = &(SYSCON->SYSTICKCLKSELX[0]);
-
- if (kNONE_to_NONE == attachId)
- {
- return kNONE_to_NONE;
- }
-
- for (i = 0U; i < 2U; i++)
- {
- mux = GET_ID_ITEM_MUX(tmp32);
- if (tmp32 != 0UL)
- {
- if (mux == CM_RTCOSC32KCLKSEL)
- {
- actualSel = (uint8_t)(PMC->RTCOSC32K);
- }
- else
- {
- actualSel = (uint8_t)(pClkSel[mux]);
- }
-
- /* Consider the combination of two registers */
- actualAttachId |= CLK_ATTACH_ID(mux, actualSel, i);
- }
- tmp32 = GET_ID_NEXT_ITEM(tmp32); /*!< pick up next descriptor */
- }
-
- actualAttachId |= selector;
-
- return (clock_attach_id_t)actualAttachId;
-}
-
-/* Set IP Clock Divider */
-/**
- * brief Setup peripheral clock dividers.
- * param div_name : Clock divider name
- * param divided_by_value: Value to be divided
- * param reset : Whether to reset the divider counter.
- * return Nothing
- */
-void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset)
-{
- volatile uint32_t *pClkDiv;
-
- pClkDiv = &(SYSCON->SYSTICKCLKDIV0);
- if (reset)
- {
- pClkDiv[(uint8_t)div_name] = 1UL << 29U;
- }
- if (divided_by_value == 0U) /*!< halt */
- {
- pClkDiv[(uint8_t)div_name] = 1UL << 30U;
- }
- else
- {
- pClkDiv[(uint8_t)div_name] = (divided_by_value - 1U);
- }
-}
-
-/* Set RTC 1KHz Clock Divider */
-/**
- * brief Setup rtc 1khz clock divider.
- * param divided_by_value: Value to be divided
- * return Nothing
- */
-void CLOCK_SetRtc1khzClkDiv(uint32_t divided_by_value)
-{
- PMC->RTCOSC32K |= (((divided_by_value - 28U) << PMC_RTCOSC32K_CLK1KHZDIV_SHIFT) | PMC_RTCOSC32K_CLK1KHZDIV_MASK);
-}
-
-/* Set RTC 1KHz Clock Divider */
-/**
- * brief Setup rtc 1hz clock divider.
- * param divided_by_value: Value to be divided
- * return Nothing
- */
-void CLOCK_SetRtc1hzClkDiv(uint32_t divided_by_value)
-{
- if (divided_by_value == 0U) /*!< halt */
- {
- PMC->RTCOSC32K |= (1UL << PMC_RTCOSC32K_CLK1HZDIVHALT_SHIFT);
- }
- else
- {
- PMC->RTCOSC32K |=
- (((divided_by_value - 31744U) << PMC_RTCOSC32K_CLK1HZDIV_SHIFT) | PMC_RTCOSC32K_CLK1HZDIV_MASK);
- }
-}
-
-/* Set FRO Clocking */
-/**
- * brief Initialize the Core clock to given frequency (12, 48 or 96 MHz).
- * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed output is
- * enabled.
- * param iFreq : Desired frequency (must be one of #CLK_FRO_12MHZ or #CLK_FRO_48MHZ or #CLK_FRO_96MHZ)
- * return returns success or fail status.
- */
-status_t CLOCK_SetupFROClocking(uint32_t iFreq)
-{
- if ((iFreq != 12000000U) && (iFreq != 48000000U) && (iFreq != 96000000U))
- {
- return kStatus_Fail;
- }
- /* Enable Analog Control module */
- SYSCON->PRESETCTRLCLR[2] = (1UL << SYSCON_PRESETCTRL2_ANALOG_CTRL_RST_SHIFT);
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_ANALOG_CTRL_MASK;
- /* Power up the FRO192M */
- POWER_DisablePD(kPDRUNCFG_PD_FRO192M);
-
- if (iFreq == 96000000U)
- {
- ANACTRL->FRO192M_CTRL |= ANACTRL_FRO192M_CTRL_ENA_96MHZCLK(1);
- }
- /* always enable
- else if (iFreq == 48000000U)
- {
- ANACTRL->FRO192M_CTRL |= ANACTRL_FRO192M_CTRL_ENA_48MHZCLK(1);
- }*/
- else
- {
- ANACTRL->FRO192M_CTRL |= ANACTRL_FRO192M_CTRL_ENA_12MHZCLK(1);
- }
- return kStatus_Success;
-}
-
-/* Set the FLASH wait states for the passed frequency */
-/**
- * brief Set the flash wait states for the input freuqency.
- * param iFreq: Input frequency
- * return Nothing
- */
-void CLOCK_SetFLASHAccessCyclesForFreq(uint32_t iFreq)
-{
- uint32_t num_wait_states; /* Flash Controller & FMC internal number of Wait States (minus 1) */
-
- if (iFreq <= 11000000UL)
- {
- /* [0 - 11 MHz] */
- num_wait_states = 0UL;
- }
- else if (iFreq <= 22000000UL)
- {
- /* [11 MHz - 22 MHz] */
- num_wait_states = 1UL;
- }
- else if (iFreq <= 33000000UL)
- {
- /* [22 MHz - 33 MHz] */
- num_wait_states = 2UL;
- }
- else if (iFreq <= 44000000UL)
- {
- /* [33 MHz - 44 MHz] */
- num_wait_states = 3UL;
- }
- else if (iFreq <= 55000000UL)
- {
- /* [44 MHz - 55 MHz] */
- num_wait_states = 4UL;
- }
- else if (iFreq <= 66000000UL)
- {
- /* [55 MHz - 662 MHz] */
- num_wait_states = 5UL;
- }
- else if (iFreq <= 77000000UL)
- {
- /* [66 MHz - 77 MHz] */
- num_wait_states = 6UL;
- }
- else if (iFreq <= 88000000UL)
- {
- /* [77 MHz - 88 MHz] */
- num_wait_states = 7UL;
- }
- else if (iFreq <= 100000000UL)
- {
- /* [88 MHz - 100 MHz] */
- num_wait_states = 8UL;
- }
- else if (iFreq <= 115000000UL)
- {
- /* [100 MHz - 115 MHz] */
- num_wait_states = 9UL;
- }
- else if (iFreq <= 130000000UL)
- {
- /* [115 MHz - 130 MHz] */
- num_wait_states = 10UL;
- }
- else if (iFreq <= 150000000UL)
- {
- /* [130 MHz - 150 MHz] */
- num_wait_states = 11UL;
- }
- else
- {
- /* Above 150 MHz */
- num_wait_states = 12UL;
- }
-
- FLASH->INT_CLR_STATUS = 0x1FUL; /* Clear all status flags */
-
- FLASH->DATAW[0] = (FLASH->DATAW[0] & 0xFFFFFFF0UL) |
- (num_wait_states & (SYSCON_FMCCR_FLASHTIM_MASK >> SYSCON_FMCCR_FLASHTIM_SHIFT));
-
- FLASH->CMD = 0x2; /* CMD_SET_READ_MODE */
-
- /* Wait until the cmd is completed (without error) */
- while (0UL == (FLASH->INT_STATUS & FLASH_INT_STATUS_DONE_MASK))
- {
- ;
- }
-
- /* Adjust FMC waiting time cycles (num_wait_states) */
- SYSCON->FMCCR = (SYSCON->FMCCR & ~SYSCON_FMCCR_FLASHTIM_MASK) |
- ((num_wait_states << SYSCON_FMCCR_FLASHTIM_SHIFT) & SYSCON_FMCCR_FLASHTIM_MASK);
-}
-
-/* Set EXT OSC Clk */
-/**
- * brief Initialize the external osc clock to given frequency.
- * param iFreq : Desired frequency (must be equal to exact rate in Hz)
- * return returns success or fail status.
- */
-status_t CLOCK_SetupExtClocking(uint32_t iFreq)
-{
- if (iFreq >= 32000000U)
- {
- return kStatus_Fail;
- }
- /* Turn on power for crystal 32 MHz */
- POWER_DisablePD(kPDRUNCFG_PD_XTAL32M);
- POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M);
- /* Enable clock_in clock for clock module. */
- SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK;
-
- s_Ext_Clk_Freq = iFreq;
- return kStatus_Success;
-}
-
-/* Set I2S MCLK Clk */
-/**
- * brief Initialize the I2S MCLK clock to given frequency.
- * param iFreq : Desired frequency (must be equal to exact rate in Hz)
- * return returns success or fail status.
- */
-status_t CLOCK_SetupI2SMClkClocking(uint32_t iFreq)
-{
- s_I2S_Mclk_Freq = iFreq;
- return kStatus_Success;
-}
-
-/* Set PLU CLKIN Clk */
-/**
- * brief Initialize the PLU CLKIN clock to given frequency.
- * param iFreq : Desired frequency (must be equal to exact rate in Hz)
- * return returns success or fail status.
- */
-status_t CLOCK_SetupPLUClkInClocking(uint32_t iFreq)
-{
- s_PLU_ClkIn_Freq = iFreq;
- return kStatus_Success;
-}
-
-/* Get CLOCK OUT Clk */
-/*! brief Return Frequency of ClockOut
- * return Frequency of ClockOut
- */
-uint32_t CLOCK_GetClockOutClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->CLKOUTSEL)
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
-
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
-
- case 2U:
- freq = CLOCK_GetExtClkFreq();
- break;
-
- case 3U:
- freq = CLOCK_GetFroHfFreq();
- break;
-
- case 4U:
- freq = CLOCK_GetFro1MFreq();
- break;
-
- case 5U:
- freq = CLOCK_GetPll1OutFreq();
- break;
-
- case 6U:
- freq = CLOCK_GetOsc32KFreq();
- break;
-
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
- return freq / ((SYSCON->CLKOUTDIV & 0xffU) + 1U);
-}
-
-/* Get ADC Clk */
-/*! brief Return Frequency of Adc Clock
- * return Frequency of Adc.
- */
-uint32_t CLOCK_GetAdcClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->ADCCLKSEL)
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 2U:
- freq = CLOCK_GetFroHfFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq / ((SYSCON->ADCCLKDIV & SYSCON_ADCCLKDIV_DIV_MASK) + 1U);
-}
-
-/* Get USB0 Clk */
-/*! brief Return Frequency of Usb0 Clock
- * return Frequency of Usb0 Clock.
- */
-uint32_t CLOCK_GetUsb0ClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->USB0CLKSEL)
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 3U:
- freq = CLOCK_GetFroHfFreq();
- break;
- case 5U:
- freq = CLOCK_GetPll1OutFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq / ((SYSCON->USB0CLKDIV & 0xffU) + 1U);
-}
-
-/* Get USB1 Clk */
-/*! brief Return Frequency of Usb1 Clock
- * return Frequency of Usb1 Clock.
- */
-uint32_t CLOCK_GetUsb1ClkFreq(void)
-{
- return ((ANACTRL->XO32M_CTRL & ANACTRL_XO32M_CTRL_ENABLE_PLL_USB_OUT_MASK) != 0UL) ? s_Ext_Clk_Freq : 0U;
-}
-
-/* Get MCLK Clk */
-/*! brief Return Frequency of MClk Clock
- * return Frequency of MClk Clock.
- */
-uint32_t CLOCK_GetMclkClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->MCLKCLKSEL)
- {
- case 0U:
- freq = CLOCK_GetFroHfFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq / ((SYSCON->MCLKDIV & 0xffU) + 1U);
-}
-
-/* Get SCTIMER Clk */
-/*! brief Return Frequency of SCTimer Clock
- * return Frequency of SCTimer Clock.
- */
-uint32_t CLOCK_GetSctClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->SCTCLKSEL)
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 2U:
- freq = CLOCK_GetExtClkFreq();
- break;
- case 3U:
- freq = CLOCK_GetFroHfFreq();
- break;
- case 5U:
- freq = CLOCK_GetI2SMClkFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq / ((SYSCON->SCTCLKDIV & 0xffU) + 1U);
-}
-
-/* Get SDIO Clk */
-/*! brief Return Frequency of SDIO Clock
- * return Frequency of SDIO Clock.
- */
-uint32_t CLOCK_GetSdioClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->SDIOCLKSEL)
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 3U:
- freq = CLOCK_GetFroHfFreq();
- break;
- case 5U:
- freq = CLOCK_GetPll1OutFreq();
- break;
- case 7U:
- freq = 0U;
- break;
- default:
- assert(false);
- break;
- }
-
- return freq / ((SYSCON->SDIOCLKDIV & 0xffU) + 1U);
-}
-
-/* Get FRO 12M Clk */
-/*! brief Return Frequency of FRO 12MHz
- * return Frequency of FRO 12MHz
- */
-uint32_t CLOCK_GetFro12MFreq(void)
-{
- return ((ANACTRL->FRO192M_CTRL & ANACTRL_FRO192M_CTRL_ENA_12MHZCLK_MASK) != 0UL) ? 12000000U : 0U;
-}
-
-/* Get FRO 1M Clk */
-/*! brief Return Frequency of FRO 1MHz
- * return Frequency of FRO 1MHz
- */
-uint32_t CLOCK_GetFro1MFreq(void)
-{
- return ((SYSCON->CLOCK_CTRL & SYSCON_CLOCK_CTRL_FRO1MHZ_CLK_ENA_MASK) != 0UL) ? 1000000U : 0U;
-}
-
-/* Get EXT OSC Clk */
-/*! brief Return Frequency of External Clock
- * return Frequency of External Clock. If no external clock is used returns 0.
- */
-uint32_t CLOCK_GetExtClkFreq(void)
-{
- return ((ANACTRL->XO32M_CTRL & ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK) != 0UL) ? s_Ext_Clk_Freq : 0U;
-}
-
-/* Get WATCH DOG Clk */
-/*! brief Return Frequency of Watchdog
- * return Frequency of Watchdog
- */
-uint32_t CLOCK_GetWdtClkFreq(void)
-{
- return CLOCK_GetFro1MFreq() / ((SYSCON->WDTCLKDIV & SYSCON_WDTCLKDIV_DIV_MASK) + 1U);
-}
-
-/* Get HF FRO Clk */
-/*! brief Return Frequency of High-Freq output of FRO
- * return Frequency of High-Freq output of FRO
- */
-uint32_t CLOCK_GetFroHfFreq(void)
-{
- return ((ANACTRL->FRO192M_CTRL & ANACTRL_FRO192M_CTRL_ENA_96MHZCLK_MASK) != 0UL) ? 96000000U : 0U;
-}
-
-/* Get SYSTEM PLL Clk */
-/*! brief Return Frequency of PLL
- * return Frequency of PLL
- */
-uint32_t CLOCK_GetPll0OutFreq(void)
-{
- return s_Pll0_Freq;
-}
-
-/* Get USB PLL Clk */
-/*! brief Return Frequency of USB PLL
- * return Frequency of PLL
- */
-uint32_t CLOCK_GetPll1OutFreq(void)
-{
- return s_Pll1_Freq;
-}
-
-/* Get RTC OSC Clk */
-/*! brief Return Frequency of 32kHz osc
- * return Frequency of 32kHz osc
- */
-uint32_t CLOCK_GetOsc32KFreq(void)
-{
- return ((0UL == (PMC->PDRUNCFG0 & PMC_PDRUNCFG0_PDEN_FRO32K_MASK)) &&
- (0UL == (PMC->RTCOSC32K & PMC_RTCOSC32K_SEL_MASK))) ?
- CLK_RTC_32K_CLK :
- ((0UL == (PMC->PDRUNCFG0 & PMC_PDRUNCFG0_PDEN_XTAL32K_MASK)) &&
- (0UL != (PMC->RTCOSC32K & PMC_RTCOSC32K_SEL_MASK))) ?
- CLK_RTC_32K_CLK :
- 0U;
-}
-
-/* Get MAIN Clk */
-/*! brief Return Frequency of Core System
- * return Frequency of Core System
- */
-uint32_t CLOCK_GetCoreSysClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->MAINCLKSELB)
- {
- case 0U:
- if (SYSCON->MAINCLKSELA == 0U)
- {
- freq = CLOCK_GetFro12MFreq();
- }
- else if (SYSCON->MAINCLKSELA == 1U)
- {
- freq = CLOCK_GetExtClkFreq();
- }
- else if (SYSCON->MAINCLKSELA == 2U)
- {
- freq = CLOCK_GetFro1MFreq();
- }
- else if (SYSCON->MAINCLKSELA == 3U)
- {
- freq = CLOCK_GetFroHfFreq();
- }
- else
- {
- /* Add comments to prevent the case of MISRA C-2012 rule 15.7. */
- }
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 2U:
- freq = CLOCK_GetPll1OutFreq();
- break;
-
- case 3U:
- freq = CLOCK_GetOsc32KFreq();
- break;
-
- default:
- freq = 0U;
- break;
- }
-
- return freq;
-}
-
-/* Get I2S MCLK Clk */
-/*! brief Return Frequency of I2S MCLK Clock
- * return Frequency of I2S MCLK Clock
- */
-uint32_t CLOCK_GetI2SMClkFreq(void)
-{
- return s_I2S_Mclk_Freq;
-}
-
-/* Get PLU CLKIN Clk */
-/*! brief Return Frequency of PLU CLKIN Clock
- * return Frequency of PLU CLKIN Clock
- */
-uint32_t CLOCK_GetPLUClkInFreq(void)
-{
- return s_PLU_ClkIn_Freq;
-}
-
-/* Get FLEXCOMM input clock */
-/*! brief Return Frequency of flexcomm input clock
- * param id : flexcomm instance id
- * return Frequency value
- */
-uint32_t CLOCK_GetFlexCommInputClock(uint32_t id)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->FCCLKSELX[id])
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq() / ((SYSCON->PLL0CLKDIV & 0xffU) + 1U);
- break;
- case 2U:
- freq = CLOCK_GetFro12MFreq();
- break;
- case 3U:
- freq = CLOCK_GetFroHfFreq() / ((SYSCON->FROHFDIV & 0xffU) + 1U);
- break;
- case 4U:
- freq = CLOCK_GetFro1MFreq();
- break;
- case 5U:
- freq = CLOCK_GetI2SMClkFreq();
- break;
- case 6U:
- freq = CLOCK_GetOsc32KFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq;
-}
-
-/* Get FLEXCOMM Clk */
-uint32_t CLOCK_GetFlexCommClkFreq(uint32_t id)
-{
- uint32_t freq = 0U;
- uint32_t temp;
-
- freq = CLOCK_GetFlexCommInputClock(id);
- temp = SYSCON->FLEXFRGXCTRL[id] & SYSCON_FLEXFRG0CTRL_MULT_MASK;
- return freq / (1U + (temp) / ((SYSCON->FLEXFRGXCTRL[id] & SYSCON_FLEXFRG0CTRL_DIV_MASK) + 1U));
-}
-
-/* Get HS_LPSI Clk */
-uint32_t CLOCK_GetHsLspiClkFreq(void)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->HSLSPICLKSEL)
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq() / ((SYSCON->PLL0CLKDIV & 0xffU) + 1U);
- break;
- case 2U:
- freq = CLOCK_GetFro12MFreq();
- break;
- case 3U:
- freq = CLOCK_GetFroHfFreq() / ((SYSCON->FROHFDIV & 0xffU) + 1U);
- break;
- case 4U:
- freq = CLOCK_GetFro1MFreq();
- break;
- case 6U:
- freq = CLOCK_GetOsc32KFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq;
-}
-
-/* Get CTimer Clk */
-/*! brief Return Frequency of CTimer functional Clock
- * return Frequency of CTimer functional Clock
- */
-uint32_t CLOCK_GetCTimerClkFreq(uint32_t id)
-{
- uint32_t freq = 0U;
-
- switch (SYSCON->CTIMERCLKSELX[id])
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case 1U:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case 3U:
- freq = CLOCK_GetFroHfFreq();
- break;
- case 4U:
- freq = CLOCK_GetFro1MFreq();
- break;
- case 5U:
- freq = CLOCK_GetI2SMClkFreq();
- break;
- case 6U:
- freq = CLOCK_GetOsc32KFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- assert(false);
- break;
- }
-
- return freq;
-}
-
-/* Get Systick Clk */
-/*! brief Return Frequency of SystickClock
- * return Frequency of Systick Clock
- */
-uint32_t CLOCK_GetSystickClkFreq(uint32_t id)
-{
- volatile uint32_t *pSystickClkDiv;
- pSystickClkDiv = &(SYSCON->SYSTICKCLKDIV0);
- uint32_t freq = 0U;
-
- switch (SYSCON->SYSTICKCLKSELX[id])
- {
- case 0U:
- freq = CLOCK_GetCoreSysClkFreq() / ((pSystickClkDiv[id] & 0xffU) + 1U);
- break;
- case 1U:
- freq = CLOCK_GetFro1MFreq();
- break;
- case 2U:
- freq = CLOCK_GetOsc32KFreq();
- break;
- case 7U:
- freq = 0U;
- break;
-
- default:
- freq = 0U;
- break;
- }
-
- return freq;
-}
-
-/* Set FlexComm Clock */
-/**
- * brief Set the flexcomm output frequency.
- * param id : flexcomm instance id
- * freq : output frequency
- * return 0 : the frequency range is out of range.
- * 1 : switch successfully.
- */
-uint32_t CLOCK_SetFlexCommClock(uint32_t id, uint32_t freq)
-{
- uint32_t input = CLOCK_GetFlexCommClkFreq(id);
- uint32_t mul;
-
- if ((freq > 48000000UL) || (freq > input) || (input / freq >= 2UL))
- {
- /* FRG output frequency should be less than equal to 48MHz */
- return 0UL;
- }
- else
- {
- mul = (uint32_t)((((uint64_t)input - freq) * 256ULL) / ((uint64_t)freq));
- SYSCON->FLEXFRGXCTRL[id] = (mul << 8U) | 0xFFU;
- return 1UL;
- }
-}
-
-/* Get IP Clk */
-/*! brief Return Frequency of selected clock
- * return Frequency of selected clock
- */
-uint32_t CLOCK_GetFreq(clock_name_t clockName)
-{
- uint32_t freq;
- switch (clockName)
- {
- case kCLOCK_CoreSysClk:
- freq = CLOCK_GetCoreSysClkFreq();
- break;
- case kCLOCK_BusClk:
- freq = CLOCK_GetCoreSysClkFreq() / ((SYSCON->AHBCLKDIV & 0xffU) + 1U);
- break;
- case kCLOCK_ClockOut:
- freq = CLOCK_GetClockOutClkFreq();
- break;
- case kCLOCK_Pll1Out:
- freq = CLOCK_GetPll1OutFreq();
- break;
- case kCLOCK_Mclk:
- freq = CLOCK_GetMclkClkFreq();
- break;
- case kCLOCK_FroHf:
- freq = CLOCK_GetFroHfFreq();
- break;
- case kCLOCK_Fro12M:
- freq = CLOCK_GetFro12MFreq();
- break;
- case kCLOCK_ExtClk:
- freq = CLOCK_GetExtClkFreq();
- break;
- case kCLOCK_Pll0Out:
- freq = CLOCK_GetPll0OutFreq();
- break;
- case kCLOCK_FlexI2S:
- freq = CLOCK_GetI2SMClkFreq();
- break;
- default:
- freq = 0U;
- break;
- }
- return freq;
-}
-
-/* Find SELP, SELI, and SELR values for raw M value, max M = MVALMAX */
-static void pllFindSel(uint32_t M, uint32_t *pSelP, uint32_t *pSelI, uint32_t *pSelR)
-{
- uint32_t seli, selp;
- /* bandwidth: compute selP from Multiplier */
- if ((SYSCON->PLL0SSCG1 & SYSCON_PLL0SSCG1_MDIV_EXT_MASK) != 0UL) /* normal mode */
- {
- selp = (M >> 2U) + 1U;
- if (selp >= 31U)
- {
- selp = 31U;
- }
- *pSelP = selp;
-
- if (M >= 8000UL)
- {
- seli = 1UL;
- }
- else if (M >= 122UL)
- {
- seli = (uint32_t)(8000UL / M); /*floor(8000/M) */
- }
- else
- {
- seli = 2UL * ((uint32_t)(M / 4UL)) + 3UL; /* 2*floor(M/4) + 3 */
- }
-
- if (seli >= 63UL)
- {
- seli = 63UL;
- }
- *pSelI = seli;
-
- *pSelR = 0U;
- }
- else
- {
- /* Note: If the spread spectrum mode, choose N to ensure 3 MHz < Fin/N < 5 MHz */
- *pSelP = 3U;
- *pSelI = 4U;
- *pSelR = 4U;
- }
-}
-
-/* Get predivider (N) from PLL0 NDEC setting */
-static uint32_t findPll0PreDiv(void)
-{
- uint32_t preDiv = 1UL;
-
- /* Direct input is not used? */
- if ((SYSCON->PLL0CTRL & SYSCON_PLL0CTRL_BYPASSPREDIV_MASK) == 0UL)
- {
- preDiv = SYSCON->PLL0NDEC & SYSCON_PLL0NDEC_NDIV_MASK;
- if (preDiv == 0UL)
- {
- preDiv = 1UL;
- }
- }
- return preDiv;
-}
-
-/* Get predivider (N) from PLL1 NDEC setting */
-static uint32_t findPll1PreDiv(void)
-{
- uint32_t preDiv = 1UL;
-
- /* Direct input is not used? */
- if ((SYSCON->PLL1CTRL & SYSCON_PLL1CTRL_BYPASSPREDIV_MASK) == 0UL)
- {
- preDiv = SYSCON->PLL1NDEC & SYSCON_PLL1NDEC_NDIV_MASK;
- if (preDiv == 0UL)
- {
- preDiv = 1UL;
- }
- }
- return preDiv;
-}
-
-/* Get postdivider (P) from PLL0 PDEC setting */
-static uint32_t findPll0PostDiv(void)
-{
- uint32_t postDiv = 1UL;
-
- if ((SYSCON->PLL0CTRL & SYSCON_PLL0CTRL_BYPASSPOSTDIV_MASK) == 0UL)
- {
- if ((SYSCON->PLL0CTRL & SYSCON_PLL0CTRL_BYPASSPOSTDIV2_MASK) != 0UL)
- {
- postDiv = SYSCON->PLL0PDEC & SYSCON_PLL0PDEC_PDIV_MASK;
- }
- else
- {
- postDiv = 2UL * (SYSCON->PLL0PDEC & SYSCON_PLL0PDEC_PDIV_MASK);
- }
- if (postDiv == 0UL)
- {
- postDiv = 2UL;
- }
- }
- return postDiv;
-}
-
-/* Get multiplier (M) from PLL0 SSCG and SEL_EXT settings */
-static float findPll0MMult(void)
-{
- float mMult = 1.0F;
- float mMult_fract;
- uint32_t mMult_int;
-
- if ((SYSCON->PLL0SSCG1 & SYSCON_PLL0SSCG1_SEL_EXT_MASK) != 0UL)
- {
- mMult =
- (float)(uint32_t)((SYSCON->PLL0SSCG1 & SYSCON_PLL0SSCG1_MDIV_EXT_MASK) >> SYSCON_PLL0SSCG1_MDIV_EXT_SHIFT);
- }
- else
- {
- mMult_int = ((SYSCON->PLL0SSCG1 & SYSCON_PLL0SSCG1_MD_MBS_MASK) << 7U);
- mMult_int = mMult_int | ((SYSCON->PLL0SSCG0) >> PLL0_SSCG_MD_INT_P);
- mMult_fract = ((float)(uint32_t)((SYSCON->PLL0SSCG0) & PLL0_SSCG_MD_FRACT_M) /
- (float)(uint32_t)(1UL << PLL0_SSCG_MD_INT_P));
- mMult = (float)mMult_int + mMult_fract;
- }
- if (mMult == 0.0F)
- {
- mMult = 1.0F;
- }
- return mMult;
-}
-
-/* Find greatest common divisor between m and n */
-static uint32_t FindGreatestCommonDivisor(uint32_t m, uint32_t n)
-{
- uint32_t tmp;
-
- while (n != 0U)
- {
- tmp = n;
- n = m % n;
- m = tmp;
- }
-
- return m;
-}
-
-/*
- * Set PLL0 output based on desired output rate.
- * In this function, the it calculates the PLL0 setting for output frequency from input clock
- * frequency. The calculation would cost a few time. So it is not recommaned to use it frequently.
- * the "pllctrl", "pllndec", "pllpdec", "pllmdec" would updated in this function.
- */
-static pll_error_t CLOCK_GetPll0ConfigInternal(uint32_t finHz, uint32_t foutHz, pll_setup_t *pSetup, bool useSS)
-{
- uint32_t nDivOutHz, fccoHz;
- uint32_t pllPreDivider, pllMultiplier, pllPostDivider;
- uint32_t pllDirectInput, pllDirectOutput;
- uint32_t pllSelP, pllSelI, pllSelR, uplimoff;
-
- /* Baseline parameters (no input or output dividers) */
- pllPreDivider = 1U; /* 1 implies pre-divider will be disabled */
- pllPostDivider = 1U; /* 1 implies post-divider will be disabled */
- pllDirectOutput = 1U;
-
- /* Verify output rate parameter */
- if (foutHz > PLL_MAX_CCO_FREQ_MHZ)
- {
- /* Maximum PLL output with post divider=1 cannot go above this frequency */
- return kStatus_PLL_OutputTooHigh;
- }
- if (foutHz < (PLL_MIN_CCO_FREQ_MHZ / (PVALMAX << 1U)))
- {
- /* Minmum PLL output with maximum post divider cannot go below this frequency */
- return kStatus_PLL_OutputTooLow;
- }
-
- /* If using SS mode, input clock needs to be between 3MHz and 20MHz */
- if (useSS)
- {
- /* Verify input rate parameter */
- if (finHz < PLL_MIN_IN_SSMODE)
- {
- /* Input clock into the PLL cannot be lower than this */
- return kStatus_PLL_InputTooLow;
- }
- /* PLL input in SS mode must be under 20MHz */
- if (finHz > (PLL_MAX_IN_SSMODE * NVALMAX))
- {
- return kStatus_PLL_InputTooHigh;
- }
- }
- else
- {
- /* Verify input rate parameter */
- if (finHz < PLL_LOWER_IN_LIMIT)
- {
- /* Input clock into the PLL cannot be lower than this */
- return kStatus_PLL_InputTooLow;
- }
- if (finHz > PLL_HIGHER_IN_LIMIT)
- {
- /* Input clock into the PLL cannot be higher than this */
- return kStatus_PLL_InputTooHigh;
- }
- }
-
- /* Find the optimal CCO frequency for the output and input that
- will keep it inside the PLL CCO range. This may require
- tweaking the post-divider for the PLL. */
- fccoHz = foutHz;
- while (fccoHz < PLL_MIN_CCO_FREQ_MHZ)
- {
- /* CCO output is less than minimum CCO range, so the CCO output
- needs to be bumped up and the post-divider is used to bring
- the PLL output back down. */
- pllPostDivider++;
- if (pllPostDivider > PVALMAX)
- {
- return kStatus_PLL_OutsideIntLimit;
- }
-
- /* Target CCO goes up, PLL output goes down */
- /* divide-by-2 divider in the post-divider is always work*/
- fccoHz = foutHz * (pllPostDivider * 2U);
- pllDirectOutput = 0U;
- }
-
- /* Determine if a pre-divider is needed to get the best frequency */
- if ((finHz > PLL_LOWER_IN_LIMIT) && (fccoHz >= finHz) && (useSS == false))
- {
- uint32_t a = FindGreatestCommonDivisor(fccoHz, finHz);
-
- if (a > PLL_LOWER_IN_LIMIT)
- {
- a = finHz / a;
- if ((a != 0U) && (a < PLL_MAX_N_DIV))
- {
- pllPreDivider = a;
- }
- }
- }
-
- /* Bypass pre-divider hardware if pre-divider is 1 */
- if (pllPreDivider > 1U)
- {
- pllDirectInput = 0U;
- }
- else
- {
- pllDirectInput = 1U;
- }
-
- /* Determine PLL multipler */
- nDivOutHz = (finHz / pllPreDivider);
- pllMultiplier = (fccoHz / nDivOutHz);
-
- /* Find optimal values for filter */
- if (useSS == false)
- {
- /* Will bumping up M by 1 get us closer to the desired CCO frequency? */
- if ((nDivOutHz * ((pllMultiplier * 2U) + 1U)) < (fccoHz * 2U))
- {
- pllMultiplier++;
- }
-
- /* Setup filtering */
- pllFindSel(pllMultiplier, &pllSelP, &pllSelI, &pllSelR);
- uplimoff = 0U;
-
- /* Get encoded value for M (mult) and use manual filter, disable SS mode */
- pSetup->pllsscg[1] =
- (uint32_t)((PLL_SSCG1_MDEC_VAL_SET(pllMultiplier)) | (1UL << SYSCON_PLL0SSCG1_SEL_EXT_SHIFT));
- }
- else
- {
- uint64_t fc;
-
- /* Filtering will be handled by SSC */
- pllSelR = 0U;
- pllSelI = 0U;
- pllSelP = 0U;
- uplimoff = 1U;
-
- /* The PLL multiplier will get very close and slightly under the
- desired target frequency. A small fractional component can be
- added to fine tune the frequency upwards to the target. */
- fc = (((uint64_t)fccoHz % (uint64_t)nDivOutHz) << 25U) / nDivOutHz;
-
- /* Set multiplier */
- pSetup->pllsscg[0] = (uint32_t)(PLL0_SSCG_MD_INT_SET(pllMultiplier) | PLL0_SSCG_MD_FRACT_SET((uint32_t)fc));
- pSetup->pllsscg[1] = (uint32_t)(PLL0_SSCG_MD_INT_SET(pllMultiplier) >> 32U);
- }
-
- /* Get encoded values for N (prediv) and P (postdiv) */
- pSetup->pllndec = PLL_NDEC_VAL_SET(pllPreDivider);
- pSetup->pllpdec = PLL_PDEC_VAL_SET(pllPostDivider);
-
- /* PLL control */
- pSetup->pllctrl = (pllSelR << SYSCON_PLL0CTRL_SELR_SHIFT) | /* Filter coefficient */
- (pllSelI << SYSCON_PLL0CTRL_SELI_SHIFT) | /* Filter coefficient */
- (pllSelP << SYSCON_PLL0CTRL_SELP_SHIFT) | /* Filter coefficient */
- (0UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT) | /* PLL bypass mode disabled */
- (uplimoff << SYSCON_PLL0CTRL_LIMUPOFF_SHIFT) | /* SS/fractional mode disabled */
- (pllDirectInput << SYSCON_PLL0CTRL_BYPASSPREDIV_SHIFT) | /* Bypass pre-divider? */
- (pllDirectOutput << SYSCON_PLL0CTRL_BYPASSPOSTDIV_SHIFT) | /* Bypass post-divider? */
- (1UL << SYSCON_PLL0CTRL_CLKEN_SHIFT); /* Ensure the PLL clock output */
-
- return kStatus_PLL_Success;
-}
-
-#if (defined(CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT) && CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT)
-/* Alloct the static buffer for cache. */
-static pll_setup_t s_PllSetupCacheStruct[CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT];
-static uint32_t s_FinHzCache[CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT] = {0};
-static uint32_t s_FoutHzCache[CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT] = {0};
-static bool s_UseSSCache[CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT] = {false};
-static uint32_t s_PllSetupCacheIdx = 0U;
-#endif /* CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT */
-
-/*
- * Calculate the PLL setting values from input clock freq to output freq.
- */
-static pll_error_t CLOCK_GetPll0Config(uint32_t finHz, uint32_t foutHz, pll_setup_t *pSetup, bool useSS)
-{
- pll_error_t retErr;
-#if (defined(CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT) && CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT)
- uint32_t i;
-
- for (i = 0U; i < CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT; i++)
- {
- if ((finHz == s_FinHzCache[i]) && (foutHz == s_FoutHzCache[i]) && (useSS == s_UseSSCache[i]))
- {
- /* Hit the target in cache buffer. */
- pSetup->pllctrl = s_PllSetupCacheStruct[i].pllctrl;
- pSetup->pllndec = s_PllSetupCacheStruct[i].pllndec;
- pSetup->pllpdec = s_PllSetupCacheStruct[i].pllpdec;
- pSetup->pllsscg[0] = s_PllSetupCacheStruct[i].pllsscg[0];
- pSetup->pllsscg[1] = s_PllSetupCacheStruct[i].pllsscg[1];
- retErr = kStatus_PLL_Success;
- break;
- }
- }
-
- if (i < CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT)
- {
- return retErr;
- }
-#endif /* CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT */
-
- retErr = CLOCK_GetPll0ConfigInternal(finHz, foutHz, pSetup, useSS);
-
-#if (defined(CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT) && CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT)
- /* Cache the most recent calulation result into buffer. */
- s_FinHzCache[s_PllSetupCacheIdx] = finHz;
- s_FoutHzCache[s_PllSetupCacheIdx] = foutHz;
- s_UseSSCache[s_PllSetupCacheIdx] = useSS;
-
- s_PllSetupCacheStruct[s_PllSetupCacheIdx].pllctrl = pSetup->pllctrl;
- s_PllSetupCacheStruct[s_PllSetupCacheIdx].pllndec = pSetup->pllndec;
- s_PllSetupCacheStruct[s_PllSetupCacheIdx].pllpdec = pSetup->pllpdec;
- s_PllSetupCacheStruct[s_PllSetupCacheIdx].pllsscg[0] = pSetup->pllsscg[0];
- s_PllSetupCacheStruct[s_PllSetupCacheIdx].pllsscg[1] = pSetup->pllsscg[1];
- /* Update the index for next available buffer. */
- s_PllSetupCacheIdx = (s_PllSetupCacheIdx + 1U) % CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT;
-#endif /* CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT */
-
- return retErr;
-}
-
-/* Update local PLL rate variable */
-static void CLOCK_GetPLL0OutFromSetupUpdate(pll_setup_t *pSetup)
-{
- s_Pll0_Freq = CLOCK_GetPLL0OutFromSetup(pSetup);
-}
-
-/* Return System PLL input clock rate */
-/*! brief Return PLL0 input clock rate
- * return PLL0 input clock rate
- */
-uint32_t CLOCK_GetPLL0InClockRate(void)
-{
- uint32_t clkRate = 0U;
-
- switch ((SYSCON->PLL0CLKSEL & SYSCON_PLL0CLKSEL_SEL_MASK))
- {
- case 0x00U:
- clkRate = CLK_FRO_12MHZ;
- break;
-
- case 0x01U:
- clkRate = CLOCK_GetExtClkFreq();
- break;
-
- case 0x02U:
- clkRate = CLOCK_GetFro1MFreq();
- break;
-
- case 0x03U:
- clkRate = CLOCK_GetOsc32KFreq();
- break;
-
- default:
- clkRate = 0U;
- break;
- }
-
- return clkRate;
-}
-
-/* Return PLL1 input clock rate */
-uint32_t CLOCK_GetPLL1InClockRate(void)
-{
- uint32_t clkRate = 0U;
-
- switch ((SYSCON->PLL1CLKSEL & SYSCON_PLL1CLKSEL_SEL_MASK))
- {
- case 0x00U:
- clkRate = CLK_FRO_12MHZ;
- break;
-
- case 0x01U:
- clkRate = CLOCK_GetExtClkFreq();
- break;
-
- case 0x02U:
- clkRate = CLOCK_GetFro1MFreq();
- break;
-
- case 0x03U:
- clkRate = CLOCK_GetOsc32KFreq();
- break;
-
- default:
- clkRate = 0U;
- break;
- }
-
- return clkRate;
-}
-
-/* Return PLL0 output clock rate from setup structure */
-/*! brief Return PLL0 output clock rate from setup structure
- * param pSetup : Pointer to a PLL setup structure
- * return PLL0 output clock rate the setup structure will generate
- */
-uint32_t CLOCK_GetPLL0OutFromSetup(pll_setup_t *pSetup)
-{
- uint32_t clkRate = 0;
- uint32_t prediv, postdiv;
- float workRate = 0.0F;
-
- /* Get the input clock frequency of PLL. */
- clkRate = CLOCK_GetPLL0InClockRate();
-
- if (((pSetup->pllctrl & SYSCON_PLL0CTRL_BYPASSPLL_MASK) == 0UL) &&
- ((pSetup->pllctrl & SYSCON_PLL0CTRL_CLKEN_MASK) != 0UL) &&
- ((PMC->PDRUNCFG0 & PMC_PDRUNCFG0_PDEN_PLL0_MASK) == 0UL) &&
- ((PMC->PDRUNCFG0 & PMC_PDRUNCFG0_PDEN_PLL0_SSCG_MASK) == 0UL))
- {
- prediv = findPll0PreDiv();
- postdiv = findPll0PostDiv();
- /* Adjust input clock */
- clkRate = clkRate / prediv;
- /* MDEC used for rate */
- workRate = (float)clkRate * (float)findPll0MMult();
- workRate /= (float)postdiv;
- }
-
- return (uint32_t)workRate;
-}
-
-/* Set the current PLL0 Rate */
-/*! brief Store the current PLL rate
- * param rate: Current rate of the PLL
- * return Nothing
- **/
-void CLOCK_SetStoredPLL0ClockRate(uint32_t rate)
-{
- s_Pll0_Freq = rate;
-}
-
-/* Return PLL0 output clock rate */
-/*! brief Return PLL0 output clock rate
- * param recompute : Forces a PLL rate recomputation if true
- * return PLL0 output clock rate
- * note The PLL rate is cached in the driver in a variable as
- * the rate computation function can take some time to perform. It
- * is recommended to use 'false' with the 'recompute' parameter.
- */
-uint32_t CLOCK_GetPLL0OutClockRate(bool recompute)
-{
- pll_setup_t Setup;
- uint32_t rate;
-
- if ((recompute) || (s_Pll0_Freq == 0U))
- {
- Setup.pllctrl = SYSCON->PLL0CTRL;
- Setup.pllndec = SYSCON->PLL0NDEC;
- Setup.pllpdec = SYSCON->PLL0PDEC;
- Setup.pllsscg[0] = SYSCON->PLL0SSCG0;
- Setup.pllsscg[1] = SYSCON->PLL0SSCG1;
-
- CLOCK_GetPLL0OutFromSetupUpdate(&Setup);
- }
-
- rate = s_Pll0_Freq;
-
- return rate;
-}
-
-/* Set PLL0 output based on the passed PLL setup data */
-/*! brief Set PLL output based on the passed PLL setup data
- * param pControl : Pointer to populated PLL control structure to generate setup with
- * param pSetup : Pointer to PLL setup structure to be filled
- * return PLL_ERROR_SUCCESS on success, or PLL setup error code
- * note Actual frequency for setup may vary from the desired frequency based on the
- * accuracy of input clocks, rounding, non-fractional PLL mode, etc.
- */
-pll_error_t CLOCK_SetupPLL0Data(pll_config_t *pControl, pll_setup_t *pSetup)
-{
- uint32_t inRate;
- bool useSS = ((pControl->flags & PLL_CONFIGFLAG_FORCENOFRACT) == 0U);
-
- pll_error_t pllError;
-
- /* Determine input rate for the PLL */
- if ((pControl->flags & PLL_CONFIGFLAG_USEINRATE) != 0U)
- {
- inRate = pControl->inputRate;
- }
- else
- {
- inRate = CLOCK_GetPLL0InClockRate();
- }
-
- /* PLL flag options */
- pllError = CLOCK_GetPll0Config(inRate, pControl->desiredRate, pSetup, useSS);
- if ((useSS) && (pllError == kStatus_PLL_Success))
- {
- /* If using SS mode, then some tweaks are made to the generated setup */
- pSetup->pllsscg[1] |= (uint32_t)pControl->ss_mf | (uint32_t)pControl->ss_mr | (uint32_t)pControl->ss_mc;
- if (pControl->mfDither)
- {
- pSetup->pllsscg[1] |= (1UL << SYSCON_PLL0SSCG1_DITHER_SHIFT);
- }
- }
-
- return pllError;
-}
-
-/* Set PLL0 output from PLL setup structure */
-/*! brief Set PLL output from PLL setup structure (precise frequency)
- * param pSetup : Pointer to populated PLL setup structure
- * param flagcfg : Flag configuration for PLL config structure
- * return PLL_ERROR_SUCCESS on success, or PLL setup error code
- * note This function will power off the PLL, setup the PLL with the
- * new setup data, and then optionally powerup the PLL, wait for PLL lock,
- * and adjust system voltages to the new PLL rate. The function will not
- * alter any source clocks (ie, main systen clock) that may use the PLL,
- * so these should be setup prior to and after exiting the function.
- */
-pll_error_t CLOCK_SetupPLL0Prec(pll_setup_t *pSetup, uint32_t flagcfg)
-{
- uint32_t inRate, clkRate, prediv;
-
- /* Power off PLL during setup changes */
- POWER_EnablePD(kPDRUNCFG_PD_PLL0);
- POWER_EnablePD(kPDRUNCFG_PD_PLL0_SSCG);
-
- pSetup->flags = flagcfg;
-
- /* Write PLL setup data */
- SYSCON->PLL0CTRL = pSetup->pllctrl;
- SYSCON->PLL0NDEC = pSetup->pllndec;
- SYSCON->PLL0NDEC = pSetup->pllndec | (1UL << SYSCON_PLL0NDEC_NREQ_SHIFT); /* latch */
- SYSCON->PLL0PDEC = pSetup->pllpdec;
- SYSCON->PLL0PDEC = pSetup->pllpdec | (1UL << SYSCON_PLL0PDEC_PREQ_SHIFT); /* latch */
- SYSCON->PLL0SSCG0 = pSetup->pllsscg[0];
- SYSCON->PLL0SSCG1 = pSetup->pllsscg[1];
- SYSCON->PLL0SSCG1 =
- pSetup->pllsscg[1] | (1UL << SYSCON_PLL0SSCG1_MREQ_SHIFT) | (1UL << SYSCON_PLL0SSCG1_MD_REQ_SHIFT); /* latch */
-
- POWER_DisablePD(kPDRUNCFG_PD_PLL0);
- POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
-
- if ((pSetup->flags & PLL_SETUPFLAG_WAITLOCK) != 0U)
- {
- if ((SYSCON->PLL0SSCG1 & SYSCON_PLL0SSCG1_MDIV_EXT_MASK) != 0UL) /* normal mode */
- {
- inRate = CLOCK_GetPLL0InClockRate();
- prediv = findPll0PreDiv();
- /* Adjust input clock */
- clkRate = inRate / prediv;
- /* The lock signal is only reliable between fref[2] :100 kHz to 20 MHz. */
- if ((clkRate >= 100000UL) && (clkRate <= 20000000UL))
- {
- while (CLOCK_IsPLL0Locked() == false)
- {
- }
- }
- else
- {
- SDK_DelayAtLeastUs(6000U,
- SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); /* software should use a 6 ms time interval
- to insure the PLL will be stable */
- }
- }
- else /* spread spectrum mode */
- {
- SDK_DelayAtLeastUs(6000U,
- SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); /* software should use a 6 ms time interval to
- insure the PLL will be stable */
- }
- }
-
- /* Update current programmed PLL rate var */
- CLOCK_GetPLL0OutFromSetupUpdate(pSetup);
-
- /* System voltage adjustment, occurs prior to setting main system clock */
- if ((pSetup->flags & PLL_SETUPFLAG_ADGVOLT) != 0U)
- {
- POWER_SetVoltageForFreq(s_Pll0_Freq);
- }
-
- return kStatus_PLL_Success;
-}
-
-/* Setup PLL Frequency from pre-calculated value */
-/**
- * brief Set PLL0 output from PLL setup structure (precise frequency)
- * param pSetup : Pointer to populated PLL setup structure
- * return kStatus_PLL_Success on success, or PLL setup error code
- * note This function will power off the PLL, setup the PLL with the
- * new setup data, and then optionally powerup the PLL, wait for PLL lock,
- * and adjust system voltages to the new PLL rate. The function will not
- * alter any source clocks (ie, main systen clock) that may use the PLL,
- * so these should be setup prior to and after exiting the function.
- */
-pll_error_t CLOCK_SetPLL0Freq(const pll_setup_t *pSetup)
-{
- uint32_t inRate, clkRate, prediv;
- /* Power off PLL during setup changes */
- POWER_EnablePD(kPDRUNCFG_PD_PLL0);
- POWER_EnablePD(kPDRUNCFG_PD_PLL0_SSCG);
-
- /* Write PLL setup data */
- SYSCON->PLL0CTRL = pSetup->pllctrl;
- SYSCON->PLL0NDEC = pSetup->pllndec;
- SYSCON->PLL0NDEC = pSetup->pllndec | (1UL << SYSCON_PLL0NDEC_NREQ_SHIFT); /* latch */
- SYSCON->PLL0PDEC = pSetup->pllpdec;
- SYSCON->PLL0PDEC = pSetup->pllpdec | (1UL << SYSCON_PLL0PDEC_PREQ_SHIFT); /* latch */
- SYSCON->PLL0SSCG0 = pSetup->pllsscg[0];
- SYSCON->PLL0SSCG1 = pSetup->pllsscg[1];
- SYSCON->PLL0SSCG1 =
- pSetup->pllsscg[1] | (1UL << SYSCON_PLL0SSCG1_MD_REQ_SHIFT) | (1UL << SYSCON_PLL0SSCG1_MREQ_SHIFT); /* latch */
-
- POWER_DisablePD(kPDRUNCFG_PD_PLL0);
- POWER_DisablePD(kPDRUNCFG_PD_PLL0_SSCG);
-
- if ((pSetup->flags & PLL_SETUPFLAG_WAITLOCK) != 0U)
- {
- if ((SYSCON->PLL0SSCG1 & SYSCON_PLL0SSCG1_MDIV_EXT_MASK) != 0UL) /* normal mode */
- {
- inRate = CLOCK_GetPLL0InClockRate();
- prediv = findPll0PreDiv();
- /* Adjust input clock */
- clkRate = inRate / prediv;
- /* The lock signal is only reliable between fref[2] :100 kHz to 20 MHz. */
- if ((clkRate >= 100000UL) && (clkRate <= 20000000UL))
- {
- while (CLOCK_IsPLL0Locked() == false)
- {
- }
- }
- else
- {
- SDK_DelayAtLeastUs(6000U,
- SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); /* software should use a 6 ms time interval
- to insure the PLL will be stable */
- }
- }
- else /* spread spectrum mode */
- {
- SDK_DelayAtLeastUs(6000U,
- SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); /* software should use a 6 ms time interval to
- insure the PLL will be stable */
- }
- }
-
- /* Update current programmed PLL rate var */
- s_Pll0_Freq = pSetup->pllRate;
-
- return kStatus_PLL_Success;
-}
-
-/* Setup PLL1 Frequency from pre-calculated value */
-/**
- * brief Set PLL1 output from PLL setup structure (precise frequency)
- * param pSetup : Pointer to populated PLL setup structure
- * return kStatus_PLL_Success on success, or PLL setup error code
- * note This function will power off the PLL, setup the PLL with the
- * new setup data, and then optionally powerup the PLL, wait for PLL lock,
- * and adjust system voltages to the new PLL rate. The function will not
- * alter any source clocks (ie, main systen clock) that may use the PLL,
- * so these should be setup prior to and after exiting the function.
- */
-pll_error_t CLOCK_SetPLL1Freq(const pll_setup_t *pSetup)
-{
- uint32_t inRate, clkRate, prediv;
- /* Power off PLL during setup changes */
- POWER_EnablePD(kPDRUNCFG_PD_PLL1);
-
- /* Write PLL setup data */
- SYSCON->PLL1CTRL = pSetup->pllctrl;
- SYSCON->PLL1NDEC = pSetup->pllndec;
- SYSCON->PLL1NDEC = pSetup->pllndec | (1UL << SYSCON_PLL1NDEC_NREQ_SHIFT); /* latch */
- SYSCON->PLL1PDEC = pSetup->pllpdec;
- SYSCON->PLL1PDEC = pSetup->pllpdec | (1UL << SYSCON_PLL1PDEC_PREQ_SHIFT); /* latch */
- SYSCON->PLL1MDEC = pSetup->pllmdec;
- SYSCON->PLL1MDEC = pSetup->pllmdec | (1UL << SYSCON_PLL1MDEC_MREQ_SHIFT); /* latch */
-
- POWER_DisablePD(kPDRUNCFG_PD_PLL1);
-
- if ((pSetup->flags & PLL_SETUPFLAG_WAITLOCK) != 0U)
- {
- inRate = CLOCK_GetPLL1InClockRate();
- prediv = findPll1PreDiv();
- /* Adjust input clock */
- clkRate = inRate / prediv;
- /* The lock signal is only reliable between fref[2] :100 kHz to 20 MHz. */
- if ((clkRate >= 100000UL) && (clkRate <= 20000000UL))
- {
- while (CLOCK_IsPLL1Locked() == false)
- {
- }
- }
- else
- {
- SDK_DelayAtLeastUs(6000U,
- SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY); /* software should use a 6 ms time interval to
- insure the PLL will be stable */
- }
- }
-
- /* Update current programmed PLL rate var */
- s_Pll0_Freq = pSetup->pllRate;
-
- return kStatus_PLL_Success;
-}
-
-/* Set PLL0 clock based on the input frequency and multiplier */
-/*! brief Set PLL0 output based on the multiplier and input frequency
- * param multiply_by : multiplier
- * param input_freq : Clock input frequency of the PLL
- * return Nothing
- * note Unlike the Chip_Clock_SetupSystemPLLPrec() function, this
- * function does not disable or enable PLL power, wait for PLL lock,
- * or adjust system voltages. These must be done in the application.
- * The function will not alter any source clocks (ie, main systen clock)
- * that may use the PLL, so these should be setup prior to and after
- * exiting the function.
- */
-void CLOCK_SetupPLL0Mult(uint32_t multiply_by, uint32_t input_freq)
-{
- uint32_t cco_freq = input_freq * multiply_by;
- uint32_t pdec = 1U;
- uint32_t selr;
- uint32_t seli;
- uint32_t selp;
- uint32_t mdec, ndec;
-
- while (cco_freq < 275000000U)
- {
- multiply_by <<= 1U; /* double value in each iteration */
- pdec <<= 1U; /* correspondingly double pdec to cancel effect of double msel */
- cco_freq = input_freq * multiply_by;
- }
-
- selr = 0U;
-
- if (multiply_by >= 8000UL)
- {
- seli = 1UL;
- }
- else if (multiply_by >= 122UL)
- {
- seli = (uint32_t)(8000UL / multiply_by); /*floor(8000/M) */
- }
- else
- {
- seli = 2UL * ((uint32_t)(multiply_by / 4UL)) + 3UL; /* 2*floor(M/4) + 3 */
- }
-
- if (seli >= 63U)
- {
- seli = 63U;
- }
-
- {
- selp = 31U;
- }
-
- if (pdec > 1U)
- {
- pdec = pdec / 2U; /* Account for minus 1 encoding */
- /* Translate P value */
- }
-
- mdec = (uint32_t)PLL_SSCG1_MDEC_VAL_SET(multiply_by);
- ndec = 0x1U; /* pre divide by 1 (hardcoded) */
-
- SYSCON->PLL0CTRL = SYSCON_PLL0CTRL_CLKEN_MASK | SYSCON_PLL0CTRL_BYPASSPOSTDIV(0) |
- SYSCON_PLL0CTRL_BYPASSPOSTDIV2(0) | (selr << SYSCON_PLL0CTRL_SELR_SHIFT) |
- (seli << SYSCON_PLL0CTRL_SELI_SHIFT) | (selp << SYSCON_PLL0CTRL_SELP_SHIFT);
- SYSCON->PLL0PDEC = pdec | (1UL << SYSCON_PLL0PDEC_PREQ_SHIFT); /* set Pdec value and assert preq */
- SYSCON->PLL0NDEC = ndec | (1UL << SYSCON_PLL0NDEC_NREQ_SHIFT); /* set Pdec value and assert preq */
- SYSCON->PLL0SSCG1 =
- mdec | (1UL << SYSCON_PLL0SSCG1_MREQ_SHIFT); /* select non sscg MDEC value, assert mreq and select mdec value */
-}
-
-/* Enable USB DEVICE FULL SPEED clock */
-/*! brief Enable USB Device FS clock.
- * param src : clock source
- * param freq: clock frequency
- * Enable USB Device Full Speed clock.
- */
-bool CLOCK_EnableUsbfs0DeviceClock(clock_usbfs_src_t src, uint32_t freq)
-{
- bool ret = true;
-
- CLOCK_DisableClock(kCLOCK_Usbd0);
-
- if (kCLOCK_UsbfsSrcFro == src)
- {
- switch (freq)
- {
- case 96000000U:
- CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 2, false); /*!< Div by 2 to get 48MHz, no divider reset */
- break;
-
- default:
- ret = false;
- break;
- }
- /* Turn ON FRO HF */
- POWER_DisablePD(kPDRUNCFG_PD_FRO192M);
- /* Enable FRO 96MHz output */
- ANACTRL->FRO192M_CTRL = ANACTRL->FRO192M_CTRL | ANACTRL_FRO192M_CTRL_ENA_96MHZCLK_MASK;
- /* Select FRO 96 or 48 MHz */
- CLOCK_AttachClk(kFRO_HF_to_USB0_CLK);
- }
- else
- {
- /*!< Configure XTAL32M */
- POWER_DisablePD(kPDRUNCFG_PD_XTAL32M); /* Ensure XTAL32M is powered */
- POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M); /* Ensure XTAL32M is powered */
- (void)CLOCK_SetupExtClocking(16000000U); /* Enable clk_in clock */
- SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clk_in from XTAL32M clock */
- ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable clk_in to system */
-
- /*!< Set up PLL1 */
- POWER_DisablePD(kPDRUNCFG_PD_PLL1);
- CLOCK_AttachClk(kEXT_CLK_to_PLL1); /*!< Switch PLL1CLKSEL to EXT_CLK */
- const pll_setup_t pll1Setup = {
- .pllctrl = SYSCON_PLL1CTRL_CLKEN_MASK | SYSCON_PLL1CTRL_SELI(19U) | SYSCON_PLL1CTRL_SELP(9U),
- .pllndec = SYSCON_PLL1NDEC_NDIV(1U),
- .pllpdec = SYSCON_PLL1PDEC_PDIV(5U),
- .pllmdec = SYSCON_PLL1MDEC_MDIV(30U),
- .pllRate = 48000000U,
- .flags = PLL_SETUPFLAG_WAITLOCK};
- (void)CLOCK_SetPLL1Freq(&pll1Setup);
-
- CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1U, false);
- CLOCK_AttachClk(kPLL1_to_USB0_CLK);
- SDK_DelayAtLeastUs(50U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
- }
- CLOCK_EnableClock(kCLOCK_Usbd0);
- CLOCK_EnableClock(kCLOCK_UsbRam1);
-
- return ret;
-}
-
-/* Enable USB HOST FULL SPEED clock */
-/*! brief Enable USB HOST FS clock.
- * param src : clock source
- * param freq: clock frequency
- * Enable USB HOST Full Speed clock.
- */
-bool CLOCK_EnableUsbfs0HostClock(clock_usbfs_src_t src, uint32_t freq)
-{
- bool ret = true;
-
- CLOCK_DisableClock(kCLOCK_Usbhmr0);
- CLOCK_DisableClock(kCLOCK_Usbhsl0);
-
- if (kCLOCK_UsbfsSrcFro == src)
- {
- switch (freq)
- {
- case 96000000U:
- CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 2, false); /*!< Div by 2 to get 48MHz, no divider reset */
- break;
-
- default:
- ret = false;
- break;
- }
- /* Turn ON FRO HF */
- POWER_DisablePD(kPDRUNCFG_PD_FRO192M);
- /* Enable FRO 96MHz output */
- ANACTRL->FRO192M_CTRL = ANACTRL->FRO192M_CTRL | ANACTRL_FRO192M_CTRL_ENA_96MHZCLK_MASK;
- /* Select FRO 96 MHz */
- CLOCK_AttachClk(kFRO_HF_to_USB0_CLK);
- }
- else
- {
- /*!< Configure XTAL32M */
- POWER_DisablePD(kPDRUNCFG_PD_XTAL32M); /* Ensure XTAL32M is powered */
- POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M); /* Ensure XTAL32M is powered */
- (void)CLOCK_SetupExtClocking(16000000U); /* Enable clk_in clock */
- SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clk_in from XTAL32M clock */
- ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_SYSTEM_CLK_OUT_MASK; /* Enable clk_in to system */
-
- /*!< Set up PLL1 */
- POWER_DisablePD(kPDRUNCFG_PD_PLL1);
- CLOCK_AttachClk(kEXT_CLK_to_PLL1); /*!< Switch PLL1CLKSEL to EXT_CLK */
- const pll_setup_t pll1Setup = {
- .pllctrl = SYSCON_PLL1CTRL_CLKEN_MASK | SYSCON_PLL1CTRL_SELI(19U) | SYSCON_PLL1CTRL_SELP(9U),
- .pllndec = SYSCON_PLL1NDEC_NDIV(1U),
- .pllpdec = SYSCON_PLL1PDEC_PDIV(5U),
- .pllmdec = SYSCON_PLL1MDEC_MDIV(30U),
- .pllRate = 48000000U,
- .flags = PLL_SETUPFLAG_WAITLOCK};
- (void)CLOCK_SetPLL1Freq(&pll1Setup);
-
- CLOCK_SetClkDiv(kCLOCK_DivUsb0Clk, 1U, false);
- CLOCK_AttachClk(kPLL1_to_USB0_CLK);
- SDK_DelayAtLeastUs(50U, SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY);
- }
- CLOCK_EnableClock(kCLOCK_Usbhmr0);
- CLOCK_EnableClock(kCLOCK_Usbhsl0);
- CLOCK_EnableClock(kCLOCK_UsbRam1);
-
- return ret;
-}
-
-/* Enable USB PHY clock */
-bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq)
-{
- volatile uint32_t i;
-
- POWER_DisablePD(kPDRUNCFG_PD_XTAL32M);
- POWER_DisablePD(kPDRUNCFG_PD_LDOXO32M);
- POWER_DisablePD(kPDRUNCFG_PD_FRO32K); /*!< Ensure FRO32k is on */
- POWER_DisablePD(kPDRUNCFG_PD_XTAL32K); /*!< Ensure xtal32k is on */
- POWER_DisablePD(kPDRUNCFG_PD_USB1_PHY); /*!< Ensure xtal32k is on */
- POWER_DisablePD(kPDRUNCFG_PD_LDOUSBHS); /*!< Ensure xtal32k is on */
-
- /* wait to make sure PHY power is fully up */
- i = 100000U;
- while ((i--) != 0U)
- {
- __ASM("nop");
- }
-
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_ANALOG_CTRL(1);
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_USB1_PHY(1);
-
- USBPHY->CTRL_CLR = USBPHY_CTRL_SFTRST_MASK;
- USBPHY->PLL_SIC = (USBPHY->PLL_SIC & ~USBPHY_PLL_SIC_PLL_DIV_SEL(0x7)) | USBPHY_PLL_SIC_PLL_DIV_SEL(0x06);
- USBPHY->PLL_SIC_SET = USBPHY_PLL_SIC_SET_PLL_REG_ENABLE_MASK;
- USBPHY->PLL_SIC_CLR = (1UL << 16U); // Reserved. User must set this bit to 0x0
- USBPHY->PLL_SIC_SET = USBPHY_PLL_SIC_SET_PLL_POWER_MASK;
- USBPHY->PLL_SIC_SET = USBPHY_PLL_SIC_SET_PLL_EN_USB_CLKS_MASK;
-
- USBPHY->CTRL_CLR = USBPHY_CTRL_CLR_CLKGATE_MASK;
- USBPHY->PWD_SET = 0x0;
-
- return true;
-}
-
-/* Enable USB DEVICE HIGH SPEED clock */
-bool CLOCK_EnableUsbhs0DeviceClock(clock_usbhs_src_t src, uint32_t freq)
-{
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_USB1_RAM(1);
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_USB1_DEV(1);
-
- /* 16 MHz will be driven by the tb on the xtal1 pin of XTAL32M */
- SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clock_in clock for clock module. */
- ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_PLL_USB_OUT(1);
- return true;
-}
-
-/* Enable USB HOST HIGH SPEED clock */
-bool CLOCK_EnableUsbhs0HostClock(clock_usbhs_src_t src, uint32_t freq)
-{
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_USB1_RAM(1);
- SYSCON->AHBCLKCTRLSET[2] = SYSCON_AHBCLKCTRL2_USB1_HOST(1);
-
- /* 16 MHz will be driven by the tb on the xtal1 pin of XTAL32M */
- SYSCON->CLOCK_CTRL |= SYSCON_CLOCK_CTRL_CLKIN_ENA_MASK; /* Enable clock_in clock for clock module. */
- ANACTRL->XO32M_CTRL |= ANACTRL_XO32M_CTRL_ENABLE_PLL_USB_OUT(1);
-
- return true;
-}
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.h
deleted file mode 100755
index d5b745965..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_clock.h
+++ /dev/null
@@ -1,1240 +0,0 @@
-/*
- * Copyright 2017 - 2020 , NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _FSL_CLOCK_H_
-#define _FSL_CLOCK_H_
-
-#include "fsl_common.h"
-
-/*! @addtogroup clock */
-/*! @{ */
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- *****************************************************************************/
-
-/*! @name Driver version */
-/*@{*/
-/*! @brief CLOCK driver version 2.3.2. */
-#define FSL_CLOCK_DRIVER_VERSION (MAKE_VERSION(2, 3, 2))
-/*@}*/
-
-/*! @brief Configure whether driver controls clock
- *
- * When set to 0, peripheral drivers will enable clock in initialize function
- * and disable clock in de-initialize function. When set to 1, peripheral
- * driver will not control the clock, application could control the clock out of
- * the driver.
- *
- * @note All drivers share this feature switcher. If it is set to 1, application
- * should handle clock enable and disable for all drivers.
- */
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL))
-#define FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL 0
-#endif
-
-/*!
- * @brief User-defined the size of cache for CLOCK_PllGetConfig() function.
- *
- * Once define this MACRO to be non-zero value, CLOCK_PllGetConfig() function
- * would cache the recent calulation and accelerate the execution to get the
- * right settings.
- */
-#ifndef CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT
-#define CLOCK_USR_CFG_PLL_CONFIG_CACHE_COUNT 2U
-#endif
-
-/* Definition for delay API in clock driver, users can redefine it to the real application. */
-#ifndef SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY
-#define SDK_DEVICE_MAXIMUM_CPU_CLOCK_FREQUENCY (150000000UL)
-#endif
-
-/*! @brief Clock ip name array for ROM. */
-#define ROM_CLOCKS \
- { \
- kCLOCK_Rom \
- }
-/*! @brief Clock ip name array for SRAM. */
-#define SRAM_CLOCKS \
- { \
- kCLOCK_Sram1, kCLOCK_Sram2, kCLOCK_Sram3, kCLOCK_Sram4 \
- }
-/*! @brief Clock ip name array for FLASH. */
-#define FLASH_CLOCKS \
- { \
- kCLOCK_Flash \
- }
-/*! @brief Clock ip name array for FMC. */
-#define FMC_CLOCKS \
- { \
- kCLOCK_Fmc \
- }
-/*! @brief Clock ip name array for INPUTMUX. */
-#define INPUTMUX_CLOCKS \
- { \
- kCLOCK_InputMux0 \
- }
-/*! @brief Clock ip name array for IOCON. */
-#define IOCON_CLOCKS \
- { \
- kCLOCK_Iocon \
- }
-/*! @brief Clock ip name array for GPIO. */
-#define GPIO_CLOCKS \
- { \
- kCLOCK_Gpio0, kCLOCK_Gpio1, kCLOCK_Gpio2, kCLOCK_Gpio3 \
- }
-/*! @brief Clock ip name array for PINT. */
-#define PINT_CLOCKS \
- { \
- kCLOCK_Pint \
- }
-/*! @brief Clock ip name array for GINT. */
-#define GINT_CLOCKS \
- { \
- kCLOCK_Gint, kCLOCK_Gint \
- }
-/*! @brief Clock ip name array for DMA. */
-#define DMA_CLOCKS \
- { \
- kCLOCK_Dma0, kCLOCK_Dma1 \
- }
-/*! @brief Clock ip name array for CRC. */
-#define CRC_CLOCKS \
- { \
- kCLOCK_Crc \
- }
-/*! @brief Clock ip name array for WWDT. */
-#define WWDT_CLOCKS \
- { \
- kCLOCK_Wwdt \
- }
-/*! @brief Clock ip name array for RTC. */
-#define RTC_CLOCKS \
- { \
- kCLOCK_Rtc \
- }
-/*! @brief Clock ip name array for Mailbox. */
-#define MAILBOX_CLOCKS \
- { \
- kCLOCK_Mailbox \
- }
-/*! @brief Clock ip name array for LPADC. */
-#define LPADC_CLOCKS \
- { \
- kCLOCK_Adc0 \
- }
-/*! @brief Clock ip name array for MRT. */
-#define MRT_CLOCKS \
- { \
- kCLOCK_Mrt \
- }
-/*! @brief Clock ip name array for OSTIMER. */
-#define OSTIMER_CLOCKS \
- { \
- kCLOCK_OsTimer0 \
- }
-/*! @brief Clock ip name array for SCT0. */
-#define SCT_CLOCKS \
- { \
- kCLOCK_Sct0 \
- }
-/*! @brief Clock ip name array for UTICK. */
-#define UTICK_CLOCKS \
- { \
- kCLOCK_Utick0 \
- }
-/*! @brief Clock ip name array for FLEXCOMM. */
-#define FLEXCOMM_CLOCKS \
- { \
- kCLOCK_FlexComm0, kCLOCK_FlexComm1, kCLOCK_FlexComm2, kCLOCK_FlexComm3, kCLOCK_FlexComm4, kCLOCK_FlexComm5, \
- kCLOCK_FlexComm6, kCLOCK_FlexComm7, kCLOCK_Hs_Lspi \
- }
-/*! @brief Clock ip name array for LPUART. */
-#define LPUART_CLOCKS \
- { \
- kCLOCK_MinUart0, kCLOCK_MinUart1, kCLOCK_MinUart2, kCLOCK_MinUart3, kCLOCK_MinUart4, kCLOCK_MinUart5, \
- kCLOCK_MinUart6, kCLOCK_MinUart7 \
- }
-
-/*! @brief Clock ip name array for BI2C. */
-#define BI2C_CLOCKS \
- { \
- kCLOCK_BI2c0, kCLOCK_BI2c1, kCLOCK_BI2c2, kCLOCK_BI2c3, kCLOCK_BI2c4, kCLOCK_BI2c5, kCLOCK_BI2c6, kCLOCK_BI2c7 \
- }
-/*! @brief Clock ip name array for LSPI. */
-#define LPSPI_CLOCKS \
- { \
- kCLOCK_LSpi0, kCLOCK_LSpi1, kCLOCK_LSpi2, kCLOCK_LSpi3, kCLOCK_LSpi4, kCLOCK_LSpi5, kCLOCK_LSpi6, kCLOCK_LSpi7 \
- }
-/*! @brief Clock ip name array for FLEXI2S. */
-#define FLEXI2S_CLOCKS \
- { \
- kCLOCK_FlexI2s0, kCLOCK_FlexI2s1, kCLOCK_FlexI2s2, kCLOCK_FlexI2s3, kCLOCK_FlexI2s4, kCLOCK_FlexI2s5, \
- kCLOCK_FlexI2s6, kCLOCK_FlexI2s7 \
- }
-/*! @brief Clock ip name array for CTIMER. */
-#define CTIMER_CLOCKS \
- { \
- kCLOCK_Timer0, kCLOCK_Timer1, kCLOCK_Timer2, kCLOCK_Timer3, kCLOCK_Timer4 \
- }
-/*! @brief Clock ip name array for COMP */
-#define COMP_CLOCKS \
- { \
- kCLOCK_Comp \
- }
-/*! @brief Clock ip name array for SDIO. */
-#define SDIO_CLOCKS \
- { \
- kCLOCK_Sdio \
- }
-/*! @brief Clock ip name array for USB1CLK. */
-#define USB1CLK_CLOCKS \
- { \
- kCLOCK_Usb1Clk \
- }
-/*! @brief Clock ip name array for FREQME. */
-#define FREQME_CLOCKS \
- { \
- kCLOCK_Freqme \
- }
-/*! @brief Clock ip name array for USBRAM. */
-#define USBRAM_CLOCKS \
- { \
- kCLOCK_UsbRam1 \
- }
-/*! @brief Clock ip name array for RNG. */
-#define RNG_CLOCKS \
- { \
- kCLOCK_Rng \
- }
-/*! @brief Clock ip name array for USBHMR0. */
-#define USBHMR0_CLOCKS \
- { \
- kCLOCK_Usbhmr0 \
- }
-/*! @brief Clock ip name array for USBHSL0. */
-#define USBHSL0_CLOCKS \
- { \
- kCLOCK_Usbhsl0 \
- }
-/*! @brief Clock ip name array for HashCrypt. */
-#define HASHCRYPT_CLOCKS \
- { \
- kCLOCK_HashCrypt \
- }
-/*! @brief Clock ip name array for PowerQuad. */
-#define POWERQUAD_CLOCKS \
- { \
- kCLOCK_PowerQuad \
- }
-/*! @brief Clock ip name array for PLULUT. */
-#define PLULUT_CLOCKS \
- { \
- kCLOCK_PluLut \
- }
-/*! @brief Clock ip name array for PUF. */
-#define PUF_CLOCKS \
- { \
- kCLOCK_Puf \
- }
-/*! @brief Clock ip name array for CASPER. */
-#define CASPER_CLOCKS \
- { \
- kCLOCK_Casper \
- }
-/*! @brief Clock ip name array for ANALOGCTRL. */
-#define ANALOGCTRL_CLOCKS \
- { \
- kCLOCK_AnalogCtrl \
- }
-/*! @brief Clock ip name array for HS_LSPI. */
-#define HS_LSPI_CLOCKS \
- { \
- kCLOCK_Hs_Lspi \
- }
-/*! @brief Clock ip name array for GPIO_SEC. */
-#define GPIO_SEC_CLOCKS \
- { \
- kCLOCK_Gpio_Sec \
- }
-/*! @brief Clock ip name array for GPIO_SEC_INT. */
-#define GPIO_SEC_INT_CLOCKS \
- { \
- kCLOCK_Gpio_Sec_Int \
- }
-/*! @brief Clock ip name array for USBD. */
-#define USBD_CLOCKS \
- { \
- kCLOCK_Usbd0, kCLOCK_Usbh1, kCLOCK_Usbd1 \
- }
-/*! @brief Clock ip name array for USBH. */
-#define USBH_CLOCKS \
- { \
- kCLOCK_Usbh1 \
- }
-#define PLU_CLOCKS \
- { \
- kCLOCK_PluLut \
- }
-#define SYSCTL_CLOCKS \
- { \
- kCLOCK_Sysctl \
- }
-/*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
-/*------------------------------------------------------------------------------
- clock_ip_name_t definition:
-------------------------------------------------------------------------------*/
-
-#define CLK_GATE_REG_OFFSET_SHIFT 8U
-#define CLK_GATE_REG_OFFSET_MASK 0xFFFFFF00U
-#define CLK_GATE_BIT_SHIFT_SHIFT 0U
-#define CLK_GATE_BIT_SHIFT_MASK 0x000000FFU
-
-#define CLK_GATE_DEFINE(reg_offset, bit_shift) \
- ((((reg_offset) << CLK_GATE_REG_OFFSET_SHIFT) & CLK_GATE_REG_OFFSET_MASK) | \
- (((bit_shift) << CLK_GATE_BIT_SHIFT_SHIFT) & CLK_GATE_BIT_SHIFT_MASK))
-
-#define CLK_GATE_ABSTRACT_REG_OFFSET(x) (((uint32_t)(x)&CLK_GATE_REG_OFFSET_MASK) >> CLK_GATE_REG_OFFSET_SHIFT)
-#define CLK_GATE_ABSTRACT_BITS_SHIFT(x) (((uint32_t)(x)&CLK_GATE_BIT_SHIFT_MASK) >> CLK_GATE_BIT_SHIFT_SHIFT)
-
-#define AHB_CLK_CTRL0 0
-#define AHB_CLK_CTRL1 1
-#define AHB_CLK_CTRL2 2
-
-/*! @brief Clock gate name used for CLOCK_EnableClock/CLOCK_DisableClock. */
-typedef enum _clock_ip_name
-{
- kCLOCK_IpInvalid = 0U,
- kCLOCK_Rom = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 1),
- kCLOCK_Sram1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 3),
- kCLOCK_Sram2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 4),
- kCLOCK_Sram3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 5),
- kCLOCK_Sram4 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 6),
- kCLOCK_Flash = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 7),
- kCLOCK_Fmc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 8),
- kCLOCK_InputMux = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 11),
- kCLOCK_Iocon = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 13),
- kCLOCK_Gpio0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 14),
- kCLOCK_Gpio1 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 15),
- kCLOCK_Gpio2 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 16),
- kCLOCK_Gpio3 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 17),
- kCLOCK_Pint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 18),
- kCLOCK_Gint = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 19),
- kCLOCK_Dma0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 20),
- kCLOCK_Crc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 21),
- kCLOCK_Wwdt = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 22),
- kCLOCK_Rtc = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 23),
- kCLOCK_Mailbox = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 26),
- kCLOCK_Adc0 = CLK_GATE_DEFINE(AHB_CLK_CTRL0, 27),
- kCLOCK_Mrt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 0),
- kCLOCK_OsTimer0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 1),
- kCLOCK_Sct0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 2),
- kCLOCK_Utick0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 10),
- kCLOCK_FlexComm0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
- kCLOCK_FlexComm1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
- kCLOCK_FlexComm2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
- kCLOCK_FlexComm3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
- kCLOCK_FlexComm4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
- kCLOCK_FlexComm5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
- kCLOCK_FlexComm6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
- kCLOCK_FlexComm7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
- kCLOCK_MinUart0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
- kCLOCK_MinUart1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
- kCLOCK_MinUart2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
- kCLOCK_MinUart3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
- kCLOCK_MinUart4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
- kCLOCK_MinUart5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
- kCLOCK_MinUart6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
- kCLOCK_MinUart7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
- kCLOCK_LSpi0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
- kCLOCK_LSpi1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
- kCLOCK_LSpi2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
- kCLOCK_LSpi3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
- kCLOCK_LSpi4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
- kCLOCK_LSpi5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
- kCLOCK_LSpi6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
- kCLOCK_LSpi7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
- kCLOCK_BI2c0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
- kCLOCK_BI2c1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
- kCLOCK_BI2c2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
- kCLOCK_BI2c3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
- kCLOCK_BI2c4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
- kCLOCK_BI2c5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
- kCLOCK_BI2c6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
- kCLOCK_BI2c7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
- kCLOCK_FlexI2s0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 11),
- kCLOCK_FlexI2s1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 12),
- kCLOCK_FlexI2s2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 13),
- kCLOCK_FlexI2s3 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 14),
- kCLOCK_FlexI2s4 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 15),
- kCLOCK_FlexI2s5 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 16),
- kCLOCK_FlexI2s6 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 17),
- kCLOCK_FlexI2s7 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 18),
- kCLOCK_Timer2 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 22),
- kCLOCK_Usbd0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 25),
- kCLOCK_Timer0 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 26),
- kCLOCK_Timer1 = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 27),
- kCLOCK_Pvt = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 28),
- kCLOCK_Ezha = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 30),
- kCLOCK_Ezhb = CLK_GATE_DEFINE(AHB_CLK_CTRL1, 31),
- kCLOCK_Dma1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 1),
- kCLOCK_Comp = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 2),
- kCLOCK_Sdio = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 3),
- kCLOCK_Usbh1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 4),
- kCLOCK_Usbd1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 5),
- kCLOCK_UsbRam1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 6),
- kCLOCK_Usb1Clk = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 7),
- kCLOCK_Freqme = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 8),
- kCLOCK_Rng = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 13),
- kCLOCK_InputMux1 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 14),
- kCLOCK_Sysctl = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 15),
- kCLOCK_Usbhmr0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 16),
- kCLOCK_Usbhsl0 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 17),
- kCLOCK_HashCrypt = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 18),
- kCLOCK_PowerQuad = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 19),
- kCLOCK_PluLut = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 20),
- kCLOCK_Timer3 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 21),
- kCLOCK_Timer4 = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 22),
- kCLOCK_Puf = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 23),
- kCLOCK_Casper = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 24),
- kCLOCK_AnalogCtrl = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 27),
- kCLOCK_Hs_Lspi = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 28),
- kCLOCK_Gpio_Sec = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 29),
- kCLOCK_Gpio_Sec_Int = CLK_GATE_DEFINE(AHB_CLK_CTRL2, 30)
-} clock_ip_name_t;
-
-/*! @brief Peripherals clock source definition. */
-#define BUS_CLK kCLOCK_BusClk
-
-#define I2C0_CLK_SRC BUS_CLK
-
-/*! @brief Clock name used to get clock frequency. */
-typedef enum _clock_name
-{
- kCLOCK_CoreSysClk, /*!< Core/system clock (aka MAIN_CLK) */
- kCLOCK_BusClk, /*!< Bus clock (AHB clock) */
- kCLOCK_ClockOut, /*!< CLOCKOUT */
- kCLOCK_FroHf, /*!< FRO48/96 */
- kCLOCK_Pll1Out, /*!< PLL1 Output */
- kCLOCK_Mclk, /*!< MCLK */
- kCLOCK_Fro12M, /*!< FRO12M */
- kCLOCK_ExtClk, /*!< External Clock */
- kCLOCK_Pll0Out, /*!< PLL0 Output */
- kCLOCK_FlexI2S, /*!< FlexI2S clock */
-
-} clock_name_t;
-
-/*! @brief Clock Mux Switches
- * The encoding is as follows each connection identified is 32bits wide while 24bits are valuable
- * starting from LSB upwards
- *
- * [4 bits for choice, 0 means invalid choice] [8 bits mux ID]*
- *
- */
-
-#define CLK_ATTACH_ID(mux, sel, pos) \
- ((((uint32_t)(mux) << 0U) | (((uint32_t)(sel) + 1U) & 0xFU) << 8U) << ((uint32_t)(pos)*12U))
-#define MUX_A(mux, sel) CLK_ATTACH_ID((mux), (sel), 0U)
-#define MUX_B(mux, sel, selector) (CLK_ATTACH_ID((mux), (sel), 1U) | ((selector) << 24U))
-
-#define GET_ID_ITEM(connection) ((connection)&0xFFFU)
-#define GET_ID_NEXT_ITEM(connection) ((connection) >> 12U)
-#define GET_ID_ITEM_MUX(connection) (((uint8_t)connection) & 0xFFU)
-#define GET_ID_ITEM_SEL(connection) ((uint8_t)((((uint32_t)(connection)&0xF00U) >> 8U) - 1U))
-#define GET_ID_SELECTOR(connection) ((connection)&0xF000000U)
-
-#define CM_SYSTICKCLKSEL0 0U
-#define CM_SYSTICKCLKSEL1 1U
-#define CM_TRACECLKSEL 2U
-#define CM_CTIMERCLKSEL0 3U
-#define CM_CTIMERCLKSEL1 4U
-#define CM_CTIMERCLKSEL2 5U
-#define CM_CTIMERCLKSEL3 6U
-#define CM_CTIMERCLKSEL4 7U
-#define CM_MAINCLKSELA 8U
-#define CM_MAINCLKSELB 9U
-#define CM_CLKOUTCLKSEL 10U
-#define CM_PLL0CLKSEL 12U
-#define CM_PLL1CLKSEL 13U
-#define CM_ADCASYNCCLKSEL 17U
-#define CM_USB0CLKSEL 18U
-#define CM_FXCOMCLKSEL0 20U
-#define CM_FXCOMCLKSEL1 21U
-#define CM_FXCOMCLKSEL2 22U
-#define CM_FXCOMCLKSEL3 23U
-#define CM_FXCOMCLKSEL4 24U
-#define CM_FXCOMCLKSEL5 25U
-#define CM_FXCOMCLKSEL6 26U
-#define CM_FXCOMCLKSEL7 27U
-#define CM_HSLSPICLKSEL 28U
-#define CM_MCLKCLKSEL 32U
-#define CM_SCTCLKSEL 36U
-#define CM_SDIOCLKSEL 38U
-
-#define CM_RTCOSC32KCLKSEL 63U
-
-typedef enum _clock_attach_id
-{
-
- kFRO12M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 0, 0),
- kEXT_CLK_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 1) | MUX_B(CM_MAINCLKSELB, 0, 0),
- kFRO1M_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 2) | MUX_B(CM_MAINCLKSELB, 0, 0),
- kFRO_HF_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 3) | MUX_B(CM_MAINCLKSELB, 0, 0),
- kPLL0_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 1, 0),
- kPLL1_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 2, 0),
- kOSC32K_to_MAIN_CLK = MUX_A(CM_MAINCLKSELA, 0) | MUX_B(CM_MAINCLKSELB, 3, 0),
-
- kMAIN_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 0),
- kPLL0_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 1),
- kEXT_CLK_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 2),
- kFRO_HF_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 3),
- kFRO1M_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 4),
- kPLL1_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 5),
- kOSC32K_to_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 6),
- kNONE_to_SYS_CLKOUT = MUX_A(CM_CLKOUTCLKSEL, 7),
-
- kFRO12M_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 0),
- kEXT_CLK_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 1),
- kFRO1M_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 2),
- kOSC32K_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 3),
- kNONE_to_PLL0 = MUX_A(CM_PLL0CLKSEL, 7),
-
- kMAIN_CLK_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 0),
- kPLL0_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 1),
- kFRO_HF_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 2),
- kNONE_to_ADC_CLK = MUX_A(CM_ADCASYNCCLKSEL, 7),
-
- kMAIN_CLK_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 0),
- kPLL0_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 1),
- kFRO_HF_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 3),
- kPLL1_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 5),
- kNONE_to_USB0_CLK = MUX_A(CM_USB0CLKSEL, 7),
-
- kMAIN_CLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 0),
- kPLL0_DIV_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 1),
- kFRO12M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 2),
- kFRO_HF_DIV_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 3),
- kFRO1M_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 4),
- kMCLK_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 5),
- kOSC32K_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 6),
- kNONE_to_FLEXCOMM0 = MUX_A(CM_FXCOMCLKSEL0, 7),
-
- kMAIN_CLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 0),
- kPLL0_DIV_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 1),
- kFRO12M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 2),
- kFRO_HF_DIV_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 3),
- kFRO1M_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 4),
- kMCLK_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 5),
- kOSC32K_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 6),
- kNONE_to_FLEXCOMM1 = MUX_A(CM_FXCOMCLKSEL1, 7),
-
- kMAIN_CLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 0),
- kPLL0_DIV_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 1),
- kFRO12M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 2),
- kFRO_HF_DIV_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 3),
- kFRO1M_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 4),
- kMCLK_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 5),
- kOSC32K_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 6),
- kNONE_to_FLEXCOMM2 = MUX_A(CM_FXCOMCLKSEL2, 7),
-
- kMAIN_CLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 0),
- kPLL0_DIV_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 1),
- kFRO12M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 2),
- kFRO_HF_DIV_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 3),
- kFRO1M_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 4),
- kMCLK_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 5),
- kOSC32K_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 6),
- kNONE_to_FLEXCOMM3 = MUX_A(CM_FXCOMCLKSEL3, 7),
-
- kMAIN_CLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 0),
- kPLL0_DIV_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 1),
- kFRO12M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 2),
- kFRO_HF_DIV_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 3),
- kFRO1M_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 4),
- kMCLK_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 5),
- kOSC32K_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 6),
- kNONE_to_FLEXCOMM4 = MUX_A(CM_FXCOMCLKSEL4, 7),
-
- kMAIN_CLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 0),
- kPLL0_DIV_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 1),
- kFRO12M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 2),
- kFRO_HF_DIV_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 3),
- kFRO1M_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 4),
- kMCLK_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 5),
- kOSC32K_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 6),
- kNONE_to_FLEXCOMM5 = MUX_A(CM_FXCOMCLKSEL5, 7),
-
- kMAIN_CLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 0),
- kPLL0_DIV_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 1),
- kFRO12M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 2),
- kFRO_HF_DIV_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 3),
- kFRO1M_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 4),
- kMCLK_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 5),
- kOSC32K_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 6),
- kNONE_to_FLEXCOMM6 = MUX_A(CM_FXCOMCLKSEL6, 7),
-
- kMAIN_CLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 0),
- kPLL0_DIV_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 1),
- kFRO12M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 2),
- kFRO_HF_DIV_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 3),
- kFRO1M_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 4),
- kMCLK_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 5),
- kOSC32K_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 6),
- kNONE_to_FLEXCOMM7 = MUX_A(CM_FXCOMCLKSEL7, 7),
-
- kMAIN_CLK_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 0),
- kPLL0_DIV_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 1),
- kFRO12M_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 2),
- kFRO_HF_DIV_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 3),
- kFRO1M_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 4),
- kOSC32K_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 6),
- kNONE_to_HSLSPI = MUX_A(CM_HSLSPICLKSEL, 7),
-
- kFRO_HF_to_MCLK = MUX_A(CM_MCLKCLKSEL, 0),
- kPLL0_to_MCLK = MUX_A(CM_MCLKCLKSEL, 1),
- kNONE_to_MCLK = MUX_A(CM_MCLKCLKSEL, 7),
-
- kMAIN_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 0),
- kPLL0_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 1),
- kEXT_CLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 2),
- kFRO_HF_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 3),
- kMCLK_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 5),
- kNONE_to_SCT_CLK = MUX_A(CM_SCTCLKSEL, 7),
-
- kMAIN_CLK_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 0),
- kPLL0_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 1),
- kFRO_HF_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 3),
- kPLL1_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 5),
- kNONE_to_SDIO_CLK = MUX_A(CM_SDIOCLKSEL, 7),
-
- kFRO32K_to_OSC32K = MUX_A(CM_RTCOSC32KCLKSEL, 0),
- kXTAL32K_to_OSC32K = MUX_A(CM_RTCOSC32KCLKSEL, 1),
-
- kTRACE_DIV_to_TRACE = MUX_A(CM_TRACECLKSEL, 0),
- kFRO1M_to_TRACE = MUX_A(CM_TRACECLKSEL, 1),
- kOSC32K_to_TRACE = MUX_A(CM_TRACECLKSEL, 2),
- kNONE_to_TRACE = MUX_A(CM_TRACECLKSEL, 7),
-
- kSYSTICK_DIV0_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 0),
- kFRO1M_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 1),
- kOSC32K_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 2),
- kNONE_to_SYSTICK0 = MUX_A(CM_SYSTICKCLKSEL0, 7),
-
- kSYSTICK_DIV1_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 0),
- kFRO1M_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 1),
- kOSC32K_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 2),
- kNONE_to_SYSTICK1 = MUX_A(CM_SYSTICKCLKSEL1, 7),
-
- kFRO12M_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 0),
- kEXT_CLK_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 1),
- kFRO1M_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 2),
- kOSC32K_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 3),
- kNONE_to_PLL1 = MUX_A(CM_PLL1CLKSEL, 7),
-
- kMAIN_CLK_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 0),
- kPLL0_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 1),
- kFRO_HF_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 3),
- kFRO1M_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 4),
- kMCLK_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 5),
- kOSC32K_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 6),
- kNONE_to_CTIMER0 = MUX_A(CM_CTIMERCLKSEL0, 7),
-
- kMAIN_CLK_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 0),
- kPLL0_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 1),
- kFRO_HF_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 3),
- kFRO1M_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 4),
- kMCLK_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 5),
- kOSC32K_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 6),
- kNONE_to_CTIMER1 = MUX_A(CM_CTIMERCLKSEL1, 7),
-
- kMAIN_CLK_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 0),
- kPLL0_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 1),
- kFRO_HF_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 3),
- kFRO1M_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 4),
- kMCLK_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 5),
- kOSC32K_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 6),
- kNONE_to_CTIMER2 = MUX_A(CM_CTIMERCLKSEL2, 7),
-
- kMAIN_CLK_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 0),
- kPLL0_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 1),
- kFRO_HF_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 3),
- kFRO1M_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 4),
- kMCLK_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 5),
- kOSC32K_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 6),
- kNONE_to_CTIMER3 = MUX_A(CM_CTIMERCLKSEL3, 7),
-
- kMAIN_CLK_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 0),
- kPLL0_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 1),
- kFRO_HF_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 3),
- kFRO1M_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 4),
- kMCLK_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 5),
- kOSC32K_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 6),
- kNONE_to_CTIMER4 = MUX_A(CM_CTIMERCLKSEL4, 7),
- kNONE_to_NONE = (int)0x80000000U,
-} clock_attach_id_t;
-
-/* Clock dividers */
-typedef enum _clock_div_name
-{
- kCLOCK_DivSystickClk0 = 0,
- kCLOCK_DivSystickClk1 = 1,
- kCLOCK_DivArmTrClkDiv = 2,
- kCLOCK_DivFlexFrg0 = 8,
- kCLOCK_DivFlexFrg1 = 9,
- kCLOCK_DivFlexFrg2 = 10,
- kCLOCK_DivFlexFrg3 = 11,
- kCLOCK_DivFlexFrg4 = 12,
- kCLOCK_DivFlexFrg5 = 13,
- kCLOCK_DivFlexFrg6 = 14,
- kCLOCK_DivFlexFrg7 = 15,
- kCLOCK_DivAhbClk = 32,
- kCLOCK_DivClkOut = 33,
- kCLOCK_DivFrohfClk = 34,
- kCLOCK_DivWdtClk = 35,
- kCLOCK_DivAdcAsyncClk = 37,
- kCLOCK_DivUsb0Clk = 38,
- kCLOCK_DivMClk = 43,
- kCLOCK_DivSctClk = 45,
- kCLOCK_DivSdioClk = 47,
- kCLOCK_DivPll0Clk = 49
-} clock_div_name_t;
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif /* __cplusplus */
-
-/**
- * @brief Enable the clock for specific IP.
- * @param name : Clock to be enabled.
- * @return Nothing
- */
-static inline void CLOCK_EnableClock(clock_ip_name_t clk)
-{
- uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
- SYSCON->AHBCLKCTRLSET[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
-}
-/**
- * @brief Disable the clock for specific IP.
- * @param name : Clock to be Disabled.
- * @return Nothing
- */
-static inline void CLOCK_DisableClock(clock_ip_name_t clk)
-{
- uint32_t index = CLK_GATE_ABSTRACT_REG_OFFSET(clk);
- SYSCON->AHBCLKCTRLCLR[index] = (1UL << CLK_GATE_ABSTRACT_BITS_SHIFT(clk));
-}
-/**
- * @brief Initialize the Core clock to given frequency (12, 48 or 96 MHz).
- * Turns on FRO and uses default CCO, if freq is 12000000, then high speed output is off, else high speed output is
- * enabled.
- * @param iFreq : Desired frequency (must be one of #CLK_FRO_12MHZ or #CLK_FRO_48MHZ or #CLK_FRO_96MHZ)
- * @return returns success or fail status.
- */
-status_t CLOCK_SetupFROClocking(uint32_t iFreq);
-/**
- * @brief Set the flash wait states for the input freuqency.
- * @param iFreq : Input frequency
- * @return Nothing
- */
-void CLOCK_SetFLASHAccessCyclesForFreq(uint32_t iFreq);
-/**
- * @brief Initialize the external osc clock to given frequency.
- * @param iFreq : Desired frequency (must be equal to exact rate in Hz)
- * @return returns success or fail status.
- */
-status_t CLOCK_SetupExtClocking(uint32_t iFreq);
-/**
- * @brief Initialize the I2S MCLK clock to given frequency.
- * @param iFreq : Desired frequency (must be equal to exact rate in Hz)
- * @return returns success or fail status.
- */
-status_t CLOCK_SetupI2SMClkClocking(uint32_t iFreq);
-/**
- * @brief Initialize the PLU CLKIN clock to given frequency.
- * @param iFreq : Desired frequency (must be equal to exact rate in Hz)
- * @return returns success or fail status.
- */
-status_t CLOCK_SetupPLUClkInClocking(uint32_t iFreq);
-/**
- * @brief Configure the clock selection muxes.
- * @param connection : Clock to be configured.
- * @return Nothing
- */
-void CLOCK_AttachClk(clock_attach_id_t connection);
-/**
- * @brief Get the actual clock attach id.
- * This fuction uses the offset in input attach id, then it reads the actual source value in
- * the register and combine the offset to obtain an actual attach id.
- * @param attachId : Clock attach id to get.
- * @return Clock source value.
- */
-clock_attach_id_t CLOCK_GetClockAttachId(clock_attach_id_t attachId);
-/**
- * @brief Setup peripheral clock dividers.
- * @param div_name : Clock divider name
- * @param divided_by_value: Value to be divided
- * @param reset : Whether to reset the divider counter.
- * @return Nothing
- */
-void CLOCK_SetClkDiv(clock_div_name_t div_name, uint32_t divided_by_value, bool reset);
-/**
- * @brief Setup rtc 1khz clock divider.
- * @param divided_by_value: Value to be divided
- * @return Nothing
- */
-void CLOCK_SetRtc1khzClkDiv(uint32_t divided_by_value);
-/**
- * @brief Setup rtc 1hz clock divider.
- * @param divided_by_value: Value to be divided
- * @return Nothing
- */
-void CLOCK_SetRtc1hzClkDiv(uint32_t divided_by_value);
-
-/**
- * @brief Set the flexcomm output frequency.
- * @param id : flexcomm instance id
- * freq : output frequency
- * @return 0 : the frequency range is out of range.
- * 1 : switch successfully.
- */
-uint32_t CLOCK_SetFlexCommClock(uint32_t id, uint32_t freq);
-
-/*! @brief Return Frequency of flexcomm input clock
- * @param id : flexcomm instance id
- * @return Frequency value
- */
-uint32_t CLOCK_GetFlexCommInputClock(uint32_t id);
-
-/*! @brief Return Frequency of selected clock
- * @return Frequency of selected clock
- */
-uint32_t CLOCK_GetFreq(clock_name_t clockName);
-/*! @brief Return Frequency of FRO 12MHz
- * @return Frequency of FRO 12MHz
- */
-uint32_t CLOCK_GetFro12MFreq(void);
-/*! @brief Return Frequency of FRO 1MHz
- * @return Frequency of FRO 1MHz
- */
-uint32_t CLOCK_GetFro1MFreq(void);
-/*! @brief Return Frequency of ClockOut
- * @return Frequency of ClockOut
- */
-uint32_t CLOCK_GetClockOutClkFreq(void);
-/*! @brief Return Frequency of Adc Clock
- * @return Frequency of Adc.
- */
-uint32_t CLOCK_GetAdcClkFreq(void);
-/*! @brief Return Frequency of Usb0 Clock
- * @return Frequency of Usb0 Clock.
- */
-uint32_t CLOCK_GetUsb0ClkFreq(void);
-/*! @brief Return Frequency of Usb1 Clock
- * @return Frequency of Usb1 Clock.
- */
-uint32_t CLOCK_GetUsb1ClkFreq(void);
-/*! @brief Return Frequency of MClk Clock
- * @return Frequency of MClk Clock.
- */
-uint32_t CLOCK_GetMclkClkFreq(void);
-/*! @brief Return Frequency of SCTimer Clock
- * @return Frequency of SCTimer Clock.
- */
-uint32_t CLOCK_GetSctClkFreq(void);
-/*! @brief Return Frequency of SDIO Clock
- * @return Frequency of SDIO Clock.
- */
-uint32_t CLOCK_GetSdioClkFreq(void);
-/*! @brief Return Frequency of External Clock
- * @return Frequency of External Clock. If no external clock is used returns 0.
- */
-uint32_t CLOCK_GetExtClkFreq(void);
-/*! @brief Return Frequency of Watchdog
- * @return Frequency of Watchdog
- */
-uint32_t CLOCK_GetWdtClkFreq(void);
-/*! @brief Return Frequency of High-Freq output of FRO
- * @return Frequency of High-Freq output of FRO
- */
-uint32_t CLOCK_GetFroHfFreq(void);
-/*! @brief Return Frequency of PLL
- * @return Frequency of PLL
- */
-uint32_t CLOCK_GetPll0OutFreq(void);
-/*! @brief Return Frequency of USB PLL
- * @return Frequency of PLL
- */
-uint32_t CLOCK_GetPll1OutFreq(void);
-/*! @brief Return Frequency of 32kHz osc
- * @return Frequency of 32kHz osc
- */
-uint32_t CLOCK_GetOsc32KFreq(void);
-/*! @brief Return Frequency of Core System
- * @return Frequency of Core System
- */
-uint32_t CLOCK_GetCoreSysClkFreq(void);
-/*! @brief Return Frequency of I2S MCLK Clock
- * @return Frequency of I2S MCLK Clock
- */
-uint32_t CLOCK_GetI2SMClkFreq(void);
-/*! @brief Return Frequency of PLU CLKIN Clock
- * @return Frequency of PLU CLKIN Clock
- */
-uint32_t CLOCK_GetPLUClkInFreq(void);
-/*! @brief Return Frequency of FlexComm Clock
- * @return Frequency of FlexComm Clock
- */
-uint32_t CLOCK_GetFlexCommClkFreq(uint32_t id);
-/*! @brief Return Frequency of High speed SPI Clock
- * @return Frequency of High speed SPI Clock
- */
-uint32_t CLOCK_GetHsLspiClkFreq(void);
-/*! @brief Return Frequency of CTimer functional Clock
- * @return Frequency of CTimer functional Clock
- */
-uint32_t CLOCK_GetCTimerClkFreq(uint32_t id);
-/*! @brief Return Frequency of SystickClock
- * @return Frequency of Systick Clock
- */
-uint32_t CLOCK_GetSystickClkFreq(uint32_t id);
-
-/*! @brief Return PLL0 input clock rate
- * @return PLL0 input clock rate
- */
-uint32_t CLOCK_GetPLL0InClockRate(void);
-
-/*! @brief Return PLL1 input clock rate
- * @return PLL1 input clock rate
- */
-uint32_t CLOCK_GetPLL1InClockRate(void);
-
-/*! @brief Return PLL0 output clock rate
- * @param recompute : Forces a PLL rate recomputation if true
- * @return PLL0 output clock rate
- * @note The PLL rate is cached in the driver in a variable as
- * the rate computation function can take some time to perform. It
- * is recommended to use 'false' with the 'recompute' parameter.
- */
-uint32_t CLOCK_GetPLL0OutClockRate(bool recompute);
-
-/*! @brief Enables and disables PLL0 bypass mode
- * @brief bypass : true to bypass PLL0 (PLL0 output = PLL0 input, false to disable bypass
- * @return PLL0 output clock rate
- */
-__STATIC_INLINE void CLOCK_SetBypassPLL0(bool bypass)
-{
- if (bypass)
- {
- SYSCON->PLL0CTRL |= (1UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT);
- }
- else
- {
- SYSCON->PLL0CTRL &= ~(1UL << SYSCON_PLL0CTRL_BYPASSPLL_SHIFT);
- }
-}
-
-/*! @brief Enables and disables PLL1 bypass mode
- * @brief bypass : true to bypass PLL1 (PLL1 output = PLL1 input, false to disable bypass
- * @return PLL1 output clock rate
- */
-__STATIC_INLINE void CLOCK_SetBypassPLL1(bool bypass)
-{
- if (bypass)
- {
- SYSCON->PLL1CTRL |= (1UL << SYSCON_PLL1CTRL_BYPASSPLL_SHIFT);
- }
- else
- {
- SYSCON->PLL1CTRL &= ~(1UL << SYSCON_PLL1CTRL_BYPASSPLL_SHIFT);
- }
-}
-
-/*! @brief Check if PLL is locked or not
- * @return true if the PLL is locked, false if not locked
- */
-__STATIC_INLINE bool CLOCK_IsPLL0Locked(void)
-{
- return (bool)((SYSCON->PLL0STAT & SYSCON_PLL0STAT_LOCK_MASK) != 0UL);
-}
-
-/*! @brief Check if PLL1 is locked or not
- * @return true if the PLL1 is locked, false if not locked
- */
-__STATIC_INLINE bool CLOCK_IsPLL1Locked(void)
-{
- return (bool)((SYSCON->PLL1STAT & SYSCON_PLL1STAT_LOCK_MASK) != 0UL);
-}
-
-/*! @brief Store the current PLL0 rate
- * @param rate: Current rate of the PLL0
- * @return Nothing
- **/
-void CLOCK_SetStoredPLL0ClockRate(uint32_t rate);
-
-/*! @brief PLL configuration structure flags for 'flags' field
- * These flags control how the PLL configuration function sets up the PLL setup structure.<br>
- *
- * When the PLL_CONFIGFLAG_USEINRATE flag is selected, the 'InputRate' field in the
- * configuration structure must be assigned with the expected PLL frequency. If the
- * PLL_CONFIGFLAG_USEINRATE is not used, 'InputRate' is ignored in the configuration
- * function and the driver will determine the PLL rate from the currently selected
- * PLL source. This flag might be used to configure the PLL input clock more accurately
- * when using the WDT oscillator or a more dyanmic CLKIN source.<br>
- *
- * When the PLL_CONFIGFLAG_FORCENOFRACT flag is selected, the PLL hardware for the
- * automatic bandwidth selection, Spread Spectrum (SS) support, and fractional M-divider
- * are not used.<br>
- */
-#define PLL_CONFIGFLAG_USEINRATE (1U << 0U) /*!< Flag to use InputRate in PLL configuration structure for setup */
-#define PLL_CONFIGFLAG_FORCENOFRACT (1U << 2U)
-/*!< Force non-fractional output mode, PLL output will not use the fractional, automatic bandwidth, or SS hardware */
-
-/*! @brief PLL Spread Spectrum (SS) Programmable modulation frequency
- * See (MF) field in the PLL0SSCG1 register in the UM.
- */
-typedef enum _ss_progmodfm
-{
- kSS_MF_512 = (0 << 20), /*!< Nss = 512 (fm ? 3.9 - 7.8 kHz) */
- kSS_MF_384 = (1 << 20), /*!< Nss ?= 384 (fm ? 5.2 - 10.4 kHz) */
- kSS_MF_256 = (2 << 20), /*!< Nss = 256 (fm ? 7.8 - 15.6 kHz) */
- kSS_MF_128 = (3 << 20), /*!< Nss = 128 (fm ? 15.6 - 31.3 kHz) */
- kSS_MF_64 = (4 << 20), /*!< Nss = 64 (fm ? 32.3 - 64.5 kHz) */
- kSS_MF_32 = (5 << 20), /*!< Nss = 32 (fm ? 62.5- 125 kHz) */
- kSS_MF_24 = (6 << 20), /*!< Nss ?= 24 (fm ? 83.3- 166.6 kHz) */
- kSS_MF_16 = (7 << 20) /*!< Nss = 16 (fm ? 125- 250 kHz) */
-} ss_progmodfm_t;
-
-/*! @brief PLL Spread Spectrum (SS) Programmable frequency modulation depth
- * See (MR) field in the PLL0SSCG1 register in the UM.
- */
-typedef enum _ss_progmoddp
-{
- kSS_MR_K0 = (0 << 23), /*!< k = 0 (no spread spectrum) */
- kSS_MR_K1 = (1 << 23), /*!< k = 1 */
- kSS_MR_K1_5 = (2 << 23), /*!< k = 1.5 */
- kSS_MR_K2 = (3 << 23), /*!< k = 2 */
- kSS_MR_K3 = (4 << 23), /*!< k = 3 */
- kSS_MR_K4 = (5 << 23), /*!< k = 4 */
- kSS_MR_K6 = (6 << 23), /*!< k = 6 */
- kSS_MR_K8 = (7 << 23) /*!< k = 8 */
-} ss_progmoddp_t;
-
-/*! @brief PLL Spread Spectrum (SS) Modulation waveform control
- * See (MC) field in the PLL0SSCG1 register in the UM.<br>
- * Compensation for low pass filtering of the PLL to get a triangular
- * modulation at the output of the PLL, giving a flat frequency spectrum.
- */
-typedef enum _ss_modwvctrl
-{
- kSS_MC_NOC = (0 << 26), /*!< no compensation */
- kSS_MC_RECC = (2 << 26), /*!< recommended setting */
- kSS_MC_MAXC = (3 << 26), /*!< max. compensation */
-} ss_modwvctrl_t;
-
-/*! @brief PLL configuration structure
- *
- * This structure can be used to configure the settings for a PLL
- * setup structure. Fill in the desired configuration for the PLL
- * and call the PLL setup function to fill in a PLL setup structure.
- */
-typedef struct _pll_config
-{
- uint32_t desiredRate; /*!< Desired PLL rate in Hz */
- uint32_t inputRate; /*!< PLL input clock in Hz, only used if PLL_CONFIGFLAG_USEINRATE flag is set */
- uint32_t flags; /*!< PLL configuration flags, Or'ed value of PLL_CONFIGFLAG_* definitions */
- ss_progmodfm_t ss_mf; /*!< SS Programmable modulation frequency, only applicable when not using
- PLL_CONFIGFLAG_FORCENOFRACT flag */
- ss_progmoddp_t ss_mr; /*!< SS Programmable frequency modulation depth, only applicable when not using
- PLL_CONFIGFLAG_FORCENOFRACT flag */
- ss_modwvctrl_t
- ss_mc; /*!< SS Modulation waveform control, only applicable when not using PLL_CONFIGFLAG_FORCENOFRACT flag */
- bool mfDither; /*!< false for fixed modulation frequency or true for dithering, only applicable when not using
- PLL_CONFIGFLAG_FORCENOFRACT flag */
-
-} pll_config_t;
-
-/*! @brief PLL setup structure flags for 'flags' field
- * These flags control how the PLL setup function sets up the PLL
- */
-#define PLL_SETUPFLAG_POWERUP (1U << 0U) /*!< Setup will power on the PLL after setup */
-#define PLL_SETUPFLAG_WAITLOCK (1U << 1U) /*!< Setup will wait for PLL lock, implies the PLL will be pwoered on */
-#define PLL_SETUPFLAG_ADGVOLT (1U << 2U) /*!< Optimize system voltage for the new PLL rate */
-#define PLL_SETUPFLAG_USEFEEDBACKDIV2 (1U << 3U) /*!< Use feedback divider by 2 in divider path */
-
-/*! @brief PLL0 setup structure
- * This structure can be used to pre-build a PLL setup configuration
- * at run-time and quickly set the PLL to the configuration. It can be
- * populated with the PLL setup function. If powering up or waiting
- * for PLL lock, the PLL input clock source should be configured prior
- * to PLL setup.
- */
-typedef struct _pll_setup
-{
- uint32_t pllctrl; /*!< PLL control register PLL0CTRL */
- uint32_t pllndec; /*!< PLL NDEC register PLL0NDEC */
- uint32_t pllpdec; /*!< PLL PDEC register PLL0PDEC */
- uint32_t pllmdec; /*!< PLL MDEC registers PLL0PDEC */
- uint32_t pllsscg[2]; /*!< PLL SSCTL registers PLL0SSCG*/
- uint32_t pllRate; /*!< Acutal PLL rate */
- uint32_t flags; /*!< PLL setup flags, Or'ed value of PLL_SETUPFLAG_* definitions */
-} pll_setup_t;
-
-/*! @brief PLL status definitions
- */
-typedef enum _pll_error
-{
- kStatus_PLL_Success = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< PLL operation was successful */
- kStatus_PLL_OutputTooLow = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< PLL output rate request was too low */
- kStatus_PLL_OutputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< PLL output rate request was too high */
- kStatus_PLL_InputTooLow = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< PLL input rate is too low */
- kStatus_PLL_InputTooHigh = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< PLL input rate is too high */
- kStatus_PLL_OutsideIntLimit = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Requested output rate isn't possible */
- kStatus_PLL_CCOTooLow = MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Requested CCO rate isn't possible */
- kStatus_PLL_CCOTooHigh = MAKE_STATUS(kStatusGroup_Generic, 7) /*!< Requested CCO rate isn't possible */
-} pll_error_t;
-
-/*! @brief USB FS clock source definition. */
-typedef enum _clock_usbfs_src
-{
- kCLOCK_UsbfsSrcFro = (uint32_t)kCLOCK_FroHf, /*!< Use FRO 96 MHz. */
- kCLOCK_UsbfsSrcPll0 = (uint32_t)kCLOCK_Pll0Out, /*!< Use PLL0 output. */
- kCLOCK_UsbfsSrcMainClock = (uint32_t)kCLOCK_CoreSysClk, /*!< Use Main clock. */
- kCLOCK_UsbfsSrcPll1 = (uint32_t)kCLOCK_Pll1Out, /*!< Use PLL1 clock. */
-
- kCLOCK_UsbfsSrcNone =
- SYSCON_USB0CLKSEL_SEL(7) /*!<this may be selected in order to reduce power when no output is needed. */
-} clock_usbfs_src_t;
-
-/*! @brief USBhs clock source definition. */
-typedef enum _clock_usbhs_src
-{
- kCLOCK_UsbSrcUnused = 0xFFFFFFFFU, /*!< Used when the function does not
- care the clock source. */
-} clock_usbhs_src_t;
-
-/*! @brief Source of the USB HS PHY. */
-typedef enum _clock_usb_phy_src
-{
- kCLOCK_UsbPhySrcExt = 0U, /*!< Use external crystal. */
-} clock_usb_phy_src_t;
-
-/*! @brief Return PLL0 output clock rate from setup structure
- * @param pSetup : Pointer to a PLL setup structure
- * @return System PLL output clock rate the setup structure will generate
- */
-uint32_t CLOCK_GetPLL0OutFromSetup(pll_setup_t *pSetup);
-
-/*! @brief Set PLL0 output based on the passed PLL setup data
- * @param pControl : Pointer to populated PLL control structure to generate setup with
- * @param pSetup : Pointer to PLL setup structure to be filled
- * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
- * @note Actual frequency for setup may vary from the desired frequency based on the
- * accuracy of input clocks, rounding, non-fractional PLL mode, etc.
- */
-pll_error_t CLOCK_SetupPLL0Data(pll_config_t *pControl, pll_setup_t *pSetup);
-
-/*! @brief Set PLL output from PLL setup structure (precise frequency)
- * @param pSetup : Pointer to populated PLL setup structure
- * @param flagcfg : Flag configuration for PLL config structure
- * @return PLL_ERROR_SUCCESS on success, or PLL setup error code
- * @note This function will power off the PLL, setup the PLL with the
- * new setup data, and then optionally powerup the PLL, wait for PLL lock,
- * and adjust system voltages to the new PLL rate. The function will not
- * alter any source clocks (ie, main systen clock) that may use the PLL,
- * so these should be setup prior to and after exiting the function.
- */
-pll_error_t CLOCK_SetupPLL0Prec(pll_setup_t *pSetup, uint32_t flagcfg);
-
-/**
- * @brief Set PLL output from PLL setup structure (precise frequency)
- * @param pSetup : Pointer to populated PLL setup structure
- * @return kStatus_PLL_Success on success, or PLL setup error code
- * @note This function will power off the PLL, setup the PLL with the
- * new setup data, and then optionally powerup the PLL, wait for PLL lock,
- * and adjust system voltages to the new PLL rate. The function will not
- * alter any source clocks (ie, main systen clock) that may use the PLL,
- * so these should be setup prior to and after exiting the function.
- */
-pll_error_t CLOCK_SetPLL0Freq(const pll_setup_t *pSetup);
-
-/**
- * @brief Set PLL output from PLL setup structure (precise frequency)
- * @param pSetup : Pointer to populated PLL setup structure
- * @return kStatus_PLL_Success on success, or PLL setup error code
- * @note This function will power off the PLL, setup the PLL with the
- * new setup data, and then optionally powerup the PLL, wait for PLL lock,
- * and adjust system voltages to the new PLL rate. The function will not
- * alter any source clocks (ie, main systen clock) that may use the PLL,
- * so these should be setup prior to and after exiting the function.
- */
-pll_error_t CLOCK_SetPLL1Freq(const pll_setup_t *pSetup);
-
-/*! @brief Set PLL0 output based on the multiplier and input frequency
- * @param multiply_by : multiplier
- * @param input_freq : Clock input frequency of the PLL
- * @return Nothing
- * @note Unlike the Chip_Clock_SetupSystemPLLPrec() function, this
- * function does not disable or enable PLL power, wait for PLL lock,
- * or adjust system voltages. These must be done in the application.
- * The function will not alter any source clocks (ie, main systen clock)
- * that may use the PLL, so these should be setup prior to and after
- * exiting the function.
- */
-void CLOCK_SetupPLL0Mult(uint32_t multiply_by, uint32_t input_freq);
-
-/*! @brief Disable USB clock.
- *
- * Disable USB clock.
- */
-static inline void CLOCK_DisableUsbDevicefs0Clock(clock_ip_name_t clk)
-{
- CLOCK_DisableClock(clk);
-}
-
-/*! @brief Enable USB Device FS clock.
- * @param src : clock source
- * @param freq: clock frequency
- * Enable USB Device Full Speed clock.
- */
-bool CLOCK_EnableUsbfs0DeviceClock(clock_usbfs_src_t src, uint32_t freq);
-
-/*! @brief Enable USB HOST FS clock.
- * @param src : clock source
- * @param freq: clock frequency
- * Enable USB HOST Full Speed clock.
- */
-bool CLOCK_EnableUsbfs0HostClock(clock_usbfs_src_t src, uint32_t freq);
-
-/*! @brief Enable USB phy clock.
- * Enable USB phy clock.
- */
-bool CLOCK_EnableUsbhs0PhyPllClock(clock_usb_phy_src_t src, uint32_t freq);
-
-/*! @brief Enable USB Device HS clock.
- * Enable USB Device High Speed clock.
- */
-bool CLOCK_EnableUsbhs0DeviceClock(clock_usbhs_src_t src, uint32_t freq);
-
-/*! @brief Enable USB HOST HS clock.
- * Enable USB HOST High Speed clock.
- */
-bool CLOCK_EnableUsbhs0HostClock(clock_usbhs_src_t src, uint32_t freq);
-
-#if defined(__cplusplus)
-}
-#endif /* __cplusplus */
-
-/*! @} */
-
-#endif /* _FSL_CLOCK_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.c
deleted file mode 100755
index e0233dcfc..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2018 NXP
- * All rights reserved.
- *
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_common.h"
-#define SDK_MEM_MAGIC_NUMBER 12345U
-
-typedef struct _mem_align_control_block
-{
- uint16_t identifier; /*!< Identifier for the memory control block. */
- uint16_t offset; /*!< offset from aligned address to real address */
-} mem_align_cb_t;
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.common"
-#endif
-
-#ifndef __GIC_PRIO_BITS
-#if defined(ENABLE_RAM_VECTOR_TABLE)
-uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
-{
-/* Addresses for VECTOR_TABLE and VECTOR_RAM come from the linker file */
-#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
- extern uint32_t Image$$VECTOR_ROM$$Base[];
- extern uint32_t Image$$VECTOR_RAM$$Base[];
- extern uint32_t Image$$RW_m_data$$Base[];
-
-#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
-#define __VECTOR_RAM Image$$VECTOR_RAM$$Base
-#define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$RW_m_data$$Base - (uint32_t)Image$$VECTOR_RAM$$Base))
-#elif defined(__ICCARM__)
- extern uint32_t __RAM_VECTOR_TABLE_SIZE[];
- extern uint32_t __VECTOR_TABLE[];
- extern uint32_t __VECTOR_RAM[];
-#elif defined(__GNUC__)
- extern uint32_t __VECTOR_TABLE[];
- extern uint32_t __VECTOR_RAM[];
- extern uint32_t __RAM_VECTOR_TABLE_SIZE_BYTES[];
- uint32_t __RAM_VECTOR_TABLE_SIZE = (uint32_t)(__RAM_VECTOR_TABLE_SIZE_BYTES);
-#endif /* defined(__CC_ARM) || defined(__ARMCC_VERSION) */
- uint32_t n;
- uint32_t ret;
- uint32_t irqMaskValue;
-
- irqMaskValue = DisableGlobalIRQ();
- if (SCB->VTOR != (uint32_t)__VECTOR_RAM)
- {
- /* Copy the vector table from ROM to RAM */
- for (n = 0; n < ((uint32_t)__RAM_VECTOR_TABLE_SIZE) / sizeof(uint32_t); n++)
- {
- __VECTOR_RAM[n] = __VECTOR_TABLE[n];
- }
- /* Point the VTOR to the position of vector table */
- SCB->VTOR = (uint32_t)__VECTOR_RAM;
- }
-
- ret = __VECTOR_RAM[irq + 16];
- /* make sure the __VECTOR_RAM is noncachable */
- __VECTOR_RAM[irq + 16] = irqHandler;
-
- EnableGlobalIRQ(irqMaskValue);
-
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-
- return ret;
-}
-#endif /* ENABLE_RAM_VECTOR_TABLE. */
-#endif /* __GIC_PRIO_BITS. */
-
-#if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
-#if !(defined(FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS) && FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS)
-
-void EnableDeepSleepIRQ(IRQn_Type interrupt)
-{
- uint32_t intNumber = (uint32_t)interrupt;
-
- uint32_t index = 0;
-
- while (intNumber >= 32u)
- {
- index++;
- intNumber -= 32u;
- }
-
- SYSCON->STARTERSET[index] = 1u << intNumber;
- EnableIRQ(interrupt); /* also enable interrupt at NVIC */
-}
-
-void DisableDeepSleepIRQ(IRQn_Type interrupt)
-{
- uint32_t intNumber = (uint32_t)interrupt;
-
- DisableIRQ(interrupt); /* also disable interrupt at NVIC */
- uint32_t index = 0;
-
- while (intNumber >= 32u)
- {
- index++;
- intNumber -= 32u;
- }
-
- SYSCON->STARTERCLR[index] = 1u << intNumber;
-}
-#endif /* FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS */
-#endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
-
-void *SDK_Malloc(size_t size, size_t alignbytes)
-{
- mem_align_cb_t *p_cb = NULL;
- uint32_t alignedsize = SDK_SIZEALIGN(size, alignbytes) + alignbytes + sizeof(mem_align_cb_t);
- void *p_align_addr, *p_addr = malloc(alignedsize);
-
- if (!p_addr)
- {
- return NULL;
- }
-
- p_align_addr = (void *)SDK_SIZEALIGN((uint32_t)p_addr + sizeof(mem_align_cb_t), alignbytes);
-
- p_cb = (mem_align_cb_t *)((uint32_t)p_align_addr - 4U);
- p_cb->identifier = SDK_MEM_MAGIC_NUMBER;
- p_cb->offset = (uint32_t)p_align_addr - (uint32_t)p_addr;
-
- return (void *)p_align_addr;
-}
-
-void SDK_Free(void *ptr)
-{
- mem_align_cb_t *p_cb = (mem_align_cb_t *)((uint32_t)ptr - 4U);
-
- if (p_cb->identifier != SDK_MEM_MAGIC_NUMBER)
- {
- return;
- }
-
- free((void *)((uint32_t)ptr - p_cb->offset));
-}
-
-/*!
- * @brief Delay function bases on while loop, every loop includes three instructions.
- *
- * @param count Counts of loop needed for dalay.
- */
-#ifndef __XCC__
-#if defined(__CC_ARM) /* This macro is arm v5 specific */
-/* clang-format off */
-__ASM static void DelayLoop(uint32_t count)
-{
-loop
- SUBS R0, R0, #1
- CMP R0, #0
- BNE loop
- BX LR
-}
-/* clang-format on */
-#elif defined(__ARMCC_VERSION) || defined(__ICCARM__) || defined(__GNUC__)
-/* Cortex-M0 has a smaller instruction set, SUBS isn't supported in thumb-16 mode reported from __GNUC__ compiler,
- * use SUB and CMP here for compatibility */
-static void DelayLoop(uint32_t count)
-{
- __ASM volatile(" MOV R0, %0" : : "r"(count));
- __ASM volatile(
- "loop: \n"
-#if defined(__GNUC__)
- " SUB R0, R0, #1 \n"
-#else
- " SUBS R0, R0, #1 \n"
-#endif
- " CMP R0, #0 \n"
-
- " BNE loop \n");
-}
-#endif /* defined(__CC_ARM) */
-
-/*!
- * @brief Delay at least for some time.
- * Please note that, this API uses while loop for delay, different run-time environments make the time not precise,
- * if precise delay count was needed, please implement a new delay function with hardware timer.
- *
- * @param delay_us Delay time in unit of microsecond.
- * @param coreClock_Hz Core clock frequency with Hz.
- */
-void SDK_DelayAtLeastUs(uint32_t delay_us, uint32_t coreClock_Hz)
-{
- assert(0U != delay_us);
- uint64_t count = USEC_TO_COUNT(delay_us, coreClock_Hz);
- assert(count <= UINT32_MAX);
-
- /* Divide value may be different in various environment to ensure delay is precise.
- * Every loop count includes three instructions, due to Cortex-M7 sometimes executes
- * two instructions in one period, through test here set divide 2. Other M cores use
- * divide 4. By the way, divide 2 or 4 could let odd count lost precision, but it does
- * not matter because other instructions outside while loop is enough to fill the time.
- */
-#if (__CORTEX_M == 7)
- count = count / 2;
-#else
- count = count / 4;
-#endif
- DelayLoop(count);
-}
-#endif
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.h
deleted file mode 100755
index a24fe1c2d..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_common.h
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _FSL_COMMON_H_
-#define _FSL_COMMON_H_
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-
-#if defined(__ICCARM__)
-#include <stddef.h>
-#endif
-
-#include "fsl_device_registers.h"
-
-/*!
- * @addtogroup ksdk_common
- * @{
- */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/*! @brief Construct a status code value from a group and code number. */
-#define MAKE_STATUS(group, code) ((((group)*100) + (code)))
-
-/*! @brief Construct the version number for drivers. */
-#define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
-
-/*! @name Driver version */
-/*@{*/
-/*! @brief common driver version 2.2.0. */
-#define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 2, 0))
-/*@}*/
-
-/* Debug console type definition. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_NONE 0U /*!< No debug console. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_UART 1U /*!< Debug console based on UART. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_LPUART 2U /*!< Debug console based on LPUART. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_LPSCI 3U /*!< Debug console based on LPSCI. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_USBCDC 4U /*!< Debug console based on USBCDC. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_FLEXCOMM 5U /*!< Debug console based on FLEXCOMM. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_IUART 6U /*!< Debug console based on i.MX UART. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_VUSART 7U /*!< Debug console based on LPC_VUSART. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_MINI_USART 8U /*!< Debug console based on LPC_USART. */
-#define DEBUG_CONSOLE_DEVICE_TYPE_SWO 9U /*!< Debug console based on SWO. */
-
-/*! @brief Status group numbers. */
-enum _status_groups
-{
- kStatusGroup_Generic = 0, /*!< Group number for generic status codes. */
- kStatusGroup_FLASH = 1, /*!< Group number for FLASH status codes. */
- kStatusGroup_LPSPI = 4, /*!< Group number for LPSPI status codes. */
- kStatusGroup_FLEXIO_SPI = 5, /*!< Group number for FLEXIO SPI status codes. */
- kStatusGroup_DSPI = 6, /*!< Group number for DSPI status codes. */
- kStatusGroup_FLEXIO_UART = 7, /*!< Group number for FLEXIO UART status codes. */
- kStatusGroup_FLEXIO_I2C = 8, /*!< Group number for FLEXIO I2C status codes. */
- kStatusGroup_LPI2C = 9, /*!< Group number for LPI2C status codes. */
- kStatusGroup_UART = 10, /*!< Group number for UART status codes. */
- kStatusGroup_I2C = 11, /*!< Group number for UART status codes. */
- kStatusGroup_LPSCI = 12, /*!< Group number for LPSCI status codes. */
- kStatusGroup_LPUART = 13, /*!< Group number for LPUART status codes. */
- kStatusGroup_SPI = 14, /*!< Group number for SPI status code.*/
- kStatusGroup_XRDC = 15, /*!< Group number for XRDC status code.*/
- kStatusGroup_SEMA42 = 16, /*!< Group number for SEMA42 status code.*/
- kStatusGroup_SDHC = 17, /*!< Group number for SDHC status code */
- kStatusGroup_SDMMC = 18, /*!< Group number for SDMMC status code */
- kStatusGroup_SAI = 19, /*!< Group number for SAI status code */
- kStatusGroup_MCG = 20, /*!< Group number for MCG status codes. */
- kStatusGroup_SCG = 21, /*!< Group number for SCG status codes. */
- kStatusGroup_SDSPI = 22, /*!< Group number for SDSPI status codes. */
- kStatusGroup_FLEXIO_I2S = 23, /*!< Group number for FLEXIO I2S status codes */
- kStatusGroup_FLEXIO_MCULCD = 24, /*!< Group number for FLEXIO LCD status codes */
- kStatusGroup_FLASHIAP = 25, /*!< Group number for FLASHIAP status codes */
- kStatusGroup_FLEXCOMM_I2C = 26, /*!< Group number for FLEXCOMM I2C status codes */
- kStatusGroup_I2S = 27, /*!< Group number for I2S status codes */
- kStatusGroup_IUART = 28, /*!< Group number for IUART status codes */
- kStatusGroup_CSI = 29, /*!< Group number for CSI status codes */
- kStatusGroup_MIPI_DSI = 30, /*!< Group number for MIPI DSI status codes */
- kStatusGroup_SDRAMC = 35, /*!< Group number for SDRAMC status codes. */
- kStatusGroup_POWER = 39, /*!< Group number for POWER status codes. */
- kStatusGroup_ENET = 40, /*!< Group number for ENET status codes. */
- kStatusGroup_PHY = 41, /*!< Group number for PHY status codes. */
- kStatusGroup_TRGMUX = 42, /*!< Group number for TRGMUX status codes. */
- kStatusGroup_SMARTCARD = 43, /*!< Group number for SMARTCARD status codes. */
- kStatusGroup_LMEM = 44, /*!< Group number for LMEM status codes. */
- kStatusGroup_QSPI = 45, /*!< Group number for QSPI status codes. */
- kStatusGroup_DMA = 50, /*!< Group number for DMA status codes. */
- kStatusGroup_EDMA = 51, /*!< Group number for EDMA status codes. */
- kStatusGroup_DMAMGR = 52, /*!< Group number for DMAMGR status codes. */
- kStatusGroup_FLEXCAN = 53, /*!< Group number for FlexCAN status codes. */
- kStatusGroup_LTC = 54, /*!< Group number for LTC status codes. */
- kStatusGroup_FLEXIO_CAMERA = 55, /*!< Group number for FLEXIO CAMERA status codes. */
- kStatusGroup_LPC_SPI = 56, /*!< Group number for LPC_SPI status codes. */
- kStatusGroup_LPC_USART = 57, /*!< Group number for LPC_USART status codes. */
- kStatusGroup_DMIC = 58, /*!< Group number for DMIC status codes. */
- kStatusGroup_SDIF = 59, /*!< Group number for SDIF status codes.*/
- kStatusGroup_SPIFI = 60, /*!< Group number for SPIFI status codes. */
- kStatusGroup_OTP = 61, /*!< Group number for OTP status codes. */
- kStatusGroup_MCAN = 62, /*!< Group number for MCAN status codes. */
- kStatusGroup_CAAM = 63, /*!< Group number for CAAM status codes. */
- kStatusGroup_ECSPI = 64, /*!< Group number for ECSPI status codes. */
- kStatusGroup_USDHC = 65, /*!< Group number for USDHC status codes.*/
- kStatusGroup_LPC_I2C = 66, /*!< Group number for LPC_I2C status codes.*/
- kStatusGroup_DCP = 67, /*!< Group number for DCP status codes.*/
- kStatusGroup_MSCAN = 68, /*!< Group number for MSCAN status codes.*/
- kStatusGroup_ESAI = 69, /*!< Group number for ESAI status codes. */
- kStatusGroup_FLEXSPI = 70, /*!< Group number for FLEXSPI status codes. */
- kStatusGroup_MMDC = 71, /*!< Group number for MMDC status codes. */
- kStatusGroup_PDM = 72, /*!< Group number for MIC status codes. */
- kStatusGroup_SDMA = 73, /*!< Group number for SDMA status codes. */
- kStatusGroup_ICS = 74, /*!< Group number for ICS status codes. */
- kStatusGroup_SPDIF = 75, /*!< Group number for SPDIF status codes. */
- kStatusGroup_LPC_MINISPI = 76, /*!< Group number for LPC_MINISPI status codes. */
- kStatusGroup_HASHCRYPT = 77, /*!< Group number for Hashcrypt status codes */
- kStatusGroup_LPC_SPI_SSP = 78, /*!< Group number for LPC_SPI_SSP status codes. */
- kStatusGroup_I3C = 79, /*!< Group number for I3C status codes */
- kStatusGroup_LPC_I2C_1 = 97, /*!< Group number for LPC_I2C_1 status codes. */
- kStatusGroup_NOTIFIER = 98, /*!< Group number for NOTIFIER status codes. */
- kStatusGroup_DebugConsole = 99, /*!< Group number for debug console status codes. */
- kStatusGroup_SEMC = 100, /*!< Group number for SEMC status codes. */
- kStatusGroup_ApplicationRangeStart = 101, /*!< Starting number for application groups. */
- kStatusGroup_IAP = 102, /*!< Group number for IAP status codes */
-
- kStatusGroup_HAL_GPIO = 121, /*!< Group number for HAL GPIO status codes. */
- kStatusGroup_HAL_UART = 122, /*!< Group number for HAL UART status codes. */
- kStatusGroup_HAL_TIMER = 123, /*!< Group number for HAL TIMER status codes. */
- kStatusGroup_HAL_SPI = 124, /*!< Group number for HAL SPI status codes. */
- kStatusGroup_HAL_I2C = 125, /*!< Group number for HAL I2C status codes. */
- kStatusGroup_HAL_FLASH = 126, /*!< Group number for HAL FLASH status codes. */
- kStatusGroup_HAL_PWM = 127, /*!< Group number for HAL PWM status codes. */
- kStatusGroup_HAL_RNG = 128, /*!< Group number for HAL RNG status codes. */
- kStatusGroup_TIMERMANAGER = 135, /*!< Group number for TiMER MANAGER status codes. */
- kStatusGroup_SERIALMANAGER = 136, /*!< Group number for SERIAL MANAGER status codes. */
- kStatusGroup_LED = 137, /*!< Group number for LED status codes. */
- kStatusGroup_BUTTON = 138, /*!< Group number for BUTTON status codes. */
- kStatusGroup_EXTERN_EEPROM = 139, /*!< Group number for EXTERN EEPROM status codes. */
- kStatusGroup_SHELL = 140, /*!< Group number for SHELL status codes. */
- kStatusGroup_MEM_MANAGER = 141, /*!< Group number for MEM MANAGER status codes. */
- kStatusGroup_LIST = 142, /*!< Group number for List status codes. */
- kStatusGroup_OSA = 143, /*!< Group number for OSA status codes. */
- kStatusGroup_COMMON_TASK = 144, /*!< Group number for Common task status codes. */
- kStatusGroup_MSG = 145, /*!< Group number for messaging status codes. */
- kStatusGroup_SDK_OCOTP = 146, /*!< Group number for OCOTP status codes. */
- kStatusGroup_SDK_FLEXSPINOR = 147, /*!< Group number for FLEXSPINOR status codes.*/
- kStatusGroup_CODEC = 148, /*!< Group number for codec status codes. */
- kStatusGroup_ASRC = 149, /*!< Group number for codec status ASRC. */
- kStatusGroup_OTFAD = 150, /*!< Group number for codec status codes. */
-};
-
-/*! @brief Generic status return codes. */
-enum
-{
- kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0),
- kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1),
- kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2),
- kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3),
- kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4),
- kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5),
- kStatus_NoTransferInProgress = MAKE_STATUS(kStatusGroup_Generic, 6),
-};
-
-/*! @brief Type used for all status and error return values. */
-typedef int32_t status_t;
-
-/*
- * Macro guard for whether to use default weak IRQ implementation in drivers
- */
-#ifndef FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ
-#define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 1
-#endif
-
-/*! @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. */
-#if !defined(ARRAY_SIZE)
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
-
-/*! @name UINT16_MAX/UINT32_MAX value */
-/* @{ */
-#if !defined(UINT16_MAX)
-#define UINT16_MAX ((uint16_t)-1)
-#endif
-
-#if !defined(UINT32_MAX)
-#define UINT32_MAX ((uint32_t)-1)
-#endif
-/* @} */
-
-/*! @name Timer utilities */
-/* @{ */
-/*! Macro to convert a microsecond period to raw count value */
-#define USEC_TO_COUNT(us, clockFreqInHz) (uint64_t)(((uint64_t)(us) * (clockFreqInHz)) / 1000000U)
-/*! Macro to convert a raw count value to microsecond */
-#define COUNT_TO_USEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000000U / clockFreqInHz)
-
-/*! Macro to convert a millisecond period to raw count value */
-#define MSEC_TO_COUNT(ms, clockFreqInHz) (uint64_t)((uint64_t)ms * clockFreqInHz / 1000U)
-/*! Macro to convert a raw count value to millisecond */
-#define COUNT_TO_MSEC(count, clockFreqInHz) (uint64_t)((uint64_t)count * 1000U / clockFreqInHz)
-/* @} */
-
-/*! @name Alignment variable definition macros */
-/* @{ */
-#if (defined(__ICCARM__))
-/**
- * Workaround to disable MISRA C message suppress warnings for IAR compiler.
- * http://supp.iar.com/Support/?note=24725
- */
-_Pragma("diag_suppress=Pm120")
-#define SDK_PRAGMA(x) _Pragma(#x)
- _Pragma("diag_error=Pm120")
-/*! Macro to define a variable with alignbytes alignment */
-#define SDK_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
-/*! Macro to define a variable with L1 d-cache line size alignment */
-#if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
-#define SDK_L1DCACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L1DCACHE_LINESIZE_BYTE) var
-#endif
-/*! Macro to define a variable with L2 cache line size alignment */
-#if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
-#define SDK_L2CACHE_ALIGN(var) SDK_PRAGMA(data_alignment = FSL_FEATURE_L2CACHE_LINESIZE_BYTE) var
-#endif
-#elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
-/*! Macro to define a variable with alignbytes alignment */
-#define SDK_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var
-/*! Macro to define a variable with L1 d-cache line size alignment */
-#if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
-#define SDK_L1DCACHE_ALIGN(var) __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))) var
-#endif
-/*! Macro to define a variable with L2 cache line size alignment */
-#if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
-#define SDK_L2CACHE_ALIGN(var) __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))) var
-#endif
-#elif defined(__GNUC__)
-/*! Macro to define a variable with alignbytes alignment */
-#define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
-/*! Macro to define a variable with L1 d-cache line size alignment */
-#if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
-#define SDK_L1DCACHE_ALIGN(var) var __attribute__((aligned(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))
-#endif
-/*! Macro to define a variable with L2 cache line size alignment */
-#if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
-#define SDK_L2CACHE_ALIGN(var) var __attribute__((aligned(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)))
-#endif
-#else
-#error Toolchain not supported
-#define SDK_ALIGN(var, alignbytes) var
-#if defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
-#define SDK_L1DCACHE_ALIGN(var) var
-#endif
-#if defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
-#define SDK_L2CACHE_ALIGN(var) var
-#endif
-#endif
-
-/*! Macro to change a value to a given size aligned value */
-#define SDK_SIZEALIGN(var, alignbytes) \
- ((unsigned int)((var) + ((alignbytes)-1)) & (unsigned int)(~(unsigned int)((alignbytes)-1)))
-/* @} */
-
-/*! @name Non-cacheable region definition macros */
-/* For initialized non-zero non-cacheable variables, please using "AT_NONCACHEABLE_SECTION_INIT(var) ={xx};" or
- * "AT_NONCACHEABLE_SECTION_ALIGN_INIT(var) ={xx};" in your projects to define them, for zero-inited non-cacheable variables,
- * please using "AT_NONCACHEABLE_SECTION(var);" or "AT_NONCACHEABLE_SECTION_ALIGN(var);" to define them, these zero-inited variables
- * will be initialized to zero in system startup.
- */
-/* @{ */
-#if (defined(__ICCARM__))
-#if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
-#define AT_NONCACHEABLE_SECTION(var) var @"NonCacheable"
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable"
-#define AT_NONCACHEABLE_SECTION_INIT(var) var @"NonCacheable.init"
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var @"NonCacheable.init"
-#else
-#define AT_NONCACHEABLE_SECTION(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
-#define AT_NONCACHEABLE_SECTION_INIT(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_PRAGMA(data_alignment = alignbytes) var
-#endif
-#elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
-#if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
-#define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"), zero_init)) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
- __attribute__((section("NonCacheable"), zero_init)) __attribute__((aligned(alignbytes))) var
-#define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
- __attribute__((section("NonCacheable.init"))) __attribute__((aligned(alignbytes))) var
-#else
-#define AT_NONCACHEABLE_SECTION(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var
-#define AT_NONCACHEABLE_SECTION_INIT(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) __attribute__((aligned(alignbytes))) var
-#endif
-#elif(defined(__XCC__))
-#define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
- __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))
-#define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable"))) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
- __attribute__((section("NonCacheable"))) var __attribute__((aligned(alignbytes)))
-#elif(defined(__GNUC__))
-/* For GCC, when the non-cacheable section is required, please define "__STARTUP_INITIALIZE_NONCACHEDATA"
- * in your projects to make sure the non-cacheable section variables will be initialized in system startup.
- */
-#if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
-#define AT_NONCACHEABLE_SECTION_INIT(var) __attribute__((section("NonCacheable.init"))) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) \
- __attribute__((section("NonCacheable.init"))) var __attribute__((aligned(alignbytes)))
-#define AT_NONCACHEABLE_SECTION(var) __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
- __attribute__((section("NonCacheable,\"aw\",%nobits @"))) var __attribute__((aligned(alignbytes)))
-#else
-#define AT_NONCACHEABLE_SECTION(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
-#define AT_NONCACHEABLE_SECTION_INIT(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var __attribute__((aligned(alignbytes)))
-#endif
-#else
-#error Toolchain not supported.
-#define AT_NONCACHEABLE_SECTION(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) var
-#define AT_NONCACHEABLE_SECTION_INIT(var) var
-#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) var
-#endif
-/* @} */
-
-/*! @name Time sensitive region */
-/* @{ */
-#if defined(FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE) && FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE
-#if (defined(__ICCARM__))
-#define AT_QUICKACCESS_SECTION_CODE(func) func @"CodeQuickAccess"
-#define AT_QUICKACCESS_SECTION_DATA(func) func @"DataQuickAccess"
-#elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
-#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
-#define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func
-#elif(defined(__GNUC__))
-#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
-#define AT_QUICKACCESS_SECTION_DATA(func) __attribute__((section("DataQuickAccess"))) func
-#else
-#error Toolchain not supported.
-#endif /* defined(__ICCARM__) */
-#else
-#if (defined(__ICCARM__))
-#define AT_QUICKACCESS_SECTION_CODE(func) func
-#define AT_QUICKACCESS_SECTION_DATA(func) func
-#elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
-#define AT_QUICKACCESS_SECTION_CODE(func) func
-#define AT_QUICKACCESS_SECTION_DATA(func) func
-#elif(defined(__GNUC__))
-#define AT_QUICKACCESS_SECTION_CODE(func) func
-#define AT_QUICKACCESS_SECTION_DATA(func) func
-#else
-#error Toolchain not supported.
-#endif
-#endif /* __FSL_SDK_DRIVER_QUICK_ACCESS_ENABLE */
-/* @} */
-
-/*! @name Ram Function */
-#if (defined(__ICCARM__))
-#define RAMFUNCTION_SECTION_CODE(func) func @"RamFunction"
-#elif(defined(__CC_ARM) || defined(__ARMCC_VERSION))
-#define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
-#elif(defined(__GNUC__))
-#define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
-#else
-#error Toolchain not supported.
-#endif /* defined(__ICCARM__) */
-/* @} */
-
-/*! @name Suppress fallthrough warning macro */
-/* For switch case code block, if case section ends without "break;" statement, there wil be
- fallthrough warning with compiler flag -Wextra or -Wimplicit-fallthrough=n when using armgcc.
- To suppress this warning, "SUPPRESS_FALL_THROUGH_WARNING();" need to be added at the end of each
- case section which misses "break;"statement.
- */
-/* @{ */
-#if (defined(__GNUC__))
-#define SUPPRESS_FALL_THROUGH_WARNING() __attribute__ ((fallthrough))
-#else
-#define SUPPRESS_FALL_THROUGH_WARNING()
-#endif /* defined(__GNUC__) */
-/* @} */
-
-/*
- * The fsl_clock.h is included here because it needs MAKE_VERSION/MAKE_STATUS/status_t
- * defined in previous of this file.
- */
-#include "fsl_clock.h"
-
-/*
- * Chip level peripheral reset API, for MCUs that implement peripheral reset control external to a peripheral
- */
-#if ((defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0)) || \
- (defined(FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT) && (FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT > 0)))
-#include "fsl_reset.h"
-#endif
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
- extern "C"
-{
-#endif
-
- /*!
- * @brief Enable specific interrupt.
- *
- * Enable LEVEL1 interrupt. For some devices, there might be multiple interrupt
- * levels. For example, there are NVIC and intmux. Here the interrupts connected
- * to NVIC are the LEVEL1 interrupts, because they are routed to the core directly.
- * The interrupts connected to intmux are the LEVEL2 interrupts, they are routed
- * to NVIC first then routed to core.
- *
- * This function only enables the LEVEL1 interrupts. The number of LEVEL1 interrupts
- * is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.
- *
- * @param interrupt The IRQ number.
- * @retval kStatus_Success Interrupt enabled successfully
- * @retval kStatus_Fail Failed to enable the interrupt
- */
- static inline status_t EnableIRQ(IRQn_Type interrupt)
- {
- if (NotAvail_IRQn == interrupt)
- {
- return kStatus_Fail;
- }
-
-#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
- if (interrupt >= FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
- {
- return kStatus_Fail;
- }
-#endif
-
-#if defined(__GIC_PRIO_BITS)
- GIC_EnableIRQ(interrupt);
-#else
- NVIC_EnableIRQ(interrupt);
-#endif
- return kStatus_Success;
- }
-
- /*!
- * @brief Disable specific interrupt.
- *
- * Disable LEVEL1 interrupt. For some devices, there might be multiple interrupt
- * levels. For example, there are NVIC and intmux. Here the interrupts connected
- * to NVIC are the LEVEL1 interrupts, because they are routed to the core directly.
- * The interrupts connected to intmux are the LEVEL2 interrupts, they are routed
- * to NVIC first then routed to core.
- *
- * This function only disables the LEVEL1 interrupts. The number of LEVEL1 interrupts
- * is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.
- *
- * @param interrupt The IRQ number.
- * @retval kStatus_Success Interrupt disabled successfully
- * @retval kStatus_Fail Failed to disable the interrupt
- */
- static inline status_t DisableIRQ(IRQn_Type interrupt)
- {
- if (NotAvail_IRQn == interrupt)
- {
- return kStatus_Fail;
- }
-
-#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
- if (interrupt >= FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
- {
- return kStatus_Fail;
- }
-#endif
-
-#if defined(__GIC_PRIO_BITS)
- GIC_DisableIRQ(interrupt);
-#else
- NVIC_DisableIRQ(interrupt);
-#endif
- return kStatus_Success;
- }
-
- /*!
- * @brief Disable the global IRQ
- *
- * Disable the global interrupt and return the current primask register. User is required to provided the primask
- * register for the EnableGlobalIRQ().
- *
- * @return Current primask value.
- */
- static inline uint32_t DisableGlobalIRQ(void)
- {
-#if defined (__XCC__)
- return 0;
-#else
-#if defined(CPSR_I_Msk)
- uint32_t cpsr = __get_CPSR() & CPSR_I_Msk;
-
- __disable_irq();
-
- return cpsr;
-#else
- uint32_t regPrimask = __get_PRIMASK();
-
- __disable_irq();
-
- return regPrimask;
-#endif
-#endif
- }
-
- /*!
- * @brief Enable the global IRQ
- *
- * Set the primask register with the provided primask value but not just enable the primask. The idea is for the
- * convenience of integration of RTOS. some RTOS get its own management mechanism of primask. User is required to
- * use the EnableGlobalIRQ() and DisableGlobalIRQ() in pair.
- *
- * @param primask value of primask register to be restored. The primask value is supposed to be provided by the
- * DisableGlobalIRQ().
- */
- static inline void EnableGlobalIRQ(uint32_t primask)
- {
-#if defined (__XCC__)
-#else
-#if defined(CPSR_I_Msk)
- __set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask);
-#else
- __set_PRIMASK(primask);
-#endif
-#endif
- }
-
-#if defined(ENABLE_RAM_VECTOR_TABLE)
- /*!
- * @brief install IRQ handler
- *
- * @param irq IRQ number
- * @param irqHandler IRQ handler address
- * @return The old IRQ handler address
- */
- uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler);
-#endif /* ENABLE_RAM_VECTOR_TABLE. */
-
-#if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
- /*!
- * @brief Enable specific interrupt for wake-up from deep-sleep mode.
- *
- * Enable the interrupt for wake-up from deep sleep mode.
- * Some interrupts are typically used in sleep mode only and will not occur during
- * deep-sleep mode because relevant clocks are stopped. However, it is possible to enable
- * those clocks (significantly increasing power consumption in the reduced power mode),
- * making these wake-ups possible.
- *
- * @note This function also enables the interrupt in the NVIC (EnableIRQ() is called internaly).
- *
- * @param interrupt The IRQ number.
- */
- void EnableDeepSleepIRQ(IRQn_Type interrupt);
-
- /*!
- * @brief Disable specific interrupt for wake-up from deep-sleep mode.
- *
- * Disable the interrupt for wake-up from deep sleep mode.
- * Some interrupts are typically used in sleep mode only and will not occur during
- * deep-sleep mode because relevant clocks are stopped. However, it is possible to enable
- * those clocks (significantly increasing power consumption in the reduced power mode),
- * making these wake-ups possible.
- *
- * @note This function also disables the interrupt in the NVIC (DisableIRQ() is called internaly).
- *
- * @param interrupt The IRQ number.
- */
- void DisableDeepSleepIRQ(IRQn_Type interrupt);
-#endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
-
- /*!
- * @brief Allocate memory with given alignment and aligned size.
- *
- * This is provided to support the dynamically allocated memory
- * used in cache-able region.
- * @param size The length required to malloc.
- * @param alignbytes The alignment size.
- * @retval The allocated memory.
- */
- void *SDK_Malloc(size_t size, size_t alignbytes);
-
- /*!
- * @brief Free memory.
- *
- * @param ptr The memory to be release.
- */
- void SDK_Free(void *ptr);
-
- /*!
- * @brief Delay at least for some time.
- * Please note that, this API uses while loop for delay, different run-time environments make the time not precise,
- * if precise delay count was needed, please implement a new delay function with hardware timer.
- *
- * @param delay_us Delay time in unit of microsecond.
- * @param coreClock_Hz Core clock frequency with Hz.
- */
- void SDK_DelayAtLeastUs(uint32_t delay_us, uint32_t coreClock_Hz);
-
-#if defined(__cplusplus)
-}
-#endif
-
-/*! @} */
-
-#endif /* _FSL_COMMON_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.c
deleted file mode 100755
index 590ab321c..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.c
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_ctimer.h"
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.ctimer"
-#endif
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-/*!
- * @brief Gets the instance from the base address
- *
- * @param base Ctimer peripheral base address
- *
- * @return The Timer instance
- */
-static uint32_t CTIMER_GetInstance(CTIMER_Type *base);
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-/*! @brief Pointers to Timer bases for each instance. */
-static CTIMER_Type *const s_ctimerBases[] = CTIMER_BASE_PTRS;
-
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
-/*! @brief Pointers to Timer clocks for each instance. */
-static const clock_ip_name_t s_ctimerClocks[] = CTIMER_CLOCKS;
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_RESET) && (FSL_FEATURE_CTIMER_HAS_NO_RESET))
-#if !(defined(FSL_SDK_DISABLE_DRIVER_RESET_CONTROL) && FSL_SDK_DISABLE_DRIVER_RESET_CONTROL)
-#if defined(FSL_FEATURE_CTIMER_WRITE_ZERO_ASSERT_RESET) && FSL_FEATURE_CTIMER_WRITE_ZERO_ASSERT_RESET
-/*! @brief Pointers to Timer resets for each instance, writing a zero asserts the reset */
-static const reset_ip_name_t s_ctimerResets[] = CTIMER_RSTS_N;
-#else
-/*! @brief Pointers to Timer resets for each instance, writing a one asserts the reset */
-static const reset_ip_name_t s_ctimerResets[] = CTIMER_RSTS;
-#endif
-#endif
-#endif /* FSL_SDK_DISABLE_DRIVER_RESET_CONTROL */
-
-/*! @brief Pointers real ISRs installed by drivers for each instance. */
-static ctimer_callback_t *s_ctimerCallback[FSL_FEATURE_SOC_CTIMER_COUNT] = {0};
-
-/*! @brief Callback type installed by drivers for each instance. */
-static ctimer_callback_type_t ctimerCallbackType[FSL_FEATURE_SOC_CTIMER_COUNT] = {kCTIMER_SingleCallback};
-
-/*! @brief Array to map timer instance to IRQ number. */
-static const IRQn_Type s_ctimerIRQ[] = CTIMER_IRQS;
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-static uint32_t CTIMER_GetInstance(CTIMER_Type *base)
-{
- uint32_t instance;
- uint32_t ctimerArrayCount = (sizeof(s_ctimerBases) / sizeof(s_ctimerBases[0]));
-
- /* Find the instance index from base address mappings. */
- for (instance = 0; instance < ctimerArrayCount; instance++)
- {
- if (s_ctimerBases[instance] == base)
- {
- break;
- }
- }
-
- assert(instance < ctimerArrayCount);
-
- return instance;
-}
-
-/*!
- * brief Ungates the clock and configures the peripheral for basic operation.
- *
- * note This API should be called at the beginning of the application before using the driver.
- *
- * param base Ctimer peripheral base address
- * param config Pointer to the user configuration structure.
- */
-void CTIMER_Init(CTIMER_Type *base, const ctimer_config_t *config)
-{
- assert(config);
-
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- /* Enable the timer clock*/
- CLOCK_EnableClock(s_ctimerClocks[CTIMER_GetInstance(base)]);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-
-#if !(defined(FSL_SDK_DISABLE_DRIVER_RESET_CONTROL) && FSL_SDK_DISABLE_DRIVER_RESET_CONTROL)
-/* Reset the module. */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_RESET) && (FSL_FEATURE_CTIMER_HAS_NO_RESET))
- RESET_PeripheralReset(s_ctimerResets[CTIMER_GetInstance(base)]);
-#endif
-#endif /* FSL_SDK_DISABLE_DRIVER_RESET_CONTROL */
-
-/* Setup the cimer mode and count select */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
- base->CTCR = CTIMER_CTCR_CTMODE(config->mode) | CTIMER_CTCR_CINSEL(config->input);
-#endif
- /* Setup the timer prescale value */
- base->PR = CTIMER_PR_PRVAL(config->prescale);
-}
-
-/*!
- * brief Gates the timer clock.
- *
- * param base Ctimer peripheral base address
- */
-void CTIMER_Deinit(CTIMER_Type *base)
-{
- uint32_t index = CTIMER_GetInstance(base);
- /* Stop the timer */
- base->TCR &= ~CTIMER_TCR_CEN_MASK;
-
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- /* Disable the timer clock*/
- CLOCK_DisableClock(s_ctimerClocks[index]);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-
- /* Disable IRQ at NVIC Level */
- DisableIRQ(s_ctimerIRQ[index]);
-}
-
-/*!
- * brief Fills in the timers configuration structure with the default settings.
- *
- * The default values are:
- * code
- * config->mode = kCTIMER_TimerMode;
- * config->input = kCTIMER_Capture_0;
- * config->prescale = 0;
- * endcode
- * param config Pointer to the user configuration structure.
- */
-void CTIMER_GetDefaultConfig(ctimer_config_t *config)
-{
- assert(config);
-
- /* Initializes the configure structure to zero. */
- memset(config, 0, sizeof(*config));
-
- /* Run as a timer */
- config->mode = kCTIMER_TimerMode;
- /* This field is ignored when mode is timer */
- config->input = kCTIMER_Capture_0;
- /* Timer counter is incremented on every APB bus clock */
- config->prescale = 0;
-}
-
-/*!
- * brief Configures the PWM signal parameters.
- *
- * Enables PWM mode on the match channel passed in and will then setup the match value
- * and other match parameters to generate a PWM signal.
- * This function will assign match channel 3 to set the PWM cycle.
- *
- * note When setting PWM output from multiple output pins, all should use the same PWM
- * frequency. Please use CTIMER_SetupPwmPeriod to set up the PWM with high resolution.
- *
- * param base Ctimer peripheral base address
- * param matchChannel Match pin to be used to output the PWM signal
- * param dutyCyclePercent PWM pulse width; the value should be between 0 to 100
- * param pwmFreq_Hz PWM signal frequency in Hz
- * param srcClock_Hz Timer counter clock in Hz
- * param enableInt Enable interrupt when the timer value reaches the match value of the PWM pulse,
- * if it is 0 then no interrupt is generated
- *
- * return kStatus_Success on success
- * kStatus_Fail If matchChannel passed in is 3; this channel is reserved to set the PWM cycle
- */
-status_t CTIMER_SetupPwm(CTIMER_Type *base,
- ctimer_match_t matchChannel,
- uint8_t dutyCyclePercent,
- uint32_t pwmFreq_Hz,
- uint32_t srcClock_Hz,
- bool enableInt)
-{
- assert(pwmFreq_Hz > 0);
-
- uint32_t reg;
- uint32_t period, pulsePeriod = 0;
- uint32_t timerClock = srcClock_Hz / (base->PR + 1);
- uint32_t index = CTIMER_GetInstance(base);
-
- if (matchChannel == kCTIMER_Match_3)
- {
- return kStatus_Fail;
- }
-
- /* Enable PWM mode on the channel */
- base->PWMC |= (1U << matchChannel);
-
- /* Clear the stop, reset and interrupt bits for this channel */
- reg = base->MCR;
- reg &= ~((CTIMER_MCR_MR0R_MASK | CTIMER_MCR_MR0S_MASK | CTIMER_MCR_MR0I_MASK) << (matchChannel * 3));
-
- /* If call back function is valid then enable match interrupt for the channel */
- if (enableInt)
- {
- reg |= (CTIMER_MCR_MR0I_MASK << (CTIMER_MCR_MR0I_SHIFT + (matchChannel * 3)));
- }
-
- /* Reset the counter when match on channel 3 */
- reg |= CTIMER_MCR_MR3R_MASK;
-
- base->MCR = reg;
-
- /* Calculate PWM period match value */
- period = (timerClock / pwmFreq_Hz) - 1;
-
- /* Calculate pulse width match value */
- if (dutyCyclePercent == 0)
- {
- pulsePeriod = period + 1;
- }
- else
- {
- pulsePeriod = (period * (100 - dutyCyclePercent)) / 100;
- }
-
- /* Match on channel 3 will define the PWM period */
- base->MR[kCTIMER_Match_3] = period;
-
- /* This will define the PWM pulse period */
- base->MR[matchChannel] = pulsePeriod;
- /* Clear status flags */
- CTIMER_ClearStatusFlags(base, CTIMER_IR_MR0INT_MASK << matchChannel);
- /* If call back function is valid then enable interrupt and update the call back function */
- if (enableInt)
- {
- EnableIRQ(s_ctimerIRQ[index]);
- }
-
- return kStatus_Success;
-}
-
-/*!
- * brief Configures the PWM signal parameters.
- *
- * Enables PWM mode on the match channel passed in and will then setup the match value
- * and other match parameters to generate a PWM signal.
- * This function will assign match channel 3 to set the PWM cycle.
- *
- * note When setting PWM output from multiple output pins, all should use the same PWM
- * period
- *
- * param base Ctimer peripheral base address
- * param matchChannel Match pin to be used to output the PWM signal
- * param pwmPeriod PWM period match value
- * param pulsePeriod Pulse width match value
- * param enableInt Enable interrupt when the timer value reaches the match value of the PWM pulse,
- * if it is 0 then no interrupt is generated
- *
- * return kStatus_Success on success
- * kStatus_Fail If matchChannel passed in is 3; this channel is reserved to set the PWM period
- */
-status_t CTIMER_SetupPwmPeriod(
- CTIMER_Type *base, ctimer_match_t matchChannel, uint32_t pwmPeriod, uint32_t pulsePeriod, bool enableInt)
-{
-/* Some CTimers only have 16bits , so the value is limited*/
-#if defined(FSL_FEATURE_SOC_CTIMER16B) && FSL_FEATURE_SOC_CTIMER16B
- assert(!((FSL_FEATURE_CTIMER_BIT_SIZEn(base) < 32) && (pulsePeriod > 0xFFFFU)));
-#endif
-
- uint32_t reg;
- uint32_t index = CTIMER_GetInstance(base);
-
- if (matchChannel == kCTIMER_Match_3)
- {
- return kStatus_Fail;
- }
-
- /* Enable PWM mode on the channel */
- base->PWMC |= (1U << matchChannel);
-
- /* Clear the stop, reset and interrupt bits for this channel */
- reg = base->MCR;
- reg &= ~((CTIMER_MCR_MR0R_MASK | CTIMER_MCR_MR0S_MASK | CTIMER_MCR_MR0I_MASK) << (matchChannel * 3));
-
- /* If call back function is valid then enable match interrupt for the channel */
- if (enableInt)
- {
- reg |= (CTIMER_MCR_MR0I_MASK << (CTIMER_MCR_MR0I_SHIFT + (matchChannel * 3)));
- }
-
- /* Reset the counter when match on channel 3 */
- reg |= CTIMER_MCR_MR3R_MASK;
-
- base->MCR = reg;
-
- /* Match on channel 3 will define the PWM period */
- base->MR[kCTIMER_Match_3] = pwmPeriod;
-
- /* This will define the PWM pulse period */
- base->MR[matchChannel] = pulsePeriod;
- /* Clear status flags */
- CTIMER_ClearStatusFlags(base, CTIMER_IR_MR0INT_MASK << matchChannel);
- /* If call back function is valid then enable interrupt and update the call back function */
- if (enableInt)
- {
- EnableIRQ(s_ctimerIRQ[index]);
- }
-
- return kStatus_Success;
-}
-
-/*!
- * brief Updates the duty cycle of an active PWM signal.
- *
- * note Please use CTIMER_UpdatePwmPulsePeriod to update the PWM with high resolution.
- *
- * param base Ctimer peripheral base address
- * param matchChannel Match pin to be used to output the PWM signal
- * param dutyCyclePercent New PWM pulse width; the value should be between 0 to 100
- */
-void CTIMER_UpdatePwmDutycycle(CTIMER_Type *base, ctimer_match_t matchChannel, uint8_t dutyCyclePercent)
-{
- uint32_t pulsePeriod = 0, period;
-
- /* Match channel 3 defines the PWM period */
- period = base->MR[kCTIMER_Match_3];
-
- /* Calculate pulse width match value */
- pulsePeriod = (period * dutyCyclePercent) / 100;
-
- /* For 0% dutycyle, make pulse period greater than period so the event will never occur */
- if (dutyCyclePercent == 0)
- {
- pulsePeriod = period + 1;
- }
- else
- {
- pulsePeriod = (period * (100 - dutyCyclePercent)) / 100;
- }
-
- /* Update dutycycle */
- base->MR[matchChannel] = pulsePeriod;
-}
-
-/*!
- * brief Setup the match register.
- *
- * User configuration is used to setup the match value and action to be taken when a match occurs.
- *
- * param base Ctimer peripheral base address
- * param matchChannel Match register to configure
- * param config Pointer to the match configuration structure
- */
-void CTIMER_SetupMatch(CTIMER_Type *base, ctimer_match_t matchChannel, const ctimer_match_config_t *config)
-{
-/* Some CTimers only have 16bits , so the value is limited*/
-#if defined(FSL_FEATURE_SOC_CTIMER16B) && FSL_FEATURE_SOC_CTIMER16B
- assert(!(FSL_FEATURE_CTIMER_BIT_SIZEn(base) < 32 && config->matchValue > 0xFFFFU));
-#endif
- uint32_t reg;
- uint32_t index = CTIMER_GetInstance(base);
-
- /* Set the counter operation when a match on this channel occurs */
- reg = base->MCR;
- reg &= ~((CTIMER_MCR_MR0R_MASK | CTIMER_MCR_MR0S_MASK | CTIMER_MCR_MR0I_MASK) << (matchChannel * 3));
- reg |= (uint32_t)((uint32_t)(config->enableCounterReset) << (CTIMER_MCR_MR0R_SHIFT + (matchChannel * 3)));
- reg |= (uint32_t)((uint32_t)(config->enableCounterStop) << (CTIMER_MCR_MR0S_SHIFT + (matchChannel * 3)));
- reg |= (uint32_t)((uint32_t)(config->enableInterrupt) << (CTIMER_MCR_MR0I_SHIFT + (matchChannel * 3)));
- base->MCR = reg;
-
- reg = base->EMR;
- /* Set the match output operation when a match on this channel occurs */
- reg &= ~(CTIMER_EMR_EMC0_MASK << (matchChannel * 2));
- reg |= (uint32_t)config->outControl << (CTIMER_EMR_EMC0_SHIFT + (matchChannel * 2));
-
- /* Set the initial state of the EM bit/output */
- reg &= ~(CTIMER_EMR_EM0_MASK << matchChannel);
- reg |= (uint32_t)config->outPinInitState << matchChannel;
- base->EMR = reg;
-
- /* Set the match value */
- base->MR[matchChannel] = config->matchValue;
- /* Clear status flags */
- CTIMER_ClearStatusFlags(base, CTIMER_IR_MR0INT_MASK << matchChannel);
- /* If interrupt is enabled then enable interrupt and update the call back function */
- if (config->enableInterrupt)
- {
- EnableIRQ(s_ctimerIRQ[index]);
- }
-}
-
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
-/*!
- * brief Setup the capture.
- *
- * param base Ctimer peripheral base address
- * param capture Capture channel to configure
- * param edge Edge on the channel that will trigger a capture
- * param enableInt Flag to enable channel interrupts, if enabled then the registered call back
- * is called upon capture
- */
-void CTIMER_SetupCapture(CTIMER_Type *base,
- ctimer_capture_channel_t capture,
- ctimer_capture_edge_t edge,
- bool enableInt)
-{
- uint32_t reg = base->CCR;
- uint32_t index = CTIMER_GetInstance(base);
-
- /* Set the capture edge */
- reg &= ~((CTIMER_CCR_CAP0RE_MASK | CTIMER_CCR_CAP0FE_MASK | CTIMER_CCR_CAP0I_MASK) << (capture * 3));
- reg |= (uint32_t)edge << (CTIMER_CCR_CAP0RE_SHIFT + (capture * 3));
- /* Clear status flags */
- CTIMER_ClearStatusFlags(base, (kCTIMER_Capture0Flag << capture));
- /* If call back function is valid then enable capture interrupt for the channel and update the call back function */
- if (enableInt)
- {
- reg |= CTIMER_CCR_CAP0I_MASK << (capture * 3);
- EnableIRQ(s_ctimerIRQ[index]);
- }
- base->CCR = reg;
-}
-#endif
-
-/*!
- * brief Register callback.
- *
- * param base Ctimer peripheral base address
- * param cb_func callback function
- * param cb_type callback function type, singular or multiple
- */
-void CTIMER_RegisterCallBack(CTIMER_Type *base, ctimer_callback_t *cb_func, ctimer_callback_type_t cb_type)
-{
- uint32_t index = CTIMER_GetInstance(base);
- s_ctimerCallback[index] = cb_func;
- ctimerCallbackType[index] = cb_type;
-}
-
-void CTIMER_GenericIRQHandler(uint32_t index)
-{
- uint32_t int_stat, i, mask;
- /* Get Interrupt status flags */
- int_stat = CTIMER_GetStatusFlags(s_ctimerBases[index]);
- /* Clear the status flags that were set */
- CTIMER_ClearStatusFlags(s_ctimerBases[index], int_stat);
- if (ctimerCallbackType[index] == kCTIMER_SingleCallback)
- {
- if (s_ctimerCallback[index][0])
- {
- s_ctimerCallback[index][0](int_stat);
- }
- }
- else
- {
-#if defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE
- for (i = 0; i <= CTIMER_IR_MR3INT_SHIFT; i++)
-#else
-#if defined(FSL_FEATURE_CTIMER_HAS_IR_CR3INT) && FSL_FEATURE_CTIMER_HAS_IR_CR3INT
- for (i = 0; i <= CTIMER_IR_CR3INT_SHIFT; i++)
-#else
- for (i = 0; i <= CTIMER_IR_CR2INT_SHIFT; i++)
-#endif /* FSL_FEATURE_CTIMER_HAS_IR_CR3INT */
-#endif
- {
- mask = 0x01 << i;
- /* For each status flag bit that was set call the callback function if it is valid */
- if ((int_stat & mask) && (s_ctimerCallback[index][i]))
- {
- s_ctimerCallback[index][i](int_stat);
- }
- }
- }
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-
-/* IRQ handler functions overloading weak symbols in the startup */
-#if defined(CTIMER0)
-void CTIMER0_DriverIRQHandler(void)
-{
- CTIMER_GenericIRQHandler(0);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(CTIMER1)
-void CTIMER1_DriverIRQHandler(void)
-{
- CTIMER_GenericIRQHandler(1);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(CTIMER2)
-void CTIMER2_DriverIRQHandler(void)
-{
- CTIMER_GenericIRQHandler(2);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(CTIMER3)
-void CTIMER3_DriverIRQHandler(void)
-{
- CTIMER_GenericIRQHandler(3);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(CTIMER4)
-void CTIMER4_DriverIRQHandler(void)
-{
- CTIMER_GenericIRQHandler(4);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.h
deleted file mode 100755
index 8ae0d886a..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_ctimer.h
+++ /dev/null
@@ -1,488 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-#ifndef _FSL_CTIMER_H_
-#define _FSL_CTIMER_H_
-
-#include "fsl_common.h"
-
-/*!
- * @addtogroup ctimer
- * @{
- */
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/*! @name Driver version */
-/*@{*/
-#define FSL_CTIMER_DRIVER_VERSION (MAKE_VERSION(2, 0, 2)) /*!< Version 2.0.2 */
-/*@}*/
-
-/*! @brief List of Timer capture channels */
-typedef enum _ctimer_capture_channel
-{
- kCTIMER_Capture_0 = 0U, /*!< Timer capture channel 0 */
- kCTIMER_Capture_1, /*!< Timer capture channel 1 */
- kCTIMER_Capture_2, /*!< Timer capture channel 2 */
-#if defined(FSL_FEATURE_CTIMER_HAS_CCR_CAP3) && FSL_FEATURE_CTIMER_HAS_CCR_CAP3
- kCTIMER_Capture_3 /*!< Timer capture channel 3 */
-#endif /* FSL_FEATURE_CTIMER_HAS_IR_CR3INT */
-} ctimer_capture_channel_t;
-
-/*! @brief List of capture edge options */
-typedef enum _ctimer_capture_edge
-{
- kCTIMER_Capture_RiseEdge = 1U, /*!< Capture on rising edge */
- kCTIMER_Capture_FallEdge = 2U, /*!< Capture on falling edge */
- kCTIMER_Capture_BothEdge = 3U, /*!< Capture on rising and falling edge */
-} ctimer_capture_edge_t;
-
-/*! @brief List of Timer match registers */
-typedef enum _ctimer_match
-{
- kCTIMER_Match_0 = 0U, /*!< Timer match register 0 */
- kCTIMER_Match_1, /*!< Timer match register 1 */
- kCTIMER_Match_2, /*!< Timer match register 2 */
- kCTIMER_Match_3 /*!< Timer match register 3 */
-} ctimer_match_t;
-
-/*! @brief List of output control options */
-typedef enum _ctimer_match_output_control
-{
- kCTIMER_Output_NoAction = 0U, /*!< No action is taken */
- kCTIMER_Output_Clear, /*!< Clear the EM bit/output to 0 */
- kCTIMER_Output_Set, /*!< Set the EM bit/output to 1 */
- kCTIMER_Output_Toggle /*!< Toggle the EM bit/output */
-} ctimer_match_output_control_t;
-
-/*! @brief List of Timer modes */
-typedef enum _ctimer_timer_mode
-{
- kCTIMER_TimerMode = 0U, /* TC is incremented every rising APB bus clock edge */
- kCTIMER_IncreaseOnRiseEdge, /* TC is incremented on rising edge of input signal */
- kCTIMER_IncreaseOnFallEdge, /* TC is incremented on falling edge of input signal */
- kCTIMER_IncreaseOnBothEdge /* TC is incremented on both edges of input signal */
-} ctimer_timer_mode_t;
-
-/*! @brief List of Timer interrupts */
-typedef enum _ctimer_interrupt_enable
-{
- kCTIMER_Match0InterruptEnable = CTIMER_MCR_MR0I_MASK, /*!< Match 0 interrupt */
- kCTIMER_Match1InterruptEnable = CTIMER_MCR_MR1I_MASK, /*!< Match 1 interrupt */
- kCTIMER_Match2InterruptEnable = CTIMER_MCR_MR2I_MASK, /*!< Match 2 interrupt */
- kCTIMER_Match3InterruptEnable = CTIMER_MCR_MR3I_MASK, /*!< Match 3 interrupt */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
- kCTIMER_Capture0InterruptEnable = CTIMER_CCR_CAP0I_MASK, /*!< Capture 0 interrupt */
- kCTIMER_Capture1InterruptEnable = CTIMER_CCR_CAP1I_MASK, /*!< Capture 1 interrupt */
- kCTIMER_Capture2InterruptEnable = CTIMER_CCR_CAP2I_MASK, /*!< Capture 2 interrupt */
-#if defined(FSL_FEATURE_CTIMER_HAS_CCR_CAP3) && FSL_FEATURE_CTIMER_HAS_CCR_CAP3
- kCTIMER_Capture3InterruptEnable = CTIMER_CCR_CAP3I_MASK, /*!< Capture 3 interrupt */
-#endif /* FSL_FEATURE_CTIMER_HAS_CCR_CAP3 */
-#endif
-} ctimer_interrupt_enable_t;
-
-/*! @brief List of Timer flags */
-typedef enum _ctimer_status_flags
-{
- kCTIMER_Match0Flag = CTIMER_IR_MR0INT_MASK, /*!< Match 0 interrupt flag */
- kCTIMER_Match1Flag = CTIMER_IR_MR1INT_MASK, /*!< Match 1 interrupt flag */
- kCTIMER_Match2Flag = CTIMER_IR_MR2INT_MASK, /*!< Match 2 interrupt flag */
- kCTIMER_Match3Flag = CTIMER_IR_MR3INT_MASK, /*!< Match 3 interrupt flag */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
- kCTIMER_Capture0Flag = CTIMER_IR_CR0INT_MASK, /*!< Capture 0 interrupt flag */
- kCTIMER_Capture1Flag = CTIMER_IR_CR1INT_MASK, /*!< Capture 1 interrupt flag */
- kCTIMER_Capture2Flag = CTIMER_IR_CR2INT_MASK, /*!< Capture 2 interrupt flag */
-#if defined(FSL_FEATURE_CTIMER_HAS_IR_CR3INT) && FSL_FEATURE_CTIMER_HAS_IR_CR3INT
- kCTIMER_Capture3Flag = CTIMER_IR_CR3INT_MASK, /*!< Capture 3 interrupt flag */
-#endif /* FSL_FEATURE_CTIMER_HAS_IR_CR3INT */
-#endif
-} ctimer_status_flags_t;
-
-typedef void (*ctimer_callback_t)(uint32_t flags);
-
-/*! @brief Callback type when registering for a callback. When registering a callback
- * an array of function pointers is passed the size could be 1 or 8, the callback
- * type will tell that.
- */
-typedef enum
-{
- kCTIMER_SingleCallback, /*!< Single Callback type where there is only one callback for the timer.
- based on the status flags different channels needs to be handled differently */
- kCTIMER_MultipleCallback /*!< Multiple Callback type where there can be 8 valid callbacks, one per channel.
- for both match/capture */
-} ctimer_callback_type_t;
-
-/*!
- * @brief Match configuration
- *
- * This structure holds the configuration settings for each match register.
- */
-typedef struct _ctimer_match_config
-{
- uint32_t matchValue; /*!< This is stored in the match register */
- bool enableCounterReset; /*!< true: Match will reset the counter
- false: Match will not reser the counter */
- bool enableCounterStop; /*!< true: Match will stop the counter
- false: Match will not stop the counter */
- ctimer_match_output_control_t outControl; /*!< Action to be taken on a match on the EM bit/output */
- bool outPinInitState; /*!< Initial value of the EM bit/output */
- bool enableInterrupt; /*!< true: Generate interrupt upon match
- false: Do not generate interrupt on match */
-
-} ctimer_match_config_t;
-
-/*!
- * @brief Timer configuration structure
- *
- * This structure holds the configuration settings for the Timer peripheral. To initialize this
- * structure to reasonable defaults, call the CTIMER_GetDefaultConfig() function and pass a
- * pointer to the configuration structure instance.
- *
- * The configuration structure can be made constant so as to reside in flash.
- */
-typedef struct _ctimer_config
-{
- ctimer_timer_mode_t mode; /*!< Timer mode */
- ctimer_capture_channel_t input; /*!< Input channel to increment the timer, used only in timer
- modes that rely on this input signal to increment TC */
- uint32_t prescale; /*!< Prescale value */
-} ctimer_config_t;
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*!
- * @name Initialization and deinitialization
- * @{
- */
-
-/*!
- * @brief Ungates the clock and configures the peripheral for basic operation.
- *
- * @note This API should be called at the beginning of the application before using the driver.
- *
- * @param base Ctimer peripheral base address
- * @param config Pointer to the user configuration structure.
- */
-void CTIMER_Init(CTIMER_Type *base, const ctimer_config_t *config);
-
-/*!
- * @brief Gates the timer clock.
- *
- * @param base Ctimer peripheral base address
- */
-void CTIMER_Deinit(CTIMER_Type *base);
-
-/*!
- * @brief Fills in the timers configuration structure with the default settings.
- *
- * The default values are:
- * @code
- * config->mode = kCTIMER_TimerMode;
- * config->input = kCTIMER_Capture_0;
- * config->prescale = 0;
- * @endcode
- * @param config Pointer to the user configuration structure.
- */
-void CTIMER_GetDefaultConfig(ctimer_config_t *config);
-
-/*! @}*/
-
-/*!
- * @name PWM setup operations
- * @{
- */
-
-/*!
- * @brief Configures the PWM signal parameters.
- *
- * Enables PWM mode on the match channel passed in and will then setup the match value
- * and other match parameters to generate a PWM signal.
- * This function will assign match channel 3 to set the PWM cycle.
- *
- * @note When setting PWM output from multiple output pins, all should use the same PWM
- * period
- *
- * @param base Ctimer peripheral base address
- * @param matchChannel Match pin to be used to output the PWM signal
- * @param pwmPeriod PWM period match value
- * @param pulsePeriod Pulse width match value
- * @param enableInt Enable interrupt when the timer value reaches the match value of the PWM pulse,
- * if it is 0 then no interrupt is generated
- *
- * @return kStatus_Success on success
- * kStatus_Fail If matchChannel passed in is 3; this channel is reserved to set the PWM period
- */
-status_t CTIMER_SetupPwmPeriod(
- CTIMER_Type *base, ctimer_match_t matchChannel, uint32_t pwmPeriod, uint32_t pulsePeriod, bool enableInt);
-
-/*!
- * @brief Configures the PWM signal parameters.
- *
- * Enables PWM mode on the match channel passed in and will then setup the match value
- * and other match parameters to generate a PWM signal.
- * This function will assign match channel 3 to set the PWM cycle.
- *
- * @note When setting PWM output from multiple output pins, all should use the same PWM
- * frequency. Please use CTIMER_SetupPwmPeriod to set up the PWM with high resolution.
- *
- * @param base Ctimer peripheral base address
- * @param matchChannel Match pin to be used to output the PWM signal
- * @param dutyCyclePercent PWM pulse width; the value should be between 0 to 100
- * @param pwmFreq_Hz PWM signal frequency in Hz
- * @param srcClock_Hz Timer counter clock in Hz
- * @param enableInt Enable interrupt when the timer value reaches the match value of the PWM pulse,
- * if it is 0 then no interrupt is generated
- *
- * @return kStatus_Success on success
- * kStatus_Fail If matchChannel passed in is 3; this channel is reserved to set the PWM cycle
- */
-status_t CTIMER_SetupPwm(CTIMER_Type *base,
- ctimer_match_t matchChannel,
- uint8_t dutyCyclePercent,
- uint32_t pwmFreq_Hz,
- uint32_t srcClock_Hz,
- bool enableInt);
-
-/*!
- * @brief Updates the pulse period of an active PWM signal.
- *
- * @param base Ctimer peripheral base address
- * @param matchChannel Match pin to be used to output the PWM signal
- * @param pulsePeriod New PWM pulse width match value
- */
-static inline void CTIMER_UpdatePwmPulsePeriod(CTIMER_Type *base, ctimer_match_t matchChannel, uint32_t pulsePeriod)
-{
- /* Update PWM pulse period match value */
- base->MR[matchChannel] = pulsePeriod;
-}
-
-/*!
- * @brief Updates the duty cycle of an active PWM signal.
- *
- * @note Please use CTIMER_UpdatePwmPulsePeriod to update the PWM with high resolution.
- *
- * @param base Ctimer peripheral base address
- * @param matchChannel Match pin to be used to output the PWM signal
- * @param dutyCyclePercent New PWM pulse width; the value should be between 0 to 100
- */
-void CTIMER_UpdatePwmDutycycle(CTIMER_Type *base, ctimer_match_t matchChannel, uint8_t dutyCyclePercent);
-
-/*! @}*/
-
-/*!
- * @brief Setup the match register.
- *
- * User configuration is used to setup the match value and action to be taken when a match occurs.
- *
- * @param base Ctimer peripheral base address
- * @param matchChannel Match register to configure
- * @param config Pointer to the match configuration structure
- */
-void CTIMER_SetupMatch(CTIMER_Type *base, ctimer_match_t matchChannel, const ctimer_match_config_t *config);
-
-/*!
- * @brief Setup the capture.
- *
- * @param base Ctimer peripheral base address
- * @param capture Capture channel to configure
- * @param edge Edge on the channel that will trigger a capture
- * @param enableInt Flag to enable channel interrupts, if enabled then the registered call back
- * is called upon capture
- */
-void CTIMER_SetupCapture(CTIMER_Type *base,
- ctimer_capture_channel_t capture,
- ctimer_capture_edge_t edge,
- bool enableInt);
-
-/*!
- * @brief Get the timer count value from TC register.
- *
- * @param base Ctimer peripheral base address.
- * @return return the timer count value.
- */
-static inline uint32_t CTIMER_GetTimerCountValue(CTIMER_Type *base)
-{
- return (base->TC);
-}
-
-/*!
- * @brief Register callback.
- *
- * @param base Ctimer peripheral base address
- * @param cb_func callback function
- * @param cb_type callback function type, singular or multiple
- */
-void CTIMER_RegisterCallBack(CTIMER_Type *base, ctimer_callback_t *cb_func, ctimer_callback_type_t cb_type);
-
-/*!
- * @name Interrupt Interface
- * @{
- */
-
-/*!
- * @brief Enables the selected Timer interrupts.
- *
- * @param base Ctimer peripheral base address
- * @param mask The interrupts to enable. This is a logical OR of members of the
- * enumeration ::ctimer_interrupt_enable_t
- */
-static inline void CTIMER_EnableInterrupts(CTIMER_Type *base, uint32_t mask)
-{
- /* Enable match interrupts */
- base->MCR |= mask & (CTIMER_MCR_MR0I_MASK | CTIMER_MCR_MR1I_MASK | CTIMER_MCR_MR2I_MASK | CTIMER_MCR_MR3I_MASK);
-
-/* Enable capture interrupts */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
- base->CCR |= mask & (CTIMER_CCR_CAP0I_MASK | CTIMER_CCR_CAP1I_MASK | CTIMER_CCR_CAP2I_MASK
-#if defined(FSL_FEATURE_CTIMER_HAS_CCR_CAP3) && FSL_FEATURE_CTIMER_HAS_CCR_CAP3
- | CTIMER_CCR_CAP3I_MASK
-#endif /* FSL_FEATURE_CTIMER_HAS_CCR_CAP3 */
- );
-#endif
-}
-
-/*!
- * @brief Disables the selected Timer interrupts.
- *
- * @param base Ctimer peripheral base address
- * @param mask The interrupts to enable. This is a logical OR of members of the
- * enumeration ::ctimer_interrupt_enable_t
- */
-static inline void CTIMER_DisableInterrupts(CTIMER_Type *base, uint32_t mask)
-{
- /* Disable match interrupts */
- base->MCR &= ~(mask & (CTIMER_MCR_MR0I_MASK | CTIMER_MCR_MR1I_MASK | CTIMER_MCR_MR2I_MASK | CTIMER_MCR_MR3I_MASK));
-
-/* Disable capture interrupts */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
- base->CCR &= ~(mask & (CTIMER_CCR_CAP0I_MASK | CTIMER_CCR_CAP1I_MASK | CTIMER_CCR_CAP2I_MASK
-#if defined(FSL_FEATURE_CTIMER_HAS_CCR_CAP3) && FSL_FEATURE_CTIMER_HAS_CCR_CAP3
- | CTIMER_CCR_CAP3I_MASK
-#endif /* FSL_FEATURE_CTIMER_HAS_CCR_CAP3 */
- ));
-#endif
-}
-
-/*!
- * @brief Gets the enabled Timer interrupts.
- *
- * @param base Ctimer peripheral base address
- *
- * @return The enabled interrupts. This is the logical OR of members of the
- * enumeration ::ctimer_interrupt_enable_t
- */
-static inline uint32_t CTIMER_GetEnabledInterrupts(CTIMER_Type *base)
-{
- uint32_t enabledIntrs = 0;
-
- /* Get all the match interrupts enabled */
- enabledIntrs =
- base->MCR & (CTIMER_MCR_MR0I_MASK | CTIMER_MCR_MR1I_MASK | CTIMER_MCR_MR2I_MASK | CTIMER_MCR_MR3I_MASK);
-
-/* Get all the capture interrupts enabled */
-#if !(defined(FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE) && (FSL_FEATURE_CTIMER_HAS_NO_INPUT_CAPTURE))
- enabledIntrs |= base->CCR & (CTIMER_CCR_CAP0I_MASK | CTIMER_CCR_CAP1I_MASK | CTIMER_CCR_CAP2I_MASK
-#if defined(FSL_FEATURE_CTIMER_HAS_CCR_CAP3) && FSL_FEATURE_CTIMER_HAS_CCR_CAP3
- | CTIMER_CCR_CAP3I_MASK
-#endif /* FSL_FEATURE_CTIMER_HAS_CCR_CAP3 */
- );
-#endif
-
- return enabledIntrs;
-}
-
-/*! @}*/
-
-/*!
- * @name Status Interface
- * @{
- */
-
-/*!
- * @brief Gets the Timer status flags.
- *
- * @param base Ctimer peripheral base address
- *
- * @return The status flags. This is the logical OR of members of the
- * enumeration ::ctimer_status_flags_t
- */
-static inline uint32_t CTIMER_GetStatusFlags(CTIMER_Type *base)
-{
- return base->IR;
-}
-
-/*!
- * @brief Clears the Timer status flags.
- *
- * @param base Ctimer peripheral base address
- * @param mask The status flags to clear. This is a logical OR of members of the
- * enumeration ::ctimer_status_flags_t
- */
-static inline void CTIMER_ClearStatusFlags(CTIMER_Type *base, uint32_t mask)
-{
- base->IR = mask;
-}
-
-/*! @}*/
-
-/*!
- * @name Counter Start and Stop
- * @{
- */
-
-/*!
- * @brief Starts the Timer counter.
- *
- * @param base Ctimer peripheral base address
- */
-static inline void CTIMER_StartTimer(CTIMER_Type *base)
-{
- base->TCR |= CTIMER_TCR_CEN_MASK;
-}
-
-/*!
- * @brief Stops the Timer counter.
- *
- * @param base Ctimer peripheral base address
- */
-static inline void CTIMER_StopTimer(CTIMER_Type *base)
-{
- base->TCR &= ~CTIMER_TCR_CEN_MASK;
-}
-
-/*! @}*/
-
-/*!
- * @brief Reset the counter.
- *
- * The timer counter and prescale counter are reset on the next positive edge of the APB clock.
- *
- * @param base Ctimer peripheral base address
- */
-static inline void CTIMER_Reset(CTIMER_Type *base)
-{
- base->TCR |= CTIMER_TCR_CRST_MASK;
- base->TCR &= ~CTIMER_TCR_CRST_MASK;
-}
-
-#if defined(__cplusplus)
-}
-#endif
-
-/*! @}*/
-
-#endif /* _FSL_CTIMER_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.c
deleted file mode 100755
index d51eb72f0..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.c
+++ /dev/null
@@ -1,404 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2019 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_common.h"
-#include "fsl_flexcomm.h"
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.flexcomm"
-#endif
-
-/*******************************************************************************
- * Prototypes
- ******************************************************************************/
-/*! @brief Set the FLEXCOMM mode . */
-static status_t FLEXCOMM_SetPeriph(FLEXCOMM_Type *base, FLEXCOMM_PERIPH_T periph, int lock);
-
-/*! @brief check whether flexcomm supports peripheral type */
-static bool FLEXCOMM_PeripheralIsPresent(FLEXCOMM_Type *base, FLEXCOMM_PERIPH_T periph);
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-
-/*! @brief Pointers to real IRQ handlers installed by drivers for each instance. */
-static flexcomm_irq_handler_t s_flexcommIrqHandler[FSL_FEATURE_SOC_FLEXCOMM_COUNT];
-
-/*! @brief Pointers to handles for each instance to provide context to interrupt routines */
-static void *s_flexcommHandle[FSL_FEATURE_SOC_FLEXCOMM_COUNT];
-
-/*! @brief Array to map FLEXCOMM instance number to IRQ number. */
-IRQn_Type const kFlexcommIrqs[] = FLEXCOMM_IRQS;
-
-/*! @brief Array to map FLEXCOMM instance number to base address. */
-static const uint32_t s_flexcommBaseAddrs[FSL_FEATURE_SOC_FLEXCOMM_COUNT] = FLEXCOMM_BASE_ADDRS;
-
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
-/*! @brief IDs of clock for each FLEXCOMM module */
-static const clock_ip_name_t s_flexcommClocks[] = FLEXCOMM_CLOCKS;
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-
-#if !(defined(FSL_FEATURE_FLEXCOMM_HAS_NO_RESET) && FSL_FEATURE_FLEXCOMM_HAS_NO_RESET)
-/*! @brief Pointers to FLEXCOMM resets for each instance. */
-static const reset_ip_name_t s_flexcommResets[] = FLEXCOMM_RSTS;
-#endif
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-/* check whether flexcomm supports peripheral type */
-static bool FLEXCOMM_PeripheralIsPresent(FLEXCOMM_Type *base, FLEXCOMM_PERIPH_T periph)
-{
- if (periph == FLEXCOMM_PERIPH_NONE)
- {
- return true;
- }
- else if (periph <= FLEXCOMM_PERIPH_I2S_TX)
- {
- return (base->PSELID & (uint32_t)(1 << ((uint32_t)periph + 3))) > (uint32_t)0 ? true : false;
- }
- else if (periph == FLEXCOMM_PERIPH_I2S_RX)
- {
- return (base->PSELID & (1 << 7)) > (uint32_t)0 ? true : false;
- }
- else
- {
- return false;
- }
-}
-
-/* Get the index corresponding to the FLEXCOMM */
-/*! brief Returns instance number for FLEXCOMM module with given base address. */
-uint32_t FLEXCOMM_GetInstance(void *base)
-{
- int i;
-
- for (i = 0; i < FSL_FEATURE_SOC_FLEXCOMM_COUNT; i++)
- {
- if ((uint32_t)base == s_flexcommBaseAddrs[i])
- {
- return i;
- }
- }
-
- assert(false);
- return 0;
-}
-
-/* Changes FLEXCOMM mode */
-static status_t FLEXCOMM_SetPeriph(FLEXCOMM_Type *base, FLEXCOMM_PERIPH_T periph, int lock)
-{
- /* Check whether peripheral type is present */
- if (!FLEXCOMM_PeripheralIsPresent(base, periph))
- {
- return kStatus_OutOfRange;
- }
-
- /* Flexcomm is locked to different peripheral type than expected */
- if ((base->PSELID & FLEXCOMM_PSELID_LOCK_MASK) && ((base->PSELID & FLEXCOMM_PSELID_PERSEL_MASK) != periph))
- {
- return kStatus_Fail;
- }
-
- /* Check if we are asked to lock */
- if (lock)
- {
- base->PSELID = (uint32_t)periph | FLEXCOMM_PSELID_LOCK_MASK;
- }
- else
- {
- base->PSELID = (uint32_t)periph;
- }
-
- return kStatus_Success;
-}
-
-/*! brief Initializes FLEXCOMM and selects peripheral mode according to the second parameter. */
-status_t FLEXCOMM_Init(void *base, FLEXCOMM_PERIPH_T periph)
-{
- int idx = FLEXCOMM_GetInstance(base);
-
- if (idx < 0)
- {
- return kStatus_InvalidArgument;
- }
-
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- /* Enable the peripheral clock */
- CLOCK_EnableClock(s_flexcommClocks[idx]);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-
-#if !(defined(FSL_FEATURE_FLEXCOMM_HAS_NO_RESET) && FSL_FEATURE_FLEXCOMM_HAS_NO_RESET)
- /* Reset the FLEXCOMM module */
- RESET_PeripheralReset(s_flexcommResets[idx]);
-#endif
-
- /* Set the FLEXCOMM to given peripheral */
- return FLEXCOMM_SetPeriph((FLEXCOMM_Type *)base, periph, 0);
-}
-
-/*! brief Sets IRQ handler for given FLEXCOMM module. It is used by drivers register IRQ handler according to FLEXCOMM
- * mode */
-void FLEXCOMM_SetIRQHandler(void *base, flexcomm_irq_handler_t handler, void *handle)
-{
- uint32_t instance;
-
- /* Look up instance number */
- instance = FLEXCOMM_GetInstance(base);
-
- /* Clear handler first to avoid execution of the handler with wrong handle */
- s_flexcommIrqHandler[instance] = NULL;
- s_flexcommHandle[instance] = handle;
- s_flexcommIrqHandler[instance] = handler;
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-
-/* IRQ handler functions overloading weak symbols in the startup */
-#if defined(FLEXCOMM0)
-void FLEXCOMM0_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[0]);
- s_flexcommIrqHandler[0]((void *)s_flexcommBaseAddrs[0], s_flexcommHandle[0]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM1)
-void FLEXCOMM1_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[1]);
- s_flexcommIrqHandler[1]((void *)s_flexcommBaseAddrs[1], s_flexcommHandle[1]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM2)
-void FLEXCOMM2_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[2]);
- s_flexcommIrqHandler[2]((void *)s_flexcommBaseAddrs[2], s_flexcommHandle[2]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM3)
-void FLEXCOMM3_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[3]);
- s_flexcommIrqHandler[3]((void *)s_flexcommBaseAddrs[3], s_flexcommHandle[3]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM4)
-void FLEXCOMM4_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[4]);
- s_flexcommIrqHandler[4]((void *)s_flexcommBaseAddrs[4], s_flexcommHandle[4]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-
-#endif
-
-#if defined(FLEXCOMM5)
-void FLEXCOMM5_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[5]);
- s_flexcommIrqHandler[5]((void *)s_flexcommBaseAddrs[5], s_flexcommHandle[5]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM6)
-void FLEXCOMM6_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[6]);
- s_flexcommIrqHandler[6]((void *)s_flexcommBaseAddrs[6], s_flexcommHandle[6]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM7)
-void FLEXCOMM7_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[7]);
- s_flexcommIrqHandler[7]((void *)s_flexcommBaseAddrs[7], s_flexcommHandle[7]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM8)
-void FLEXCOMM8_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[8]);
- s_flexcommIrqHandler[8]((void *)s_flexcommBaseAddrs[8], s_flexcommHandle[8]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM9)
-void FLEXCOMM9_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[9]);
- s_flexcommIrqHandler[9]((void *)s_flexcommBaseAddrs[9], s_flexcommHandle[9]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM10)
-void FLEXCOMM10_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[10]);
- s_flexcommIrqHandler[10]((void *)s_flexcommBaseAddrs[10], s_flexcommHandle[10]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM11)
-void FLEXCOMM11_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[11]);
- s_flexcommIrqHandler[11]((void *)s_flexcommBaseAddrs[11], s_flexcommHandle[11]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM12)
-void FLEXCOMM12_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[12]);
- s_flexcommIrqHandler[12]((void *)s_flexcommBaseAddrs[12], s_flexcommHandle[12]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM13)
-void FLEXCOMM13_DriverIRQHandler(void)
-{
- assert(s_flexcommIrqHandler[13]);
- s_flexcommIrqHandler[13]((void *)s_flexcommBaseAddrs[13], s_flexcommHandle[13]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM14)
-void FLEXCOMM14_DriverIRQHandler(void)
-{
- uint32_t instance;
-
- /* Look up instance number */
- instance = FLEXCOMM_GetInstance(FLEXCOMM14);
- assert(s_flexcommIrqHandler[instance]);
- s_flexcommIrqHandler[instance]((void *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM15)
-void FLEXCOMM15_DriverIRQHandler(void)
-{
- uint32_t instance;
-
- /* Look up instance number */
- instance = FLEXCOMM_GetInstance(FLEXCOMM15);
- assert(s_flexcommIrqHandler[instance]);
- s_flexcommIrqHandler[instance]((void *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
-
-#if defined(FLEXCOMM16)
-void FLEXCOMM16_DriverIRQHandler(void)
-{
- uint32_t instance;
-
- /* Look up instance number */
- instance = FLEXCOMM_GetInstance(FLEXCOMM16);
- assert(s_flexcommIrqHandler[instance]);
- s_flexcommIrqHandler[instance]((void *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
-/* Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
- exception return operation might vector to incorrect interrupt */
-#if defined __CORTEX_M && (__CORTEX_M == 4U)
- __DSB();
-#endif
-}
-#endif
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.h
deleted file mode 100755
index cf5b6ef99..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_flexcomm.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2019 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-#ifndef _FSL_FLEXCOMM_H_
-#define _FSL_FLEXCOMM_H_
-
-#include "fsl_common.h"
-
-/*!
- * @addtogroup flexcomm_driver
- * @{
- */
-
-/*! @name Driver version */
-/*@{*/
-/*! @brief FlexCOMM driver version 2.0.2. */
-#define FSL_FLEXCOMM_DRIVER_VERSION (MAKE_VERSION(2, 0, 2))
-/*@}*/
-
-/*! @brief FLEXCOMM peripheral modes. */
-typedef enum
-{
- FLEXCOMM_PERIPH_NONE, /*!< No peripheral */
- FLEXCOMM_PERIPH_USART, /*!< USART peripheral */
- FLEXCOMM_PERIPH_SPI, /*!< SPI Peripheral */
- FLEXCOMM_PERIPH_I2C, /*!< I2C Peripheral */
- FLEXCOMM_PERIPH_I2S_TX, /*!< I2S TX Peripheral */
- FLEXCOMM_PERIPH_I2S_RX, /*!< I2S RX Peripheral */
-} FLEXCOMM_PERIPH_T;
-
-/*! @brief Typedef for interrupt handler. */
-typedef void (*flexcomm_irq_handler_t)(void *base, void *handle);
-
-/*! @brief Array with IRQ number for each FLEXCOMM module. */
-extern IRQn_Type const kFlexcommIrqs[];
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*! @brief Returns instance number for FLEXCOMM module with given base address. */
-uint32_t FLEXCOMM_GetInstance(void *base);
-
-/*! @brief Initializes FLEXCOMM and selects peripheral mode according to the second parameter. */
-status_t FLEXCOMM_Init(void *base, FLEXCOMM_PERIPH_T periph);
-
-/*! @brief Sets IRQ handler for given FLEXCOMM module. It is used by drivers register IRQ handler according to FLEXCOMM
- * mode */
-void FLEXCOMM_SetIRQHandler(void *base, flexcomm_irq_handler_t handler, void *handle);
-
-#if defined(__cplusplus)
-}
-#endif
-
-/*@}*/
-
-#endif /* _FSL_FLEXCOMM_H_*/
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.c
deleted file mode 100755
index 9a2d9ee0b..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.c
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_gpio.h"
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.lpc_gpio"
-#endif
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
-/*! @brief Array to map FGPIO instance number to clock name. */
-static const clock_ip_name_t s_gpioClockName[] = GPIO_CLOCKS;
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-
-#if !(defined(FSL_FEATURE_GPIO_HAS_NO_RESET) && FSL_FEATURE_GPIO_HAS_NO_RESET)
-/*! @brief Pointers to GPIO resets for each instance. */
-static const reset_ip_name_t s_gpioResets[] = GPIO_RSTS_N;
-#endif
-/*******************************************************************************
- * Prototypes
- ************ ******************************************************************/
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-/*!
- * brief Initializes the GPIO peripheral.
- *
- * This function ungates the GPIO clock.
- *
- * param base GPIO peripheral base pointer.
- * param port GPIO port number.
- */
-void GPIO_PortInit(GPIO_Type *base, uint32_t port)
-{
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- assert(port < ARRAY_SIZE(s_gpioClockName));
-
- /* Upgate the GPIO clock */
- CLOCK_EnableClock(s_gpioClockName[port]);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-#if !(defined(FSL_FEATURE_GPIO_HAS_NO_RESET) && FSL_FEATURE_GPIO_HAS_NO_RESET)
- /* Reset the GPIO module */
- RESET_PeripheralReset(s_gpioResets[port]);
-#endif
-}
-
-/*!
- * brief Initializes a GPIO pin used by the board.
- *
- * To initialize the GPIO, define a pin configuration, either input or output, in the user file.
- * Then, call the GPIO_PinInit() function.
- *
- * This is an example to define an input pin or output pin configuration:
- * code
- * // Define a digital input pin configuration,
- * gpio_pin_config_t config =
- * {
- * kGPIO_DigitalInput,
- * 0,
- * }
- * //Define a digital output pin configuration,
- * gpio_pin_config_t config =
- * {
- * kGPIO_DigitalOutput,
- * 0,
- * }
- * endcode
- *
- * param base GPIO peripheral base pointer(Typically GPIO)
- * param port GPIO port number
- * param pin GPIO pin number
- * param config GPIO pin configuration pointer
- */
-void GPIO_PinInit(GPIO_Type *base, uint32_t port, uint32_t pin, const gpio_pin_config_t *config)
-{
- if (config->pinDirection == kGPIO_DigitalInput)
- {
-#if defined(FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR) && (FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR)
- base->DIRCLR[port] = 1U << pin;
-#else
- base->DIR[port] &= ~(1U << pin);
-#endif /*FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR*/
- }
- else
- {
- /* Set default output value */
- if (config->outputLogic == 0U)
- {
- base->CLR[port] = (1U << pin);
- }
- else
- {
- base->SET[port] = (1U << pin);
- }
-/* Set pin direction */
-#if defined(FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR) && (FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR)
- base->DIRSET[port] = 1U << pin;
-#else
- base->DIR[port] |= 1U << pin;
-#endif /*FSL_FEATURE_GPIO_DIRSET_AND_DIRCLR*/
- }
-}
-
-#if defined(FSL_FEATURE_GPIO_HAS_INTERRUPT) && FSL_FEATURE_GPIO_HAS_INTERRUPT
-/*!
- * @brief Configures the gpio pin interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number
- * @param pin GPIO pin number.
- * @param config GPIO pin interrupt configuration..
- */
-void GPIO_SetPinInterruptConfig(GPIO_Type *base, uint32_t port, uint32_t pin, gpio_interrupt_config_t *config)
-{
- base->INTEDG[port] = base->INTEDG[port] | (config->mode << pin);
-
- base->INTPOL[port] = base->INTPOL[port] | (config->polarity << pin);
-}
-
-/*!
- * @brief Enables multiple pins interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PortEnableInterrupts(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask)
-{
- if (kGPIO_InterruptA == index)
- {
- base->INTENA[port] = base->INTENA[port] | mask;
- }
- else if (kGPIO_InterruptB == index)
- {
- base->INTENB[port] = base->INTENB[port] | mask;
- }
- else
- {
- /*Should not enter here*/
- }
-}
-
-/*!
- * @brief Disables multiple pins interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PortDisableInterrupts(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask)
-{
- if (kGPIO_InterruptA == index)
- {
- base->INTENA[port] = base->INTENA[port] & ~mask;
- }
- else if (kGPIO_InterruptB == index)
- {
- base->INTENB[port] = base->INTENB[port] & ~mask;
- }
- else
- {
- /*Should not enter here*/
- }
-}
-
-/*!
- * @brief Clears multiple pins interrupt flag. Status flags are cleared by
- * writing a 1 to the corresponding bit position.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PortClearInterruptFlags(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask)
-{
- if (kGPIO_InterruptA == index)
- {
- base->INTSTATA[port] = mask;
- }
- else if (kGPIO_InterruptB == index)
- {
- base->INTSTATB[port] = mask;
- }
- else
- {
- /*Should not enter here*/
- }
-}
-
-/*!
- * @ Read port interrupt status.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number
- * @param index GPIO interrupt number.
- * @retval masked GPIO status value
- */
-uint32_t GPIO_PortGetInterruptStatus(GPIO_Type *base, uint32_t port, uint32_t index)
-{
- uint32_t status = 0U;
-
- if (kGPIO_InterruptA == index)
- {
- status = base->INTSTATA[port];
- }
- else if (kGPIO_InterruptB == index)
- {
- status = base->INTSTATB[port];
- }
- else
- {
- /*Should not enter here*/
- }
- return status;
-}
-
-/*!
- * @brief Enables the specific pin interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param pin GPIO pin number.
- * @param index GPIO interrupt number.
- */
-void GPIO_PinEnableInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index)
-{
- if (kGPIO_InterruptA == index)
- {
- base->INTENA[port] = base->INTENA[port] | (1U << pin);
- }
- else if (kGPIO_InterruptB == index)
- {
- base->INTENB[port] = base->INTENB[port] | (1U << pin);
- }
- else
- {
- /*Should not enter here*/
- }
-}
-
-/*!
- * @brief Disables the specific pin interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param pin GPIO pin number.
- * @param index GPIO interrupt number.
- */
-void GPIO_PinDisableInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index)
-{
- if (kGPIO_InterruptA == index)
- {
- base->INTENA[port] = base->INTENA[port] & ~(1U << pin);
- }
- else if (kGPIO_InterruptB == index)
- {
- base->INTENB[port] = base->INTENB[port] & ~(1U << pin);
- }
- else
- {
- /*Should not enter here*/
- }
-}
-
-/*!
- * @brief Clears the specific pin interrupt flag. Status flags are cleared by
- * writing a 1 to the corresponding bit position.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PinClearInterruptFlag(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index)
-{
- if (kGPIO_InterruptA == index)
- {
- base->INTSTATA[port] = 1U << pin;
- }
- else if (kGPIO_InterruptB == index)
- {
- base->INTSTATB[port] = 1U << pin;
- }
- else
- {
- /*Should not enter here*/
- }
-}
-#endif /* FSL_FEATURE_GPIO_HAS_INTERRUPT */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.h
deleted file mode 100755
index f1762502b..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_gpio.h
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _LPC_GPIO_H_
-#define _LPC_GPIO_H_
-
-#include "fsl_common.h"
-
-/*!
- * @addtogroup lpc_gpio
- * @{
- */
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/*! @name Driver version */
-/*@{*/
-/*! @brief LPC GPIO driver version 2.1.3. */
-#define FSL_GPIO_DRIVER_VERSION (MAKE_VERSION(2, 1, 4))
-/*@}*/
-
-/*! @brief LPC GPIO direction definition */
-typedef enum _gpio_pin_direction
-{
- kGPIO_DigitalInput = 0U, /*!< Set current pin as digital input*/
- kGPIO_DigitalOutput = 1U, /*!< Set current pin as digital output*/
-} gpio_pin_direction_t;
-
-/*!
- * @brief The GPIO pin configuration structure.
- *
- * Every pin can only be configured as either output pin or input pin at a time.
- * If configured as a input pin, then leave the outputConfig unused.
- */
-typedef struct _gpio_pin_config
-{
- gpio_pin_direction_t pinDirection; /*!< GPIO direction, input or output */
- /* Output configurations, please ignore if configured as a input one */
- uint8_t outputLogic; /*!< Set default output logic, no use in input */
-} gpio_pin_config_t;
-
-#if (defined(FSL_FEATURE_GPIO_HAS_INTERRUPT) && FSL_FEATURE_GPIO_HAS_INTERRUPT)
-#define GPIO_PIN_INT_LEVEL 0x00U
-#define GPIO_PIN_INT_EDGE 0x01U
-
-#define PINT_PIN_INT_HIGH_OR_RISE_TRIGGER 0x00U
-#define PINT_PIN_INT_LOW_OR_FALL_TRIGGER 0x01U
-
-/*! @brief GPIO Pin Interrupt enable mode */
-typedef enum _gpio_pin_enable_mode
-{
- kGPIO_PinIntEnableLevel = GPIO_PIN_INT_LEVEL, /*!< Generate Pin Interrupt on level mode */
- kGPIO_PinIntEnableEdge = GPIO_PIN_INT_EDGE /*!< Generate Pin Interrupt on edge mode */
-} gpio_pin_enable_mode_t;
-
-/*! @brief GPIO Pin Interrupt enable polarity */
-typedef enum _gpio_pin_enable_polarity
-{
- kGPIO_PinIntEnableHighOrRise =
- PINT_PIN_INT_HIGH_OR_RISE_TRIGGER, /*!< Generate Pin Interrupt on high level or rising edge */
- kGPIO_PinIntEnableLowOrFall =
- PINT_PIN_INT_LOW_OR_FALL_TRIGGER /*!< Generate Pin Interrupt on low level or falling edge */
-} gpio_pin_enable_polarity_t;
-
-/*! @brief LPC GPIO interrupt index definition */
-typedef enum _gpio_interrupt_index
-{
- kGPIO_InterruptA = 0U, /*!< Set current pin as interrupt A*/
- kGPIO_InterruptB = 1U, /*!< Set current pin as interrupt B*/
-} gpio_interrupt_index_t;
-
-/*! @brief Configures the interrupt generation condition. */
-typedef struct _gpio_interrupt_config
-{
- uint8_t mode; /* The trigger mode of GPIO interrupts */
- uint8_t polarity; /* The polarity of GPIO interrupts */
-} gpio_interrupt_config_t;
-#endif
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*! @name GPIO Configuration */
-/*@{*/
-
-/*!
- * @brief Initializes the GPIO peripheral.
- *
- * This function ungates the GPIO clock.
- *
- * @param base GPIO peripheral base pointer.
- * @param port GPIO port number.
- */
-void GPIO_PortInit(GPIO_Type *base, uint32_t port);
-
-/*!
- * @brief Initializes a GPIO pin used by the board.
- *
- * To initialize the GPIO, define a pin configuration, either input or output, in the user file.
- * Then, call the GPIO_PinInit() function.
- *
- * This is an example to define an input pin or output pin configuration:
- * @code
- * // Define a digital input pin configuration,
- * gpio_pin_config_t config =
- * {
- * kGPIO_DigitalInput,
- * 0,
- * }
- * //Define a digital output pin configuration,
- * gpio_pin_config_t config =
- * {
- * kGPIO_DigitalOutput,
- * 0,
- * }
- * @endcode
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param pin GPIO pin number
- * @param config GPIO pin configuration pointer
- */
-void GPIO_PinInit(GPIO_Type *base, uint32_t port, uint32_t pin, const gpio_pin_config_t *config);
-
-/*@}*/
-
-/*! @name GPIO Output Operations */
-/*@{*/
-
-/*!
- * @brief Sets the output level of the one GPIO pin to the logic 1 or 0.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param pin GPIO pin number
- * @param output GPIO pin output logic level.
- * - 0: corresponding pin output low-logic level.
- * - 1: corresponding pin output high-logic level.
- */
-static inline void GPIO_PinWrite(GPIO_Type *base, uint32_t port, uint32_t pin, uint8_t output)
-{
- base->B[port][pin] = output;
-}
-
-/*@}*/
-/*! @name GPIO Input Operations */
-/*@{*/
-
-/*!
- * @brief Reads the current input value of the GPIO PIN.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param pin GPIO pin number
- * @retval GPIO port input value
- * - 0: corresponding pin input low-logic level.
- * - 1: corresponding pin input high-logic level.
- */
-static inline uint32_t GPIO_PinRead(GPIO_Type *base, uint32_t port, uint32_t pin)
-{
- return (uint32_t)base->B[port][pin];
-}
-
-/*@}*/
-
-/*!
- * @brief Sets the output level of the multiple GPIO pins to the logic 1.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param mask GPIO pin number macro
- */
-static inline void GPIO_PortSet(GPIO_Type *base, uint32_t port, uint32_t mask)
-{
- base->SET[port] = mask;
-}
-
-/*!
- * @brief Sets the output level of the multiple GPIO pins to the logic 0.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param mask GPIO pin number macro
- */
-static inline void GPIO_PortClear(GPIO_Type *base, uint32_t port, uint32_t mask)
-{
- base->CLR[port] = mask;
-}
-
-/*!
- * @brief Reverses current output logic of the multiple GPIO pins.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param mask GPIO pin number macro
- */
-static inline void GPIO_PortToggle(GPIO_Type *base, uint32_t port, uint32_t mask)
-{
- base->NOT[port] = mask;
-}
-
-/*@}*/
-
-/*!
- * @brief Reads the current input value of the whole GPIO port.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- */
-static inline uint32_t GPIO_PortRead(GPIO_Type *base, uint32_t port)
-{
- return (uint32_t)base->PIN[port];
-}
-
-/*@}*/
-/*! @name GPIO Mask Operations */
-/*@{*/
-
-/*!
- * @brief Sets port mask, 0 - enable pin, 1 - disable pin.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param mask GPIO pin number macro
- */
-static inline void GPIO_PortMaskedSet(GPIO_Type *base, uint32_t port, uint32_t mask)
-{
- base->MASK[port] = mask;
-}
-
-/*!
- * @brief Sets the output level of the masked GPIO port. Only pins enabled by GPIO_SetPortMask() will be affected.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @param output GPIO port output value.
- */
-static inline void GPIO_PortMaskedWrite(GPIO_Type *base, uint32_t port, uint32_t output)
-{
- base->MPIN[port] = output;
-}
-
-/*!
- * @brief Reads the current input value of the masked GPIO port. Only pins enabled by GPIO_SetPortMask() will be
- * affected.
- *
- * @param base GPIO peripheral base pointer(Typically GPIO)
- * @param port GPIO port number
- * @retval masked GPIO port value
- */
-static inline uint32_t GPIO_PortMaskedRead(GPIO_Type *base, uint32_t port)
-{
- return (uint32_t)base->MPIN[port];
-}
-
-#if defined(FSL_FEATURE_GPIO_HAS_INTERRUPT) && FSL_FEATURE_GPIO_HAS_INTERRUPT
-/*!
- * @brief Configures the gpio pin interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number
- * @param pin GPIO pin number.
- * @param config GPIO pin interrupt configuration..
- */
-void GPIO_SetPinInterruptConfig(GPIO_Type *base, uint32_t port, uint32_t pin, gpio_interrupt_config_t *config);
-
-/*!
- * @brief Enables multiple pins interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PortEnableInterrupts(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask);
-
-/*!
- * @brief Disables multiple pins interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PortDisableInterrupts(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask);
-
-/*!
- * @brief Clears pin interrupt flag. Status flags are cleared by
- * writing a 1 to the corresponding bit position.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param index GPIO interrupt number.
- * @param mask GPIO pin number macro.
- */
-void GPIO_PortClearInterruptFlags(GPIO_Type *base, uint32_t port, uint32_t index, uint32_t mask);
-
-/*!
- * @ Read port interrupt status.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number
- * @param index GPIO interrupt number.
- * @retval masked GPIO status value
- */
-uint32_t GPIO_PortGetInterruptStatus(GPIO_Type *base, uint32_t port, uint32_t index);
-
-/*!
- * @brief Enables the specific pin interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param pin GPIO pin number.
- * @param index GPIO interrupt number.
- */
-void GPIO_PinEnableInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index);
-
-/*!
- * @brief Disables the specific pin interrupt.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param pin GPIO pin number.
- * @param index GPIO interrupt number.
- */
-void GPIO_PinDisableInterrupt(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index);
-
-/*!
- * @brief Clears the specific pin interrupt flag. Status flags are cleared by
- * writing a 1 to the corresponding bit position.
- *
- * @param base GPIO base pointer.
- * @param port GPIO port number.
- * @param pin GPIO pin number.
- * @param index GPIO interrupt number.
- */
-void GPIO_PinClearInterruptFlag(GPIO_Type *base, uint32_t port, uint32_t pin, uint32_t index);
-
-#endif /* FSL_FEATURE_GPIO_HAS_INTERRUPT */
-
-/*@}*/
-
-#if defined(__cplusplus)
-}
-#endif
-
-/*!
- * @}
- */
-
-#endif /* _LPC_GPIO_H_*/
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.c
deleted file mode 100755
index b6c323c6d..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.c
+++ /dev/null
@@ -1,1316 +0,0 @@
-/*
- * Copyright 2017-2019 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "fsl_hashcrypt.h"
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.hashcrypt"
-#endif
-
-/*******************************************************************************
- * Definitions
- *******************************************************************************/
-
-/*!< SHA-1 and SHA-256 block size */
-#define SHA_BLOCK_SIZE 64
-/*!< max number of blocks that can be proccessed in one run (master mode) */
-#define SHA_MASTER_MAX_BLOCKS 2048
-
-/*!< Use standard C library memcpy */
-#define hashcrypt_memcpy memcpy
-
-/*! Internal states of the HASH creation process */
-typedef enum _hashcrypt_sha_algo_state
-{
- kHASHCRYPT_HashInit = 1u, /*!< Init state, the NEW bit in SHA Control register has not been written yet. */
- kHASHCRYPT_HashUpdate, /*!< Update state, DIGEST registers contain running hash, NEW bit in SHA control register has
- been written. */
-} hashcrypt_sha_algo_state_t;
-
-/*! 64-byte block represented as byte array of 16 32-bit words */
-typedef union _sha_hash_block
-{
- uint32_t w[SHA_BLOCK_SIZE / 4]; /*!< array of 32-bit words */
- uint8_t b[SHA_BLOCK_SIZE]; /*!< byte array */
-} hashcrypt_sha_block_t;
-
-/*! internal sha context structure */
-typedef struct _hashcrypt_sha_ctx_internal
-{
- hashcrypt_sha_block_t blk; /*!< memory buffer. only full 64-byte blocks are written to SHA during hash updates */
- size_t blksz; /*!< number of valid bytes in memory buffer */
- hashcrypt_algo_t algo; /*!< selected algorithm from the set of supported algorithms */
- hashcrypt_sha_algo_state_t state; /*!< finite machine state of the hash software process */
- size_t fullMessageSize; /*!< track message size during SHA_Update(). The value is used for padding. */
- uint32_t remainingBlcks; /*!< number of remaining blocks to process in AHB master mode */
- hashcrypt_callback_t hashCallback; /*!< pointer to HASH callback function */
- void
- *userData; /*!< user data to be passed as an argument to callback function, once callback is invoked from isr */
-#if defined(FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE) && (FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE > 0)
- uint32_t runningHash[8]; /*!< running hash. up to SHA-256, that is 32 bytes. */
-#endif
-} hashcrypt_sha_ctx_internal_t;
-
-#if defined(FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE) && (FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE > 0)
-#define SHA1_LEN 5u
-#define SHA256_LEN 8u
-#define ALG_MODE_MASK 0xFFFFFFF8u /*!< Algorithm mode mask */
-#endif
-
-/*!< SHA-1 and SHA-256 digest length in bytes */
-enum _hashcrypt_sha_digest_len
-{
- kHASHCRYPT_OutLenSha1 = 20u,
- kHASHCRYPT_OutLenSha256 = 32u,
-};
-
-/*!< pointer to hash context structure used by isr */
-static hashcrypt_hash_ctx_t *s_ctx;
-
-/*!< macro for checking build time condition. It is used to assure the hashcrypt_sha_ctx_internal_t can fit into
- * hashcrypt_hash_ctx_t */
-#define BUILD_ASSERT(condition, msg) extern int msg[1 - 2 * (!(condition))] __attribute__((unused))
-
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-/*!
- * @brief Swap bytes withing 32-bit word.
- *
- * This function changes endianess of a 32-bit word.
- *
- * @param in 32-bit unsigned integer
- * @return 32-bit unsigned integer with different endianess (big endian to little endian and vice versa).
- */
-
-#define swap_bytes(in) __REV(in)
-
-/*!
- * @brief Increment a 16 byte integer.
- *
- * This function increments by one a 16 byte integer.
- *
- * @param input Pointer to a 16 byte integer to be incremented by one.
- */
-static void ctrIncrement(uint8_t *input)
-{
- int i = 15;
- while (input[i] == (uint8_t)0xFFu)
- {
- input[i] = (uint8_t)0x00u;
- i--;
- if (i < 0)
- {
- return;
- }
- }
-
- if (i >= 0)
- {
- input[i] += (uint8_t)1u;
- }
-}
-
-/*!
- * @brief Reads an unaligned word.
- *
- * This function creates a 32-bit word from an input array of four bytes.
- *
- * @param src Input array of four bytes. The array can start at any address in memory.
- * @return 32-bit unsigned int created from the input byte array.
- */
-
-/* Force lower optimization for Keil, otherwise it replaces inline LDR with LDM */
-#if defined(__CC_ARM)
-#pragma push
-#pragma O0
-#endif
-
-static inline uint32_t hashcrypt_get_word_from_unaligned(const uint8_t *srcAddr)
-{
-#if (!(defined(__CORTEX_M)) || (defined(__CORTEX_M) && (__CORTEX_M == 0)))
- register const uint8_t *src = srcAddr;
- /* Cortex M0 does not support misaligned loads */
- if (0U != ((uint32_t)src & 0x3u))
- {
- union _align_bytes_t
- {
- uint32_t word;
- uint8_t byte[sizeof(uint32_t)];
- } my_bytes;
-
- my_bytes.byte[0] = *src;
- my_bytes.byte[1] = src[1];
- my_bytes.byte[2] = src[2];
- my_bytes.byte[3] = src[3];
- return my_bytes.word;
- }
- else
- {
- /* addr aligned to 0-modulo-4 so it is safe to type cast */
- return *((const uint32_t *)(uint32_t)src);
- }
-#elif defined(__CC_ARM)
- /* -O3 optimization in Keil 5.15 and 5.16a uses LDM instruction here (LDM r4!, {r0})
- * which is wrong, because srcAddr might be unaligned.
- * LDM on unaligned address causes hard-fault. in contrary,
- * LDR supports unaligned address on Cortex M4 */
-
- register uint32_t retVal;
- __asm
- {
- LDR retVal, [srcAddr]
- }
- return retVal;
-#else
- return *((const uint32_t *)srcAddr);
-#endif
-}
-
-/* End lower optimization */
-#if defined(__CC_ARM)
-#pragma pop
-#endif
-
-static status_t hashcrypt_get_key_from_unaligned_src(uint8_t *dest, const uint8_t *src, size_t size)
-{
- status_t retVal = kStatus_InvalidArgument;
- uint32_t i;
-
- /* destination is SDK driver internal workspace and it must be aligned */
- assert(0x0 == ((uint32_t)dest & 0x1u));
- if ((uint32_t)dest & 0x1u)
- {
- return retVal;
- }
-
- for (i = 0; i < ((uint32_t)size / 4u); i++)
- {
- ((uint32_t *)dest)[i] = hashcrypt_get_word_from_unaligned(&src[i * sizeof(uint32_t)]);
- }
-
- return kStatus_Success;
-}
-
-/*!
- * @brief LDM to SHA engine INDATA and ALIAS registers.
- *
- * This function writes 16 words starting from the src address (must be word aligned)
- * to the dst address. Dst address does not increment (destination is peripheral module register INDATA).
- * Src address increments to load 16 consecutive words.
- *
- * @param dst peripheral register address (word aligned)
- * @param src address of the input 512-bit block (16 words) (word aligned)
- *
- */
-__STATIC_FORCEINLINE void hashcrypt_sha_ldm_stm_16_words(HASHCRYPT_Type *base, const uint32_t *src)
-{
- /*
- typedef struct _one_block
- {
- uint32_t a[8];
- } one_block_t;
-
- volatile one_block_t *ldst = (void *)(uintptr_t)(&base->INDATA);
- one_block_t *lsrc = (void *)(uintptr_t)src;
- *ldst = lsrc[0];
- *ldst = lsrc[1];
- */
- base->MEMADDR = HASHCRYPT_MEMADDR_BASE(src);
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(1) | HASHCRYPT_MEMCTRL_COUNT(1);
-}
-
-/*!
- * @brief Loads data to Hashcrypt engine INDATA register.
- *
- * This function writes desired number of bytes starting from the src address (must be word aligned)
- * to the dst address. Dst address does not increment (destination is peripheral module register INDATA).
- * Src address increments to load consecutive words.
- *
- * @param dst peripheral register address (word aligned)
- * @param src address of the input block (word aligned)
- * @param size number of bytes to write (word aligned)
- *
- */
-__STATIC_INLINE void hashcrypt_load_data(HASHCRYPT_Type *base, const uint32_t *src, size_t size)
-{
- if (size >= sizeof(uint32_t))
- {
- base->INDATA = src[0];
- size -= sizeof(uint32_t);
- }
-
- for (uint32_t i = 0; i < size / 4; i++)
- {
- base->ALIAS[i] = src[i + 1];
- }
-}
-
-/*!
- * @brief Checks availability of HW AES key.
- *
- * This function checks if the AES key is present at dedicated hardware bus
- * and can be used at actual security level.
- *
- * @param base HASHCRYPT peripheral base address
- * @param handle Handle used for this request.
- * @return kStatus_Success if available, kStatus_Fail otherwise.
- *
- */
-static status_t hashcrypt_check_need_key(HASHCRYPT_Type *base, hashcrypt_handle_t *handle)
-{
- if (handle->keyType == kHASHCRYPT_SecretKey)
- {
- volatile uint32_t wait = 50u;
- /* wait until STATUS register is non-zero */
- while ((base->STATUS == 0) && (wait > 0))
- {
- wait--;
- }
- /* if NEEDKEY bit is not set, HW key is available */
- if (0 == (base->STATUS & HASHCRYPT_STATUS_NEEDKEY_MASK))
- {
- return kStatus_Success;
- }
- /* NEEDKEY is set, HW key is not available */
- return kStatus_Fail;
- }
- else
- {
- /* in case user key is used, return success */
- return kStatus_Success;
- }
-}
-
-/*!
- * @brief Read OUTDATA registers.
- *
- * This function copies OUTDATA to output buffer.
- *
- * @param base Hachcrypt peripheral base address.
- * @param[out] output Output buffer.
- * @param Number of bytes to copy.
- */
-static void hashcrypt_get_data(HASHCRYPT_Type *base, uint32_t *output, size_t outputSize)
-{
- uint32_t digest[8];
-
- while (0 == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
- {
- }
-
- for (int i = 0; i < 8; i++)
- {
- digest[i] = swap_bytes(base->DIGEST0[i]);
- }
-
- if (outputSize > sizeof(digest))
- {
- outputSize = sizeof(digest);
- }
- hashcrypt_memcpy(output, digest, outputSize);
-}
-
-/*!
- * @brief Initialize the Hashcrypt engine for new operation.
- *
- * This function sets NEW and MODE fields in Hashcrypt Control register to start new operation.
- *
- * @param base Hashcrypt peripheral base address.
- * @param hashcrypt_algo_t Internal context.
- */
-static void hashcrypt_engine_init(HASHCRYPT_Type *base, hashcrypt_algo_t algo)
-{
- /* NEW bit must be set before we switch from previous mode otherwise new mode will not work correctly */
- base->CTRL = HASHCRYPT_CTRL_NEW_HASH(1);
- base->CTRL = HASHCRYPT_CTRL_MODE(algo) | HASHCRYPT_CTRL_NEW_HASH(1);
-}
-
-/*!
- * @brief Loads user key to INDATA register.
- *
- * This function writes user key stored in handle into HashCrypt INDATA register.
- *
- * @param base Hashcrypt peripheral base address.
- * @param handle Handle used for this request.
- */
-static void hashcrypt_aes_load_userKey(HASHCRYPT_Type *base, hashcrypt_handle_t *handle)
-{
- size_t keySize = 0;
-
- switch (handle->keySize)
- {
- case kHASHCRYPT_Aes128:
- keySize = 16;
- break;
- case kHASHCRYPT_Aes192:
- keySize = 24;
- break;
- case kHASHCRYPT_Aes256:
- keySize = 32;
- break;
- default:
- break;
- }
- if (keySize == 0)
- {
- return;
- }
- hashcrypt_load_data(base, &handle->keyWord[0], keySize);
-}
-
-/*!
- * @brief Performs AES encryption/decryption of one data block.
- *
- * This function encrypts/decrypts one block of data with specified size.
- *
- * @param base Hashcrypt peripheral base address.
- * @param input input data
- * @param output output data
- * @param size size of data block to process in bytes (must be 16bytes multiple).
- */
-static status_t hashcrypt_aes_one_block(HASHCRYPT_Type *base, const uint8_t *input, uint8_t *output, size_t size)
-{
- status_t status = kStatus_Fail;
- int idx = 0;
-
- /* we use AHB master mode as much as possible */
- /* however, it can work only with aligned input data */
- /* so, if unaligned, we do memcpy to temp buffer on stack, which is aligned, and use AHB mode to read data in */
- /* then we read data back to it and do memcpy to the output buffer */
- if (((uint32_t)input & 0x3u) || ((uint32_t)output & 0x3u))
- {
- uint32_t temp[256 / sizeof(uint32_t)];
- int cnt = 0;
- while (size)
- {
- size_t actSz = size >= 256u ? 256u : size;
- size_t actSzOrig = actSz;
- memcpy(temp, input + 256 * cnt, actSz);
- size -= actSz;
- base->MEMADDR = HASHCRYPT_MEMADDR_BASE(temp);
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(1) | HASHCRYPT_MEMCTRL_COUNT(actSz / 16);
- int outidx = 0;
- while (actSz)
- {
- while (0 == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
- {
- }
- for (int i = 0; i < 4; i++)
- {
- (temp + outidx)[i] = swap_bytes(base->DIGEST0[i]);
- }
- outidx += HASHCRYPT_AES_BLOCK_SIZE / 4;
- actSz -= HASHCRYPT_AES_BLOCK_SIZE;
- }
- memcpy(output + 256 * cnt, temp, actSzOrig);
- cnt++;
- }
- }
- else
- {
- base->MEMADDR = HASHCRYPT_MEMADDR_BASE(input);
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(1) | HASHCRYPT_MEMCTRL_COUNT(size / 16);
- while (size >= HASHCRYPT_AES_BLOCK_SIZE)
- {
- /* Get result */
- while (0 == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
- {
- }
-
- for (int i = 0; i < 4; i++)
- {
- ((uint32_t *)output + idx)[i] = swap_bytes(base->DIGEST0[i]);
- }
-
- idx += HASHCRYPT_AES_BLOCK_SIZE / 4;
- size -= HASHCRYPT_AES_BLOCK_SIZE;
- }
- }
-
- if (0 == (base->STATUS & HASHCRYPT_STATUS_ERROR_MASK))
- {
- status = kStatus_Success;
- }
-
- return status;
-}
-
-/*!
- * @brief Check validity of algoritm.
- *
- * This function checks the validity of input argument.
- *
- * @param algo Tested algorithm value.
- * @return kStatus_Success if valid, kStatus_InvalidArgument otherwise.
- */
-static status_t hashcrypt_sha_check_input_alg(HASHCRYPT_Type *base, hashcrypt_algo_t algo)
-{
- if ((algo == kHASHCRYPT_Sha1) || (algo == kHASHCRYPT_Sha256))
- {
- return kStatus_Success;
- }
-
- return kStatus_InvalidArgument;
-}
-
-/*!
- * @brief Check validity of input arguments.
- *
- * This function checks the validity of input arguments.
- *
- * @param base SHA peripheral base address.
- * @param ctx Memory buffer given by user application where the SHA_Init/SHA_Update/SHA_Finish store context.
- * @param algo Tested algorithm value.
- * @return kStatus_Success if valid, kStatus_InvalidArgument otherwise.
- */
-static status_t hashcrypt_sha_check_input_args(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, hashcrypt_algo_t algo)
-{
- /* Check validity of input algorithm */
- if (kStatus_Success != hashcrypt_sha_check_input_alg(base, algo))
- {
- return kStatus_InvalidArgument;
- }
-
- if ((NULL == ctx) || (NULL == base))
- {
- return kStatus_InvalidArgument;
- }
-
- return kStatus_Success;
-}
-
-/*!
- * @brief Check validity of internal software context.
- *
- * This function checks if the internal context structure looks correct.
- *
- * @param ctxInternal Internal context.
- * @return kStatus_Success if valid, kStatus_InvalidArgument otherwise.
- */
-static status_t hashcrypt_sha_check_context(HASHCRYPT_Type *base, hashcrypt_sha_ctx_internal_t *ctxInternal)
-{
- if ((NULL == ctxInternal) || (kStatus_Success != hashcrypt_sha_check_input_alg(base, ctxInternal->algo)))
- {
- return kStatus_InvalidArgument;
- }
- return kStatus_Success;
-}
-
-/*!
- * @brief Load 512-bit block (16 words) into SHA engine.
- *
- * This function aligns the input block and moves it into SHA engine INDATA.
- * CPU polls the WAITING bit and then moves data by using LDM and STM instructions.
- *
- * @param base SHA peripheral base address.
- * @param blk 512-bit block
- */
-static void hashcrypt_sha_one_block(HASHCRYPT_Type *base, const uint8_t *blk)
-{
- uint32_t temp[SHA_BLOCK_SIZE / sizeof(uint32_t)];
- const uint32_t *actBlk;
-
- /* make sure the 512-bit block is word aligned */
- if ((uintptr_t)blk & 0x3u)
- {
- hashcrypt_memcpy(temp, blk, SHA_BLOCK_SIZE);
- actBlk = (const uint32_t *)(uintptr_t)temp;
- }
- else
- {
- actBlk = (const uint32_t *)(uintptr_t)blk;
- }
-
- /* poll waiting. */
- while (0 == (base->STATUS & HASHCRYPT_STATUS_WAITING_MASK))
- {
- }
- /* feed INDATA (and ALIASes). use STM instruction. */
- hashcrypt_sha_ldm_stm_16_words(base, actBlk);
-}
-
-/*!
- * @brief Adds message to current hash.
- *
- * This function merges the message to fill the internal buffer, empties the internal buffer if
- * it becomes full, then process all remaining message data.
- *
- *
- * @param base SHA peripheral base address.
- * @param ctxInternal Internal context.
- * @param message Input message.
- * @param messageSize Size of input message in bytes.
- * @return kStatus_Success.
- */
-static status_t hashcrypt_sha_process_message_data(HASHCRYPT_Type *base,
- hashcrypt_sha_ctx_internal_t *ctxInternal,
- const uint8_t *message,
- size_t messageSize)
-{
- /* first fill the internal buffer to full block */
- if (ctxInternal->blksz)
- {
- size_t toCopy = SHA_BLOCK_SIZE - ctxInternal->blksz;
- hashcrypt_memcpy(&ctxInternal->blk.b[ctxInternal->blksz], message, toCopy);
- message += toCopy;
- messageSize -= toCopy;
-
- /* process full internal block */
- hashcrypt_sha_one_block(base, &ctxInternal->blk.b[0]);
- }
-
- /* process all full blocks in message[] */
- if (messageSize >= SHA_BLOCK_SIZE)
- {
- if ((uintptr_t)message & 0x3u)
- {
- while (messageSize >= SHA_BLOCK_SIZE)
- {
- hashcrypt_sha_one_block(base, message);
- message += SHA_BLOCK_SIZE;
- messageSize -= SHA_BLOCK_SIZE;
- }
- }
- else
- {
- /* poll waiting. */
- while (0 == (base->STATUS & HASHCRYPT_STATUS_WAITING_MASK))
- {
- }
- uint32_t blkNum = (messageSize >> 6); /* div by 64 bytes */
- uint32_t blkBytes = blkNum * 64u; /* number of bytes in 64 bytes blocks */
- base->MEMADDR = HASHCRYPT_MEMADDR_BASE(message);
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(1) | HASHCRYPT_MEMCTRL_COUNT(blkNum);
- message += blkBytes;
- messageSize -= blkBytes;
- while (0 == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
- {
- }
- }
- }
-
- /* copy last incomplete message bytes into internal block */
- hashcrypt_memcpy(&ctxInternal->blk.b[0], message, messageSize);
- ctxInternal->blksz = messageSize;
- return kStatus_Success;
-}
-
-/*!
- * @brief Finalize the running hash to make digest.
- *
- * This function empties the internal buffer, adds padding bits, and generates final digest.
- *
- * @param base SHA peripheral base address.
- * @param ctxInternal Internal context.
- * @return kStatus_Success.
- */
-static status_t hashcrypt_sha_finalize(HASHCRYPT_Type *base, hashcrypt_sha_ctx_internal_t *ctxInternal)
-{
- hashcrypt_sha_block_t lastBlock;
-
- memset(&lastBlock, 0, sizeof(hashcrypt_sha_block_t));
-
- /* this is last call, so need to flush buffered message bytes along with padding */
- if (ctxInternal->blksz <= 55u)
- {
- /* last data is 440 bits or less. */
- hashcrypt_memcpy(&lastBlock.b[0], &ctxInternal->blk.b[0], ctxInternal->blksz);
- lastBlock.b[ctxInternal->blksz] = (uint8_t)0x80U;
- lastBlock.w[SHA_BLOCK_SIZE / 4 - 1] = swap_bytes(8u * ctxInternal->fullMessageSize);
- hashcrypt_sha_one_block(base, &lastBlock.b[0]);
- }
- else
- {
- if (ctxInternal->blksz < SHA_BLOCK_SIZE)
- {
- ctxInternal->blk.b[ctxInternal->blksz] = (uint8_t)0x80U;
- for (uint32_t i = ctxInternal->blksz + 1u; i < SHA_BLOCK_SIZE; i++)
- {
- ctxInternal->blk.b[i] = 0;
- }
- }
- else
- {
- lastBlock.b[0] = (uint8_t)0x80U;
- }
-
- hashcrypt_sha_one_block(base, &ctxInternal->blk.b[0]);
- lastBlock.w[SHA_BLOCK_SIZE / 4 - 1] = swap_bytes(8u * ctxInternal->fullMessageSize);
- hashcrypt_sha_one_block(base, &lastBlock.b[0]);
- }
- /* poll wait for final digest */
- while (0 == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
- {
- }
- return kStatus_Success;
-}
-
-static void hashcrypt_save_running_hash(HASHCRYPT_Type *base, hashcrypt_sha_ctx_internal_t *ctxInternal)
-{
-#if defined(FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE) && (FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE > 0)
- size_t len = (ctxInternal->algo == kHASHCRYPT_Sha1) ? SHA1_LEN : SHA256_LEN;
-
- /* Wait until digest is ready */
- while (0 == (base->STATUS & HASHCRYPT_STATUS_DIGEST_MASK))
- {
- }
-
- /* Store partial digest to context */
- for (int i = 0; i < len; i++)
- {
- ctxInternal->runningHash[i] = base->DIGEST0[i];
- }
-#endif
-}
-
-static void hashcrypt_restore_running_hash(HASHCRYPT_Type *base, hashcrypt_sha_ctx_internal_t *ctxInternal)
-{
-#if defined(FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE) && (FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE > 0)
- size_t len = (ctxInternal->algo == kHASHCRYPT_Sha1) ? SHA1_LEN : SHA256_LEN;
-
- /* Set corresponding mode before reloadning the runningHash */
- base->CTRL = (base->CTRL & ALG_MODE_MASK) | HASHCRYPT_CTRL_MODE(ctxInternal->algo);
- /* Set RELOAD bit to allow registers to be used */
- base->CTRL |= HASHCRYPT_CTRL_RELOAD_MASK;
-
- /* Reload partial hash digest */
- for (int i = 0; i < len; i++)
- {
- base->RELOAD[i] = ctxInternal->runningHash[i];
- }
- /* Clear RELOAD register before continuing */
- base->CTRL &= ~HASHCRYPT_CTRL_RELOAD_MASK;
-#endif
-}
-
-status_t HASHCRYPT_SHA(HASHCRYPT_Type *base,
- hashcrypt_algo_t algo,
- const uint8_t *input,
- size_t inputSize,
- uint8_t *output,
- size_t *outputSize)
-{
- hashcrypt_hash_ctx_t hashCtx;
- status_t status;
-
- status = HASHCRYPT_SHA_Init(base, &hashCtx, algo);
- if (status != kStatus_Success)
- {
- return status;
- }
-
- status = HASHCRYPT_SHA_Update(base, &hashCtx, input, inputSize);
- if (status != kStatus_Success)
- {
- return status;
- }
-
- status = HASHCRYPT_SHA_Finish(base, &hashCtx, output, outputSize);
-
- return status;
-}
-
-status_t HASHCRYPT_SHA_Init(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, hashcrypt_algo_t algo)
-{
- status_t status;
-
- hashcrypt_sha_ctx_internal_t *ctxInternal;
- /* compile time check for the correct structure size */
- BUILD_ASSERT(sizeof(hashcrypt_hash_ctx_t) >= sizeof(hashcrypt_sha_ctx_internal_t), hashcrypt_hash_ctx_t_size);
-
- status = hashcrypt_sha_check_input_args(base, ctx, algo);
- if (status != kStatus_Success)
- {
- return status;
- }
-
- /* set algorithm in context struct for later use */
- ctxInternal = (hashcrypt_sha_ctx_internal_t *)ctx;
- ctxInternal->algo = algo;
- ctxInternal->blksz = 0u;
-#ifdef HASHCRYPT_SHA_DO_WIPE_CONTEXT
- for (int i = 0; i < sizeof(ctxInternal->blk.w) / sizeof(ctxInternal->blk.w[0]); i++)
- {
- ctxInternal->blk.w[i] = 0u;
- }
-#endif /* HASHCRYPT_SHA_DO_WIPE_CONTEXT */
- ctxInternal->state = kHASHCRYPT_HashInit;
- ctxInternal->fullMessageSize = 0;
- return kStatus_Success;
-}
-
-status_t HASHCRYPT_SHA_Update(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize)
-{
- bool isUpdateState;
- status_t status;
- hashcrypt_sha_ctx_internal_t *ctxInternal;
- size_t blockSize;
-
- if (inputSize == 0)
- {
- return kStatus_Success;
- }
-
- ctxInternal = (hashcrypt_sha_ctx_internal_t *)ctx;
-#ifdef HASHCRYPT_SHA_DO_CHECK_CONTEXT
- status = hashcrypt_sha_check_context(base, ctxInternal);
- if (kStatus_Success != status)
- {
- return status;
- }
-#endif /* HASHCRYPT_SHA_DO_CHECK_CONTEXT */
-
- ctxInternal->fullMessageSize += inputSize;
- blockSize = SHA_BLOCK_SIZE;
- /* if we are still less than 64 bytes, keep only in context */
- if ((ctxInternal->blksz + inputSize) <= blockSize)
- {
- hashcrypt_memcpy((&ctxInternal->blk.b[0]) + ctxInternal->blksz, input, inputSize);
- ctxInternal->blksz += inputSize;
- return kStatus_Success;
- }
- else
- {
- isUpdateState = ctxInternal->state == kHASHCRYPT_HashUpdate;
- if (!isUpdateState)
- {
- /* start NEW hash */
- hashcrypt_engine_init(base, ctxInternal->algo);
- ctxInternal->state = kHASHCRYPT_HashUpdate;
- }
- else
- {
- hashcrypt_restore_running_hash(base, ctxInternal);
- }
- }
-
- /* process message data */
- status = hashcrypt_sha_process_message_data(base, ctxInternal, input, inputSize);
- hashcrypt_save_running_hash(base, ctxInternal);
- return status;
-}
-
-status_t HASHCRYPT_SHA_Finish(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, uint8_t *output, size_t *outputSize)
-{
- size_t algOutSize = 0;
- status_t status;
- hashcrypt_sha_ctx_internal_t *ctxInternal;
-#ifdef HASHCRYPT_SHA_DO_CHECK_CONTEXT
- uint32_t *ctxW;
- uint32_t i;
-#endif /* HASHCRYPT_SHA_DO_CHECK_CONTEXT */
-
- if (output == NULL)
- {
- return kStatus_InvalidArgument;
- }
-
- ctxInternal = (hashcrypt_sha_ctx_internal_t *)ctx;
-#ifdef HASHCRYPT_SHA_DO_CHECK_CONTEXT
- status = hashcrypt_sha_check_context(base, ctxInternal);
- if (kStatus_Success != status)
- {
- return status;
- }
-#endif /* HASHCRYPT_SHA_DO_CHECK_CONTEXT */
-
- if (ctxInternal->state == kHASHCRYPT_HashInit)
- {
- hashcrypt_engine_init(base, ctxInternal->algo);
- }
- else
- {
- hashcrypt_restore_running_hash(base, ctxInternal);
- }
-
- size_t outSize = 0u;
-
- /* compute algorithm output length */
- switch (ctxInternal->algo)
- {
- case kHASHCRYPT_Sha1:
- outSize = kHASHCRYPT_OutLenSha1;
- break;
- case kHASHCRYPT_Sha256:
- outSize = kHASHCRYPT_OutLenSha256;
- break;
- default:
- break;
- }
- algOutSize = outSize;
-
- /* flush message last incomplete block, if there is any, and add padding bits */
- status = hashcrypt_sha_finalize(base, ctxInternal);
-
- if (outputSize)
- {
- if (algOutSize < *outputSize)
- {
- *outputSize = algOutSize;
- }
- else
- {
- algOutSize = *outputSize;
- }
- }
-
- hashcrypt_get_data(base, (uint32_t *)output, algOutSize);
-
-#ifdef HASHCRYPT_SHA_DO_WIPE_CONTEXT
- ctxW = (uint32_t *)ctx;
- for (i = 0; i < HASHCRYPT_HASH_CTX_SIZE; i++)
- {
- ctxW[i] = 0u;
- }
-#endif /* HASHCRYPT_SHA_DO_WIPE_CONTEXT */
- return status;
-}
-
-void HASHCRYPT_SHA_SetCallback(HASHCRYPT_Type *base,
- hashcrypt_hash_ctx_t *ctx,
- hashcrypt_callback_t callback,
- void *userData)
-{
- hashcrypt_sha_ctx_internal_t *ctxInternal;
-
- s_ctx = ctx;
- ctxInternal = (hashcrypt_sha_ctx_internal_t *)ctx;
- ctxInternal->hashCallback = callback;
- ctxInternal->userData = userData;
-
- EnableIRQ(HASHCRYPT_IRQn);
-}
-
-status_t HASHCRYPT_SHA_UpdateNonBlocking(HASHCRYPT_Type *base,
- hashcrypt_hash_ctx_t *ctx,
- const uint8_t *input,
- size_t inputSize)
-{
- hashcrypt_sha_ctx_internal_t *ctxInternal;
- uint32_t numBlocks;
- status_t status;
-
- if (inputSize == 0)
- {
- return kStatus_Success;
- }
-
- if ((uintptr_t)input & 0x3U)
- {
- return kStatus_Fail;
- }
-
- ctxInternal = (hashcrypt_sha_ctx_internal_t *)ctx;
- status = hashcrypt_sha_check_context(base, ctxInternal);
- if (kStatus_Success != status)
- {
- return status;
- }
-
- ctxInternal->fullMessageSize = inputSize;
- ctxInternal->remainingBlcks = inputSize / SHA_BLOCK_SIZE;
- ctxInternal->blksz = inputSize % SHA_BLOCK_SIZE;
-
- /* copy last incomplete block to context */
- if ((ctxInternal->blksz > 0) && (ctxInternal->blksz <= SHA_BLOCK_SIZE))
- {
- hashcrypt_memcpy((&ctxInternal->blk.b[0]), input + SHA_BLOCK_SIZE * ctxInternal->remainingBlcks,
- ctxInternal->blksz);
- }
-
- if (ctxInternal->remainingBlcks >= SHA_MASTER_MAX_BLOCKS)
- {
- numBlocks = SHA_MASTER_MAX_BLOCKS - 1;
- }
- else
- {
- numBlocks = ctxInternal->remainingBlcks;
- }
- /* update remainingBlks so that ISR can run another hash if necessary */
- ctxInternal->remainingBlcks -= numBlocks;
-
- /* compute hash using AHB Master mode for full blocks */
- if (numBlocks > 0)
- {
- ctxInternal->state = kHASHCRYPT_HashUpdate;
- hashcrypt_engine_init(base, ctxInternal->algo);
-
- /* Enable digest and error interrupts and start hash */
- base->INTENSET = HASHCRYPT_INTENCLR_DIGEST_MASK | HASHCRYPT_INTENCLR_ERROR_MASK;
- base->MEMADDR = HASHCRYPT_MEMADDR_BASE(input);
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(1) | HASHCRYPT_MEMCTRL_COUNT(numBlocks);
- }
- /* no full blocks, invoke callback directly */
- else
- {
- ctxInternal->hashCallback(HASHCRYPT, ctx, status, ctxInternal->userData);
- }
-
- return status;
-}
-
-status_t HASHCRYPT_AES_SetKey(HASHCRYPT_Type *base, hashcrypt_handle_t *handle, const uint8_t *key, size_t keySize)
-{
- status_t retVal = kStatus_InvalidArgument;
-
- switch (keySize)
- {
- case 16:
- handle->keySize = kHASHCRYPT_Aes128;
- break;
- case 24:
- handle->keySize = kHASHCRYPT_Aes192;
- break;
- case 32:
- handle->keySize = kHASHCRYPT_Aes256;
- break;
- default:
- handle->keySize = kHASHCRYPT_InvalidKey;
- break;
- }
-
- if (handle->keySize == kHASHCRYPT_InvalidKey)
- {
- return retVal;
- }
-
- if (handle->keyType == kHASHCRYPT_SecretKey)
- {
- /* for kHASHCRYPT_SecretKey just return Success */
- retVal = kStatus_Success;
- }
- else if (handle->keyType == kHASHCRYPT_UserKey)
- {
- retVal = hashcrypt_get_key_from_unaligned_src((uint8_t *)&handle->keyWord[0], key, keySize);
- }
- else
- {
- retVal = kStatus_InvalidArgument;
- }
-
- return retVal;
-}
-
-status_t HASHCRYPT_AES_EncryptEcb(
- HASHCRYPT_Type *base, hashcrypt_handle_t *handle, const uint8_t *plaintext, uint8_t *ciphertext, size_t size)
-{
- status_t status = kStatus_Fail;
-
- if ((size % 16u) || (handle->keySize == kHASHCRYPT_InvalidKey))
- {
- return kStatus_InvalidArgument;
- }
-
- uint32_t keyType = (handle->keyType == kHASHCRYPT_UserKey) ? 0 : 1u;
- base->CRYPTCFG = HASHCRYPT_CRYPTCFG_AESMODE(kHASHCRYPT_AesEcb) | HASHCRYPT_CRYPTCFG_AESDECRYPT(AES_ENCRYPT) |
- HASHCRYPT_CRYPTCFG_AESSECRET(keyType) | HASHCRYPT_CRYPTCFG_AESKEYSZ(handle->keySize) |
- HASHCRYPT_CRYPTCFG_MSW1ST_OUT(1) | HASHCRYPT_CRYPTCFG_SWAPKEY(1) | HASHCRYPT_CRYPTCFG_SWAPDAT(1) |
- HASHCRYPT_CRYPTCFG_MSW1ST(1);
-
- hashcrypt_engine_init(base, kHASHCRYPT_Aes);
-
- /* in case of HW AES key, check if it is available */
- if (hashcrypt_check_need_key(base, handle) != kStatus_Success)
- {
- return kStatus_Fail;
- }
-
- /* load key if kHASHCRYPT_UserKey is selected */
- if (handle->keyType == kHASHCRYPT_UserKey)
- {
- hashcrypt_aes_load_userKey(base, handle);
- }
-
- /* load message and get result */
- status = hashcrypt_aes_one_block(base, plaintext, ciphertext, size);
-
- return status;
-}
-
-status_t HASHCRYPT_AES_DecryptEcb(
- HASHCRYPT_Type *base, hashcrypt_handle_t *handle, const uint8_t *ciphertext, uint8_t *plaintext, size_t size)
-{
- status_t status = kStatus_Fail;
-
- if ((size % 16u) || (handle->keySize == kHASHCRYPT_InvalidKey))
- {
- return kStatus_InvalidArgument;
- }
-
- uint32_t keyType = (handle->keyType == kHASHCRYPT_UserKey) ? 0 : 1u;
- base->CRYPTCFG = HASHCRYPT_CRYPTCFG_AESMODE(kHASHCRYPT_AesEcb) | HASHCRYPT_CRYPTCFG_AESDECRYPT(AES_DECRYPT) |
- HASHCRYPT_CRYPTCFG_AESSECRET(keyType) | HASHCRYPT_CRYPTCFG_AESKEYSZ(handle->keySize) |
- HASHCRYPT_CRYPTCFG_MSW1ST_OUT(1) | HASHCRYPT_CRYPTCFG_SWAPKEY(1) | HASHCRYPT_CRYPTCFG_SWAPDAT(1) |
- HASHCRYPT_CRYPTCFG_MSW1ST(1);
-
- hashcrypt_engine_init(base, kHASHCRYPT_Aes);
-
- /* in case of HW AES key, check if it is available */
- if (hashcrypt_check_need_key(base, handle) != kStatus_Success)
- {
- return kStatus_Fail;
- }
-
- /* load key if kHASHCRYPT_UserKey is selected */
- if (handle->keyType == kHASHCRYPT_UserKey)
- {
- hashcrypt_aes_load_userKey(base, handle);
- }
-
- /* load message and get result */
- status = hashcrypt_aes_one_block(base, ciphertext, plaintext, size);
-
- return status;
-}
-
-status_t HASHCRYPT_AES_EncryptCbc(HASHCRYPT_Type *base,
- hashcrypt_handle_t *handle,
- const uint8_t *plaintext,
- uint8_t *ciphertext,
- size_t size,
- const uint8_t iv[16])
-{
- status_t status = kStatus_Fail;
-
- if ((size % 16u) || (handle->keySize == kHASHCRYPT_InvalidKey))
- {
- return kStatus_InvalidArgument;
- }
-
- uint32_t keyType = (handle->keyType == kHASHCRYPT_UserKey) ? 0 : 1u;
- base->CRYPTCFG = HASHCRYPT_CRYPTCFG_AESMODE(kHASHCRYPT_AesCbc) | HASHCRYPT_CRYPTCFG_AESDECRYPT(AES_ENCRYPT) |
- HASHCRYPT_CRYPTCFG_AESSECRET(keyType) | HASHCRYPT_CRYPTCFG_AESKEYSZ(handle->keySize) |
- HASHCRYPT_CRYPTCFG_MSW1ST_OUT(1) | HASHCRYPT_CRYPTCFG_SWAPKEY(1) | HASHCRYPT_CRYPTCFG_SWAPDAT(1) |
- HASHCRYPT_CRYPTCFG_MSW1ST(1);
-
- hashcrypt_engine_init(base, kHASHCRYPT_Aes);
-
- /* in case of HW AES key, check if it is available */
- if (hashcrypt_check_need_key(base, handle) != kStatus_Success)
- {
- return kStatus_Fail;
- }
-
- /* load key if kHASHCRYPT_UserKey is selected */
- if (handle->keyType == kHASHCRYPT_UserKey)
- {
- hashcrypt_aes_load_userKey(base, handle);
- }
-
- /* load 16b iv */
- hashcrypt_load_data(base, (uint32_t *)iv, 16);
-
- /* load message and get result */
- status = hashcrypt_aes_one_block(base, plaintext, ciphertext, size);
-
- return status;
-}
-
-status_t HASHCRYPT_AES_DecryptCbc(HASHCRYPT_Type *base,
- hashcrypt_handle_t *handle,
- const uint8_t *ciphertext,
- uint8_t *plaintext,
- size_t size,
- const uint8_t iv[16])
-{
- status_t status = kStatus_Fail;
-
- if ((size % 16u) || (handle->keySize == kHASHCRYPT_InvalidKey))
- {
- return kStatus_InvalidArgument;
- }
-
- uint32_t keyType = (handle->keyType == kHASHCRYPT_UserKey) ? 0 : 1u;
- base->CRYPTCFG = HASHCRYPT_CRYPTCFG_AESMODE(kHASHCRYPT_AesCbc) | HASHCRYPT_CRYPTCFG_AESDECRYPT(AES_DECRYPT) |
- HASHCRYPT_CRYPTCFG_AESSECRET(keyType) | HASHCRYPT_CRYPTCFG_AESKEYSZ(handle->keySize) |
- HASHCRYPT_CRYPTCFG_MSW1ST_OUT(1) | HASHCRYPT_CRYPTCFG_SWAPKEY(1) | HASHCRYPT_CRYPTCFG_SWAPDAT(1) |
- HASHCRYPT_CRYPTCFG_MSW1ST(1);
-
- hashcrypt_engine_init(base, kHASHCRYPT_Aes);
-
- /* in case of HW AES key, check if it is available */
- if (hashcrypt_check_need_key(base, handle) != kStatus_Success)
- {
- return kStatus_Fail;
- }
-
- /* load key if kHASHCRYPT_UserKey is selected */
- if (handle->keyType == kHASHCRYPT_UserKey)
- {
- hashcrypt_aes_load_userKey(base, handle);
- }
-
- /* load iv */
- hashcrypt_load_data(base, (uint32_t *)iv, 16);
-
- /* load message and get result */
- status = hashcrypt_aes_one_block(base, ciphertext, plaintext, size);
-
- return status;
-}
-
-status_t HASHCRYPT_AES_CryptCtr(HASHCRYPT_Type *base,
- hashcrypt_handle_t *handle,
- const uint8_t *input,
- uint8_t *output,
- size_t size,
- uint8_t counter[HASHCRYPT_AES_BLOCK_SIZE],
- uint8_t counterlast[HASHCRYPT_AES_BLOCK_SIZE],
- size_t *szLeft)
-{
- uint32_t lastSize;
- uint8_t lastBlock[HASHCRYPT_AES_BLOCK_SIZE] = {0};
- uint8_t *lastEncryptedCounter;
- status_t status = kStatus_Fail;
-
- if (handle->keySize == kHASHCRYPT_InvalidKey)
- {
- return kStatus_InvalidArgument;
- }
-
- uint32_t keyType = (handle->keyType == kHASHCRYPT_UserKey) ? 0 : 1u;
- base->CRYPTCFG = HASHCRYPT_CRYPTCFG_AESMODE(kHASHCRYPT_AesCtr) | HASHCRYPT_CRYPTCFG_AESDECRYPT(AES_ENCRYPT) |
- HASHCRYPT_CRYPTCFG_AESSECRET(keyType) | HASHCRYPT_CRYPTCFG_AESKEYSZ(handle->keySize) |
- HASHCRYPT_CRYPTCFG_MSW1ST_OUT(1) | HASHCRYPT_CRYPTCFG_SWAPKEY(1) | HASHCRYPT_CRYPTCFG_SWAPDAT(1) |
- HASHCRYPT_CRYPTCFG_MSW1ST(1);
-
- hashcrypt_engine_init(base, kHASHCRYPT_Aes);
-
- /* in case of HW AES key, check if it is available */
- if (hashcrypt_check_need_key(base, handle) != kStatus_Success)
- {
- return kStatus_Fail;
- }
-
- /* load key if kHASHCRYPT_UserKey is selected */
- if (handle->keyType == kHASHCRYPT_UserKey)
- {
- hashcrypt_aes_load_userKey(base, handle);
- }
-
- /* load nonce */
- hashcrypt_load_data(base, (uint32_t *)counter, 16);
-
- lastSize = size % HASHCRYPT_AES_BLOCK_SIZE;
- size -= lastSize;
-
- /* encrypt full 16byte blocks */
- hashcrypt_aes_one_block(base, input, output, size);
-
- while (size)
- {
- ctrIncrement(counter);
- size -= 16u;
- input += 16;
- output += 16;
- }
-
- if (lastSize)
- {
- if (counterlast)
- {
- lastEncryptedCounter = counterlast;
- }
- else
- {
- lastEncryptedCounter = lastBlock;
- }
-
- /* Perform encryption with all zeros to get last counter. XOR with zeros doesn't change. */
- status = hashcrypt_aes_one_block(base, lastBlock, lastEncryptedCounter, HASHCRYPT_AES_BLOCK_SIZE);
- if (status != kStatus_Success)
- {
- return status;
- }
- /* remain output = input XOR counterlast */
- for (uint32_t i = 0; i < lastSize; i++)
- {
- output[i] = input[i] ^ lastEncryptedCounter[i];
- }
- /* Increment counter parameter */
- ctrIncrement(counter);
- }
- else
- {
- lastSize = HASHCRYPT_AES_BLOCK_SIZE;
- /* no remaining bytes in couterlast so clearing it */
- if (counterlast)
- {
- memset(counterlast, 0, HASHCRYPT_AES_BLOCK_SIZE);
- }
- }
-
- if (szLeft)
- {
- *szLeft = HASHCRYPT_AES_BLOCK_SIZE - lastSize;
- }
-
- return kStatus_Success;
-}
-
-void HASHCRYPT_DriverIRQHandler(void)
-{
- hashcrypt_sha_ctx_internal_t *ctxInternal;
- HASHCRYPT_Type *base = HASHCRYPT;
- uint32_t numBlocks;
- status_t status;
-
- ctxInternal = (hashcrypt_sha_ctx_internal_t *)s_ctx;
-
- if (0 == (base->STATUS & HASHCRYPT_STATUS_ERROR_MASK))
- {
- if (ctxInternal->remainingBlcks > 0)
- {
- if (ctxInternal->remainingBlcks >= SHA_MASTER_MAX_BLOCKS)
- {
- numBlocks = SHA_MASTER_MAX_BLOCKS - 1;
- }
- else
- {
- numBlocks = ctxInternal->remainingBlcks;
- }
- /* some blocks still remaining, update remainingBlcks for next ISR and start another hash */
- ctxInternal->remainingBlcks -= numBlocks;
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(1) | HASHCRYPT_MEMCTRL_COUNT(numBlocks);
- return;
- }
- /* no full blocks left, disable interrupts and AHB master mode */
- base->INTENCLR = HASHCRYPT_INTENCLR_DIGEST_MASK | HASHCRYPT_INTENCLR_ERROR_MASK;
- base->MEMCTRL = HASHCRYPT_MEMCTRL_MASTER(0);
- hashcrypt_save_running_hash(base, ctxInternal);
- status = kStatus_Success;
- }
- else
- {
- status = kStatus_Fail;
- }
-
- /* Invoke callback if there is one */
- if (NULL != ctxInternal->hashCallback)
- {
- ctxInternal->hashCallback(HASHCRYPT, s_ctx, status, ctxInternal->userData);
- }
-}
-
-void HASHCRYPT_Init(HASHCRYPT_Type *base)
-{
- RESET_PeripheralReset(kHASHCRYPT_RST_SHIFT_RSTn);
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- CLOCK_EnableClock(kCLOCK_HashCrypt);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-}
-
-void HASHCRYPT_Deinit(HASHCRYPT_Type *base)
-{
- RESET_SetPeripheralReset(kHASHCRYPT_RST_SHIFT_RSTn);
-#if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
- CLOCK_DisableClock(kCLOCK_HashCrypt);
-#endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
-}
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.h
deleted file mode 100755
index 2e5ca47f8..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_hashcrypt.h
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * Copyright 2017-2019 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-#ifndef _FSL_HASHCRYPT_H_
-#define _FSL_HASHCRYPT_H_
-
-#include "fsl_common.h"
-
-/*! @brief HASHCRYPT status return codes. */
-enum _hashcrypt_status
-{
- kStatus_HASHCRYPT_Again =
- MAKE_STATUS(kStatusGroup_HASHCRYPT, 0), /*!< Non-blocking function shall be called again. */
-};
-
-/*******************************************************************************
- * Definitions
- *******************************************************************************/
-
-/*!
- * @addtogroup hashcrypt_driver
- * @{
- */
-/*! @name Driver version */
-/*@{*/
-/*! @brief HASHCRYPT driver version. Version 2.1.0.
- *
- * Current version: 2.1.0
- *
- * Change log:
- * - Version 2.0.0
- * - Initial version
- * - Version 2.0.1
- * - Support loading AES key from unaligned address
- * - Version 2.0.2
- * - Support loading AES key from unaligned address for different compiler and core variants
- * - Version 2.0.3
- * - Remove SHA512 and AES ICB algorithm definitions
- * - Version 2.0.4
- * - Add SHA context switch support
- * - Version 2.1.0
- * - Update the register name and macro to align with new header.
- */
-#define FSL_HASHCRYPT_DRIVER_VERSION (MAKE_VERSION(2, 1, 0))
-/*@}*/
-
-/*! @brief Algorithm definitions correspond with the values for Mode field in Control register !*/
-#define HASHCRYPT_MODE_SHA1 0x1
-#define HASHCRYPT_MODE_SHA256 0x2
-#define HASHCRYPT_MODE_AES 0x4
-
-/*! @brief Algorithm used for Hashcrypt operation */
-typedef enum _hashcrypt_algo_t
-{
- kHASHCRYPT_Sha1 = HASHCRYPT_MODE_SHA1, /*!< SHA_1 */
- kHASHCRYPT_Sha256 = HASHCRYPT_MODE_SHA256, /*!< SHA_256 */
- kHASHCRYPT_Aes = HASHCRYPT_MODE_AES, /*!< AES */
-} hashcrypt_algo_t;
-
-/*! @} */
-
-/*******************************************************************************
- * AES Definitions
- *******************************************************************************/
-
-/*!
- * @addtogroup hashcrypt_driver_aes
- * @{
- */
-
-/*! AES block size in bytes */
-#define HASHCRYPT_AES_BLOCK_SIZE 16
-#define AES_ENCRYPT 0
-#define AES_DECRYPT 1
-
-/*! @brief AES mode */
-typedef enum _hashcrypt_aes_mode_t
-{
- kHASHCRYPT_AesEcb = 0U, /*!< AES ECB mode */
- kHASHCRYPT_AesCbc = 1U, /*!< AES CBC mode */
- kHASHCRYPT_AesCtr = 2U, /*!< AES CTR mode */
-} hashcrypt_aes_mode_t;
-
-/*! @brief Size of AES key */
-typedef enum _hashcrypt_aes_keysize_t
-{
- kHASHCRYPT_Aes128 = 0U, /*!< AES 128 bit key */
- kHASHCRYPT_Aes192 = 1U, /*!< AES 192 bit key */
- kHASHCRYPT_Aes256 = 2U, /*!< AES 256 bit key */
- kHASHCRYPT_InvalidKey = 3U, /*!< AES invalid key */
-} hashcrypt_aes_keysize_t;
-
-/*! @brief HASHCRYPT key source selection.
- *
- */
-typedef enum _hashcrypt_key
-{
- kHASHCRYPT_UserKey = 0xc3c3U, /*!< HASHCRYPT user key */
- kHASHCRYPT_SecretKey = 0x3c3cU, /*!< HASHCRYPT secret key (dedicated hw bus from PUF) */
-} hashcrypt_key_t;
-
-/*! @brief Specify HASHCRYPT's key resource. */
-struct _hashcrypt_handle
-{
- uint32_t keyWord[8]; /*!< Copy of user key (set by HASHCRYPT_AES_SetKey(). */
- hashcrypt_aes_keysize_t keySize;
- hashcrypt_key_t keyType; /*!< For operations with key (such as AES encryption/decryption), specify key type. */
-} __attribute__((aligned));
-
-typedef struct _hashcrypt_handle hashcrypt_handle_t;
-
-/*!
- *@}
- */ /* end of hashcrypt_driver_aes */
-
-/*******************************************************************************
- * HASH Definitions
- ******************************************************************************/
-/*!
- * @addtogroup hashcrypt_driver_hash
- * @{
- */
-
-/*! @brief HASHCRYPT HASH Context size. */
-#if defined(FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE) && (FSL_FEATURE_HASHCRYPT_HAS_RELOAD_FEATURE > 0)
-#define HASHCRYPT_HASH_CTX_SIZE 30
-#else
-#define HASHCRYPT_HASH_CTX_SIZE 22
-#endif
-
-/*! @brief Storage type used to save hash context. */
-typedef struct _hashcrypt_hash_ctx_t
-{
- uint32_t x[HASHCRYPT_HASH_CTX_SIZE]; /*!< storage */
-} hashcrypt_hash_ctx_t;
-
-/*! @brief HASHCRYPT background hash callback function. */
-typedef void (*hashcrypt_callback_t)(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, status_t status, void *userData);
-
-/*!
- *@}
- */ /* end of hashcrypt_driver_hash */
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*!
- * @addtogroup hashcrypt_driver
- * @{
- */
-
-/*!
- * @brief Enables clock and disables reset for HASHCRYPT peripheral.
- *
- * Enable clock and disable reset for HASHCRYPT.
- *
- * @param base HASHCRYPT base address
- */
-void HASHCRYPT_Init(HASHCRYPT_Type *base);
-
-/*!
- * @brief Disables clock for HASHCRYPT peripheral.
- *
- * Disable clock and enable reset.
- *
- * @param base HASHCRYPT base address
- */
-void HASHCRYPT_Deinit(HASHCRYPT_Type *base);
-
-/*!
- *@}
- */ /* end of hashcrypt_driver */
-
-/*******************************************************************************
- * AES API
- ******************************************************************************/
-
-/*!
- * @addtogroup hashcrypt_driver_aes
- * @{
- */
-
-/*!
- * @brief Set AES key to hashcrypt_handle_t struct and optionally to HASHCRYPT.
- *
- * Sets the AES key for encryption/decryption with the hashcrypt_handle_t structure.
- * The hashcrypt_handle_t input argument specifies key source.
- *
- * @param base HASHCRYPT peripheral base address.
- * @param handle Handle used for the request.
- * @param key 0-mod-4 aligned pointer to AES key.
- * @param keySize AES key size in bytes. Shall equal 16, 24 or 32.
- * @return status from set key operation
- */
-status_t HASHCRYPT_AES_SetKey(HASHCRYPT_Type *base, hashcrypt_handle_t *handle, const uint8_t *key, size_t keySize);
-
-/*!
- * @brief Encrypts AES on one or multiple 128-bit block(s).
- *
- * Encrypts AES.
- * The source plaintext and destination ciphertext can overlap in system memory.
- *
- * @param base HASHCRYPT peripheral base address
- * @param handle Handle used for this request.
- * @param plaintext Input plain text to encrypt
- * @param[out] ciphertext Output cipher text
- * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
- * @return Status from encrypt operation
- */
-status_t HASHCRYPT_AES_EncryptEcb(
- HASHCRYPT_Type *base, hashcrypt_handle_t *handle, const uint8_t *plaintext, uint8_t *ciphertext, size_t size);
-
-/*!
- * @brief Decrypts AES on one or multiple 128-bit block(s).
- *
- * Decrypts AES.
- * The source ciphertext and destination plaintext can overlap in system memory.
- *
- * @param base HASHCRYPT peripheral base address
- * @param handle Handle used for this request.
- * @param ciphertext Input plain text to encrypt
- * @param[out] plaintext Output cipher text
- * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
- * @return Status from decrypt operation
- */
-status_t HASHCRYPT_AES_DecryptEcb(
- HASHCRYPT_Type *base, hashcrypt_handle_t *handle, const uint8_t *ciphertext, uint8_t *plaintext, size_t size);
-
-/*!
- * @brief Encrypts AES using CBC block mode.
- *
- * @param base HASHCRYPT peripheral base address
- * @param handle Handle used for this request.
- * @param plaintext Input plain text to encrypt
- * @param[out] ciphertext Output cipher text
- * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
- * @param iv Input initial vector to combine with the first input block.
- * @return Status from encrypt operation
- */
-status_t HASHCRYPT_AES_EncryptCbc(HASHCRYPT_Type *base,
- hashcrypt_handle_t *handle,
- const uint8_t *plaintext,
- uint8_t *ciphertext,
- size_t size,
- const uint8_t iv[16]);
-
-/*!
- * @brief Decrypts AES using CBC block mode.
- *
- * @param base HASHCRYPT peripheral base address
- * @param handle Handle used for this request.
- * @param ciphertext Input cipher text to decrypt
- * @param[out] plaintext Output plain text
- * @param size Size of input and output data in bytes. Must be multiple of 16 bytes.
- * @param iv Input initial vector to combine with the first input block.
- * @return Status from decrypt operation
- */
-status_t HASHCRYPT_AES_DecryptCbc(HASHCRYPT_Type *base,
- hashcrypt_handle_t *handle,
- const uint8_t *ciphertext,
- uint8_t *plaintext,
- size_t size,
- const uint8_t iv[16]);
-
-/*!
- * @brief Encrypts or decrypts AES using CTR block mode.
- *
- * Encrypts or decrypts AES using CTR block mode.
- * AES CTR mode uses only forward AES cipher and same algorithm for encryption and decryption.
- * The only difference between encryption and decryption is that, for encryption, the input argument
- * is plain text and the output argument is cipher text. For decryption, the input argument is cipher text
- * and the output argument is plain text.
- *
- * @param base HASHCRYPT peripheral base address
- * @param handle Handle used for this request.
- * @param input Input data for CTR block mode
- * @param[out] output Output data for CTR block mode
- * @param size Size of input and output data in bytes
- * @param[in,out] counter Input counter (updates on return)
- * @param[out] counterlast Output cipher of last counter, for chained CTR calls (statefull encryption). NULL can be
- * passed if chained calls are
- * not used.
- * @param[out] szLeft Output number of bytes in left unused in counterlast block. NULL can be passed if chained calls
- * are not used.
- * @return Status from encrypt operation
- */
-status_t HASHCRYPT_AES_CryptCtr(HASHCRYPT_Type *base,
- hashcrypt_handle_t *handle,
- const uint8_t *input,
- uint8_t *output,
- size_t size,
- uint8_t counter[HASHCRYPT_AES_BLOCK_SIZE],
- uint8_t counterlast[HASHCRYPT_AES_BLOCK_SIZE],
- size_t *szLeft);
-
-/*!
- *@}
- */ /* end of hashcrypt_driver_aes */
-
-/*******************************************************************************
- * HASH API
- ******************************************************************************/
-
-/*!
- * @addtogroup hashcrypt_driver_hash
- * @{
- */
-
-/*!
- * @brief Create HASH on given data
- *
- * Perform the full SHA in one function call. The function is blocking.
- *
- * @param base HASHCRYPT peripheral base address
- * @param algo Underlaying algorithm to use for hash computation.
- * @param input Input data
- * @param inputSize Size of input data in bytes
- * @param[out] output Output hash data
- * @param[out] outputSize Output parameter storing the size of the output hash in bytes
- * @return Status of the one call hash operation.
- */
-status_t HASHCRYPT_SHA(HASHCRYPT_Type *base,
- hashcrypt_algo_t algo,
- const uint8_t *input,
- size_t inputSize,
- uint8_t *output,
- size_t *outputSize);
-
-/*!
- * @brief Initialize HASH context
- *
- * This function initializes the HASH.
- *
- * @param base HASHCRYPT peripheral base address
- * @param[out] ctx Output hash context
- * @param algo Underlaying algorithm to use for hash computation.
- * @return Status of initialization
- */
-status_t HASHCRYPT_SHA_Init(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, hashcrypt_algo_t algo);
-
-/*!
- * @brief Add data to current HASH
- *
- * Add data to current HASH. This can be called repeatedly with an arbitrary amount of data to be
- * hashed. The functions blocks. If it returns kStatus_Success, the running hash
- * has been updated (HASHCRYPT has processed the input data), so the memory at \p input pointer
- * can be released back to system. The HASHCRYPT context buffer is updated with the running hash
- * and with all necessary information to support possible context switch.
- *
- * @param base HASHCRYPT peripheral base address
- * @param[in,out] ctx HASH context
- * @param input Input data
- * @param inputSize Size of input data in bytes
- * @return Status of the hash update operation
- */
-status_t HASHCRYPT_SHA_Update(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, const uint8_t *input, size_t inputSize);
-
-/*!
- * @brief Finalize hashing
- *
- * Outputs the final hash (computed by HASHCRYPT_HASH_Update()) and erases the context.
- *
- * @param base HASHCRYPT peripheral base address
- * @param[in,out] ctx Input hash context
- * @param[out] output Output hash data
- * @param[in,out] outputSize Optional parameter (can be passed as NULL). On function entry, it specifies the size of
- * output[] buffer. On function return, it stores the number of updated output bytes.
- * @return Status of the hash finish operation
- */
-status_t HASHCRYPT_SHA_Finish(HASHCRYPT_Type *base, hashcrypt_hash_ctx_t *ctx, uint8_t *output, size_t *outputSize);
-
-/*!
- *@}
- */ /* end of hashcrypt_driver_hash */
-
-/*!
- * @addtogroup hashcrypt_background_driver_hash
- * @{
- */
-
-/*!
- * @brief Initializes the HASHCRYPT handle for background hashing.
- *
- * This function initializes the hash context for background hashing
- * (Non-blocking) APIs. This is less typical interface to hash function, but can be used
- * for parallel processing, when main CPU has something else to do.
- * Example is digital signature RSASSA-PKCS1-V1_5-VERIFY((n,e),M,S) algorithm, where
- * background hashing of M can be started, then CPU can compute S^e mod n
- * (in parallel with background hashing) and once the digest becomes available,
- * CPU can proceed to comparison of EM with EM'.
- *
- * @param base HASHCRYPT peripheral base address.
- * @param[out] ctx Hash context.
- * @param callback Callback function.
- * @param userData User data (to be passed as an argument to callback function, once callback is invoked from isr).
- */
-void HASHCRYPT_SHA_SetCallback(HASHCRYPT_Type *base,
- hashcrypt_hash_ctx_t *ctx,
- hashcrypt_callback_t callback,
- void *userData);
-
-/*!
- * @brief Create running hash on given data.
- *
- * Configures the HASHCRYPT to compute new running hash as AHB master
- * and returns immediately. HASHCRYPT AHB Master mode supports only aligned \p input
- * address and can be called only once per continuous block of data. Every call to this function
- * must be preceded with HASHCRYPT_SHA_Init() and finished with HASHCRYPT_SHA_Finish().
- * Once callback function is invoked by HASHCRYPT isr, it should set a flag
- * for the main application to finalize the hashing (padding) and to read out the final digest
- * by calling HASHCRYPT_SHA_Finish().
- *
- * @param base HASHCRYPT peripheral base address
- * @param ctx Specifies callback. Last incomplete 512-bit block of the input is copied into clear buffer for padding.
- * @param input 32-bit word aligned pointer to Input data.
- * @param inputSize Size of input data in bytes (must be word aligned)
- * @return Status of the hash update operation.
- */
-status_t HASHCRYPT_SHA_UpdateNonBlocking(HASHCRYPT_Type *base,
- hashcrypt_hash_ctx_t *ctx,
- const uint8_t *input,
- size_t inputSize);
-/*!
- *@}
- */ /* end of hashcrypt_background_driver_hash */
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* _FSL_HASHCRYPT_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.c b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.c
deleted file mode 100755
index 650bb6045..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.c
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Copyright 2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include "fsl_iap.h"
-#include "fsl_iap_ffr.h"
-#include "fsl_device_registers.h"
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.iap1"
-#endif
-
-/*!
- * @addtogroup flash_driver_api
- * @{
- */
-
-#define ROM_API_TREE ((uint32_t *)0x130010f0)
-#define BOOTLOADER_API_TREE_POINTER ((bootloader_tree_t *)ROM_API_TREE)
-
-static uint32_t S_VersionMajor = 0;
-
-typedef status_t (*EraseCommend_t)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
-typedef status_t (*ProgramCommend_t)(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
-typedef status_t (*VerifyProgramCommend_t)(flash_config_t *config,
- uint32_t start,
- uint32_t lengthInBytes,
- const uint8_t *expectedData,
- uint32_t *failedAddress,
- uint32_t *failedData);
-/*
- *!@brief Structure of version property.
- *
- *!@ingroup bl_core
- */
-typedef union StandardVersion
-{
- struct
- {
- uint32_t bugfix : 8; /*!< bugfix version [7:0] */
- uint32_t minor : 8; /*!< minor version [15:8] */
- uint32_t major : 8; /*!< major version [23:16] */
- uint32_t name : 8; /*!< 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;
-
-/*! @brief Interface for the flash driver.*/
-typedef struct FlashDriverInterface
-{
- standard_version_t version; /*!< flash driver API version number.*/
-
- /*!< Flash driver.*/
- status_t (*flash_init)(flash_config_t *config);
- 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, uint8_t *src, uint32_t lengthInBytes);
- status_t (*flash_verify_erase)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes);
- status_t (*flash_verify_program)(flash_config_t *config,
- uint32_t start,
- uint32_t lengthInBytes,
- const uint8_t *expectedData,
- 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_erase_with_checker)(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
- status_t (*flash_program_with_checker)(flash_config_t *config,
- uint32_t start,
- uint8_t *src,
- uint32_t lengthInBytes);
- status_t (*flash_verify_program_with_checker)(flash_config_t *config,
- uint32_t start,
- uint32_t lengthInBytes,
- const uint8_t *expectedData,
- uint32_t *failedAddress,
- uint32_t *failedData);
- /*!< Flash FFR driver*/
- status_t (*ffr_init)(flash_config_t *config);
- status_t (*ffr_deinit)(flash_config_t *config);
- status_t (*ffr_cust_factory_page_write)(flash_config_t *config, uint8_t *page_data, bool seal_part);
- status_t (*ffr_get_uuid)(flash_config_t *config, uint8_t *uuid);
- status_t (*ffr_get_customer_data)(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
- status_t (*ffr_keystore_write)(flash_config_t *config, ffr_key_store_t *pKeyStore);
- status_t (*ffr_keystore_get_ac)(flash_config_t *config, uint8_t *pActivationCode);
- status_t (*ffr_keystore_get_kc)(flash_config_t *config, uint8_t *pKeyCode, ffr_key_type_t keyIndex);
- status_t (*ffr_infield_page_write)(flash_config_t *config, uint8_t *page_data, uint32_t valid_len);
- status_t (*ffr_get_customer_infield_data)(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
-} flash_driver_interface_t;
-
-/*!
- * @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.
- */
-typedef struct BootloaderTree
-{
- void (*runBootloader)(void *arg); /*!< Function to start the bootloader executing. */
- standard_version_t bootloader_version; /*!< Bootloader version number. */
- const char *copyright; /*!< Copyright string. */
- const uint32_t *reserved; /*!< Do NOT use. */
- const flash_driver_interface_t *flashDriver; /*!< Flash driver API. */
-} bootloader_tree_t;
-
-/*******************************************************************************
- * Variables
- ******************************************************************************/
-
-/*! @brief Global pointer to the flash driver API table in ROM. */
-flash_driver_interface_t *FLASH_API_TREE;
-/*! Get pointer to flash driver API table in ROM. */
-#define FLASH_API_TREE BOOTLOADER_API_TREE_POINTER->flashDriver
-/*******************************************************************************
- * Code
- ******************************************************************************/
-
-/*! See fsl_iap.h for documentation of this function. */
-status_t FLASH_Init(flash_config_t *config)
-{
- assert(FLASH_API_TREE);
- config->modeConfig.sysFreqInMHz = kSysToFlashFreq_defaultInMHz;
- S_VersionMajor = BOOTLOADER_API_TREE_POINTER->bootloader_version.major;
- return FLASH_API_TREE->flash_init(config);
-}
-
-/*! See fsl_iap.h for documentation of this function. */
-status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key)
-{
- if (S_VersionMajor == 2)
- {
- EraseCommend_t EraseCommand =
- (EraseCommend_t)(0x1300413b); /*!< get the flash erase api location adress int rom */
- return EraseCommand(config, start, lengthInBytes, key);
- }
- else
- {
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->flash_erase(config, start, lengthInBytes, key);
- }
-}
-
-/*! See fsl_iap.h for documentation of this function. */
-status_t FLASH_Program(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes)
-{
- if (S_VersionMajor == 2)
- {
- ProgramCommend_t ProgramCommend =
- (ProgramCommend_t)(0x1300419d); /*!< get the flash program api location adress in rom*/
- return ProgramCommend(config, start, src, lengthInBytes);
- }
- else
- {
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->flash_program(config, start, src, lengthInBytes);
- }
-}
-
-/*! See fsl_iap.h for documentation of this function. */
-status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->flash_verify_erase(config, start, lengthInBytes);
-}
-
-/*! See fsl_iap.h for documentation of this function. */
-status_t FLASH_VerifyProgram(flash_config_t *config,
- uint32_t start,
- uint32_t lengthInBytes,
- const uint8_t *expectedData,
- uint32_t *failedAddress,
- uint32_t *failedData)
-{
- if (S_VersionMajor == 2)
- {
- VerifyProgramCommend_t VerifyProgramCommend =
- (VerifyProgramCommend_t)(0x1300427d); /*!< get the flash verify program api location adress in
- rom*/
- return VerifyProgramCommend(config, start, lengthInBytes, expectedData, failedAddress, failedData);
- }
- else
- {
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->flash_verify_program(config, start, lengthInBytes, expectedData, failedAddress,
- failedData);
- }
-}
-
-/*! See fsl_iap.h for documentation of this function.*/
-status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->flash_get_property(config, whichProperty, value);
-}
-/********************************************************************************
- * fsl iap ffr CODE
- *******************************************************************************/
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_Init(flash_config_t *config)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_init(config);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_Deinit(flash_config_t *config)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_deinit(config);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_CustFactoryPageWrite(flash_config_t *config, uint8_t *page_data, bool seal_part)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_cust_factory_page_write(config, page_data, seal_part);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_GetUUID(flash_config_t *config, uint8_t *uuid)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_get_uuid(config, uuid);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_GetCustomerData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_get_customer_data(config, pData, offset, len);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_KeystoreWrite(flash_config_t *config, ffr_key_store_t *pKeyStore)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_keystore_write(config, pKeyStore);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_KeystoreGetAC(flash_config_t *config, uint8_t *pActivationCode)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_keystore_get_ac(config, pActivationCode);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_KeystoreGetKC(flash_config_t *config, uint8_t *pKeyCode, ffr_key_type_t keyIndex)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_keystore_get_kc(config, pKeyCode, keyIndex);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_InfieldPageWrite(flash_config_t *config, uint8_t *page_data, uint32_t valid_len)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_infield_page_write(config, page_data, valid_len);
-}
-
-/*! See fsl_iap_ffr.h for documentation of this function. */
-status_t FFR_GetCustomerInfieldData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len)
-{
- assert(FLASH_API_TREE);
- return FLASH_API_TREE->ffr_get_customer_infield_data(config, pData, offset, len);
-}
-
-/*! @}*/
-
-/********************************************************************************
- * EOF
- *******************************************************************************/
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.h
deleted file mode 100755
index c57f66707..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap.h
+++ /dev/null
@@ -1,498 +0,0 @@
-/*
- * Copyright 2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __FSL_IAP_H_
-#define __FSL_IAP_H_
-
-#include "fsl_common.h"
-/*!
- * @addtogroup flash_driver
- * @{
- */
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-/*!
- * @name Flash version
- * @{
- */
-/*! @brief Constructs the version number for drivers. */
-#if !defined(MAKE_VERSION)
-#define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
-#endif
-
-/*! @brief Flash driver version for SDK*/
-#define FSL_FLASH_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
-
-/*! @brief Flash driver version for ROM*/
-enum _flash_driver_version_constants
-{
- kFLASH_DriverVersionName = 'F', /*!< Flash driver version name.*/
- kFLASH_DriverVersionMajor = 2, /*!< Major flash driver version.*/
- kFLASH_DriverVersionMinor = 0, /*!< Minor flash driver version.*/
- kFLASH_DriverVersionBugfix = 0 /*!< Bugfix for flash driver version.*/
-};
-
-/*@}*/
-
-/*!
- * @name Flash configuration
- * @{
- */
-/*! @brief Flash IP Type. */
-#if !defined(FSL_FEATURE_FLASH_IP_IS_C040HD_ATFC)
-#define FSL_FEATURE_FLASH_IP_IS_C040HD_ATFC (1)
-#endif
-#if !defined(FSL_FEATURE_FLASH_IP_IS_C040HD_FC)
-#define FSL_FEATURE_FLASH_IP_IS_C040HD_FC (0)
-#endif
-
-/*!
- * @name Flash status
- * @{
- */
-/*! @brief Flash driver status group. */
-#if defined(kStatusGroup_FlashDriver)
-#define kStatusGroupGeneric kStatusGroup_Generic
-#define kStatusGroupFlashDriver kStatusGroup_FlashDriver
-#elif defined(kStatusGroup_FLASHIAP)
-#define kStatusGroupGeneric kStatusGroup_Generic
-#define kStatusGroupFlashDriver kStatusGroup_FLASH
-#else
-#define kStatusGroupGeneric 0
-#define kStatusGroupFlashDriver 1
-#endif
-
-/*! @brief Constructs a status code value from a group and a code number. */
-#if !defined(MAKE_STATUS)
-#define MAKE_STATUS(group, code) ((((group)*100) + (code)))
-#endif
-
-/*!
- * @brief Flash driver status codes.
- */
-enum _flash_status
-{
- kStatus_FLASH_Success = MAKE_STATUS(kStatusGroupGeneric, 0), /*!< API is executed successfully*/
- kStatus_FLASH_InvalidArgument = MAKE_STATUS(kStatusGroupGeneric, 4), /*!< Invalid argument*/
- kStatus_FLASH_SizeError = MAKE_STATUS(kStatusGroupFlashDriver, 0), /*!< Error size*/
- kStatus_FLASH_AlignmentError =
- MAKE_STATUS(kStatusGroupFlashDriver, 1), /*!< Parameter is not aligned with the specified baseline*/
- kStatus_FLASH_AddressError = MAKE_STATUS(kStatusGroupFlashDriver, 2), /*!< Address is out of range */
- kStatus_FLASH_AccessError =
- MAKE_STATUS(kStatusGroupFlashDriver, 3), /*!< Invalid instruction codes and out-of bound addresses */
- kStatus_FLASH_ProtectionViolation = MAKE_STATUS(
- kStatusGroupFlashDriver, 4), /*!< The program/erase operation is requested to execute on protected areas */
- kStatus_FLASH_CommandFailure =
- MAKE_STATUS(kStatusGroupFlashDriver, 5), /*!< Run-time error during command execution. */
- kStatus_FLASH_UnknownProperty = MAKE_STATUS(kStatusGroupFlashDriver, 6), /*!< Unknown property.*/
- kStatus_FLASH_EraseKeyError = MAKE_STATUS(kStatusGroupFlashDriver, 7), /*!< API erase key is invalid.*/
- kStatus_FLASH_RegionExecuteOnly =
- MAKE_STATUS(kStatusGroupFlashDriver, 8), /*!< The current region is execute-only.*/
- kStatus_FLASH_ExecuteInRamFunctionNotReady =
- MAKE_STATUS(kStatusGroupFlashDriver, 9), /*!< Execute-in-RAM function is not available.*/
-
- kStatus_FLASH_CommandNotSupported = MAKE_STATUS(kStatusGroupFlashDriver, 11), /*!< Flash API is not supported.*/
- kStatus_FLASH_ReadOnlyProperty = MAKE_STATUS(kStatusGroupFlashDriver, 12), /*!< The flash property is read-only.*/
- kStatus_FLASH_InvalidPropertyValue =
- MAKE_STATUS(kStatusGroupFlashDriver, 13), /*!< The flash property value is out of range.*/
- kStatus_FLASH_InvalidSpeculationOption =
- MAKE_STATUS(kStatusGroupFlashDriver, 14), /*!< The option of flash prefetch speculation is invalid.*/
- kStatus_FLASH_EccError = MAKE_STATUS(kStatusGroupFlashDriver,
- 0x10), /*!< A correctable or uncorrectable error during command execution. */
- kStatus_FLASH_CompareError =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x11), /*!< Destination and source memory contents do not match. */
- kStatus_FLASH_RegulationLoss = MAKE_STATUS(kStatusGroupFlashDriver, 0x12), /*!< A loss of regulation during read. */
- kStatus_FLASH_InvalidWaitStateCycles =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x13), /*!< The wait state cycle set to r/w mode is invalid. */
-
- kStatus_FLASH_OutOfDateCfpaPage =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x20), /*!< CFPA page version is out of date. */
- kStatus_FLASH_BlankIfrPageData = MAKE_STATUS(kStatusGroupFlashDriver, 0x21), /*!< Blank page cannnot be read. */
- kStatus_FLASH_EncryptedRegionsEraseNotDoneAtOnce =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x22), /*!< Encrypted flash subregions are not erased at once. */
- kStatus_FLASH_ProgramVerificationNotAllowed = MAKE_STATUS(
- kStatusGroupFlashDriver, 0x23), /*!< Program verification is not allowed when the encryption is enabled. */
- kStatus_FLASH_HashCheckError =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x24), /*!< Hash check of page data is failed. */
- kStatus_FLASH_SealedFfrRegion = MAKE_STATUS(kStatusGroupFlashDriver, 0x25), /*!< The FFR region is sealed. */
- kStatus_FLASH_FfrRegionWriteBroken = MAKE_STATUS(
- kStatusGroupFlashDriver, 0x26), /*!< The FFR Spec region is not allowed to be written discontinuously. */
- kStatus_FLASH_NmpaAccessNotAllowed =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x27), /*!< The NMPA region is not allowed to be read/written/erased. */
- kStatus_FLASH_CmpaCfgDirectEraseNotAllowed =
- MAKE_STATUS(kStatusGroupFlashDriver, 0x28), /*!< The CMPA Cfg region is not allowed to be erased directly. */
- kStatus_FLASH_FfrBankIsLocked = MAKE_STATUS(kStatusGroupFlashDriver, 0x29), /*!< The FFR bank region is locked. */
-};
-/*@}*/
-
-/*!
- * @name Flash API key
- * @{
- */
-/*! @brief Constructs the four character code for the Flash driver API key. */
-#if !defined(FOUR_CHAR_CODE)
-#define FOUR_CHAR_CODE(a, b, c, d) (((d) << 24) | ((c) << 16) | ((b) << 8) | ((a)))
-#endif
-
-/*!
- * @brief Enumeration for Flash driver API keys.
- *
- * @note 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.
- */
-enum _flash_driver_api_keys
-{
- kFLASH_ApiEraseKey = FOUR_CHAR_CODE('l', 'f', 'e', 'k') /*!< Key value used to validate all flash erase APIs.*/
-};
-/*@}*/
-
-/*!
- * @brief Enumeration for various flash properties.
- */
-typedef enum _flash_property_tag
-{
- kFLASH_PropertyPflashSectorSize = 0x00U, /*!< Pflash sector size property.*/
- kFLASH_PropertyPflashTotalSize = 0x01U, /*!< Pflash total size property.*/
- kFLASH_PropertyPflashBlockSize = 0x02U, /*!< Pflash block size property.*/
- kFLASH_PropertyPflashBlockCount = 0x03U, /*!< Pflash block count property.*/
- kFLASH_PropertyPflashBlockBaseAddr = 0x04U, /*!< Pflash block base address property.*/
-
- kFLASH_PropertyPflashPageSize = 0x30U, /*!< Pflash page size property.*/
- kFLASH_PropertyPflashSystemFreq = 0x31U, /*!< System Frequency System Frequency.*/
-
- kFLASH_PropertyFfrSectorSize = 0x40U, /*!< FFR sector size property.*/
- kFLASH_PropertyFfrTotalSize = 0x41U, /*!< FFR total size property.*/
- kFLASH_PropertyFfrBlockBaseAddr = 0x42U, /*!< FFR block base address property.*/
- kFLASH_PropertyFfrPageSize = 0x43U, /*!< FFR page size property.*/
-} flash_property_tag_t;
-
-/*!
- * @brief Enumeration for flash max pages to erase.
- */
-enum _flash_max_erase_page_value
-{
- kFLASH_MaxPagesToErase = 100U /*!< The max value in pages to erase. */
-};
-
-/*!
- * @brief Enumeration for flash alignment property.
- */
-enum _flash_alignment_property
-{
- kFLASH_AlignementUnitVerifyErase = 4, /*!< The alignment unit in bytes used for verify erase operation.*/
- kFLASH_AlignementUnitProgram = 512, /*!< The alignment unit in bytes used for program operation.*/
- /*kFLASH_AlignementUnitVerifyProgram = 4,*/ /*!< The alignment unit in bytes used for verify program operation.*/
- kFLASH_AlignementUnitSingleWordRead = 16 /*!< The alignment unit in bytes used for SingleWordRead command.*/
-};
-
-/*!
- * @brief Enumeration for flash read ecc option
- */
-enum _flash_read_ecc_option
-{
- kFLASH_ReadWithEccOn = 0, /*! ECC is on */
- kFLASH_ReadWithEccOff = 1, /*! ECC is off */
-};
-
-/* set flash Controller timing before flash init */
-enum _flash_freq_tag
-{
- kSysToFlashFreq_lowInMHz = 12u,
- kSysToFlashFreq_defaultInMHz = 96u,
-};
-
-/*!
- * @brief Enumeration for flash read margin option
- */
-enum _flash_read_margin_option
-{
- kFLASH_ReadMarginNormal = 0, /*!< Normal read */
- kFLASH_ReadMarginVsProgram = 1, /*!< Margin vs. program */
- kFLASH_ReadMarginVsErase = 2, /*!< Margin vs. erase */
- kFLASH_ReadMarginIllegalBitCombination = 3 /*!< Illegal bit combination */
-};
-
-/*!
- * @brief Enumeration for flash read dmacc option
- */
-enum _flash_read_dmacc_option
-{
- kFLASH_ReadDmaccDisabled = 0, /*!< Memory word */
- kFLASH_ReadDmaccEnabled = 1, /*!< DMACC word */
-};
-
-/*!
- * @brief Enumeration for flash ramp control option
- */
-enum _flash_ramp_control_option
-{
- kFLASH_RampControlDivisionFactorReserved = 0, /*!< Reserved */
- kFLASH_RampControlDivisionFactor256 = 1, /*!< clk48mhz / 256 = 187.5KHz */
- kFLASH_RampControlDivisionFactor128 = 2, /*!< clk48mhz / 128 = 375KHz */
- kFLASH_RampControlDivisionFactor64 = 3 /*!< clk48mhz / 64 = 750KHz */
-};
-
-/*! @brief Flash ECC log info. */
-typedef struct _flash_ecc_log
-{
- uint32_t firstEccEventAddress;
- uint32_t eccErrorCount;
- uint32_t eccCorrectionCount;
- uint32_t reserved;
-} flash_ecc_log_t;
-
-/*! @brief Flash controller paramter config. */
-typedef struct _flash_mode_config
-{
- uint32_t sysFreqInMHz;
- /* ReadSingleWord parameter. */
- struct
- {
- uint8_t readWithEccOff : 1;
- uint8_t readMarginLevel : 2;
- uint8_t readDmaccWord : 1;
- uint8_t reserved0 : 4;
- uint8_t reserved1[3];
- } readSingleWord;
- /* SetWriteMode parameter. */
- struct
- {
- uint8_t programRampControl;
- uint8_t eraseRampControl;
- uint8_t reserved[2];
- } setWriteMode;
- /* SetReadMode parameter. */
- struct
- {
- uint16_t readInterfaceTimingTrim;
- uint16_t readControllerTimingTrim;
- uint8_t readWaitStates;
- uint8_t reserved[3];
- } setReadMode;
-} flash_mode_config_t;
-
-/*! @brief Flash controller paramter config. */
-typedef struct _flash_ffr_config
-{
- uint32_t ffrBlockBase;
- uint32_t ffrTotalSize;
- uint32_t ffrPageSize;
- uint32_t cfpaPageVersion;
- uint32_t cfpaPageOffset;
-} flash_ffr_config_t;
-
-/*! @brief Flash driver state information.
- *
- * An instance of this structure is allocated by the user of the flash driver and
- * passed into each of the driver APIs.
- */
-typedef struct _flash_config
-{
- uint32_t PFlashBlockBase; /*!< A base address of the first PFlash block */
- uint32_t PFlashTotalSize; /*!< The size of the combined PFlash block. */
- uint32_t PFlashBlockCount; /*!< A number of PFlash blocks. */
- uint32_t PFlashPageSize; /*!< The size in bytes of a page of PFlash. */
- uint32_t PFlashSectorSize; /*!< The size in bytes of a sector of PFlash. */
- flash_ffr_config_t ffrConfig;
- flash_mode_config_t modeConfig;
-} flash_config_t;
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*!
- * @name Initialization
- * @{
- */
-
-/*!
- * @brief Initializes the global flash properties structure members.
- *
- * This function checks and initializes the Flash module for the other Flash APIs.
- *
- * @param config Pointer to the storage for the driver runtime state.
- *
- * @retval #kStatus_FLASH_Success API was executed successfully.
- * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
- * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
- */
-status_t FLASH_Init(flash_config_t *config);
-
-/*@}*/
-
-/*!
- * @name Erasing
- * @{
- */
-
-/*!
- * @brief Erases the flash sectors encompassed by parameters passed into function.
- *
- * This function erases the appropriate number of flash sectors based on the
- * desired start address and length.
- *
- * @param config The pointer to the storage for the driver runtime state.
- * @param start The start address of the desired flash memory to be erased.
- * The start address does not need to be sector-aligned.
- * @param lengthInBytes The length, given in bytes (not words or long-words)
- * to be erased. Must be word-aligned.
- * @param key The value used to validate all flash erase APIs.
- *
- * @retval #kStatus_FLASH_Success API was executed successfully.
- * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
- * @retval #kStatus_FLASH_AlignmentError The parameter is not aligned with the specified baseline.
- * @retval #kStatus_FLASH_AddressError The address is out of range.
- * @retval #kStatus_FLASH_EraseKeyError The API erase key is invalid.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
- * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
- */
-status_t FLASH_Erase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes, uint32_t key);
-
-/*@}*/
-
-/*!
- * @name Programming
- * @{
- */
-
-/*!
- * @brief Programs flash with data at locations passed in through parameters.
- *
- * This function programs the flash memory with the desired data for a given
- * flash area as determined by the start address and the length.
- *
- * @param config A pointer to the storage for the driver runtime state.
- * @param start The start address of the desired flash memory to be programmed. Must be
- * word-aligned.
- * @param src A pointer to the source buffer of data that is to be programmed
- * into the flash.
- * @param lengthInBytes The length, given in bytes (not words or long-words),
- * to be programmed. Must be word-aligned.
- *
- * @retval #kStatus_FLASH_Success API was executed successfully.
- * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
- * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with the specified baseline.
- * @retval #kStatus_FLASH_AddressError Address is out of range.
- * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
- * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
- */
-status_t FLASH_Program(flash_config_t *config, uint32_t start, uint8_t *src, uint32_t lengthInBytes);
-
-/*@}*/
-
-/*!
- * @name Verification
- * @{
- */
-
-/*!
- * @brief Verifies an erasure of the desired flash area at a specified margin level.
- *
- * This function checks the appropriate number of flash sectors based on
- * the desired start address and length to check whether the flash is erased
- * to the specified read margin level.
- *
- * @param config A pointer to the storage for the driver runtime state.
- * @param start The start address of the desired flash memory to be verified.
- * The start address does not need to be sector-aligned but must be word-aligned.
- * @param lengthInBytes The length, given in bytes (not words or long-words),
- * to be verified. Must be word-aligned.
- * @param margin Read margin choice.
- *
- * @retval #kStatus_FLASH_Success API was executed successfully.
- * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
- * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
- * @retval #kStatus_FLASH_AddressError Address is out of range.
- * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
- * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
- */
-status_t FLASH_VerifyErase(flash_config_t *config, uint32_t start, uint32_t lengthInBytes);
-
-/*!
- * @brief Verifies programming of the desired flash area at a specified margin level.
- *
- * This function verifies the data programed in the flash memory using the
- * Flash Program Check Command and compares it to the expected data for a given
- * flash area as determined by the start address and length.
- *
- * @param config A pointer to the storage for the driver runtime state.
- * @param start The start address of the desired flash memory to be verified. Must be word-aligned.
- * @param lengthInBytes The length, given in bytes (not words or long-words),
- * to be verified. Must be word-aligned.
- * @param expectedData A pointer to the expected data that is to be
- * verified against.
- * @param margin Read margin choice.
- * @param failedAddress A pointer to the returned failing address.
- * @param failedData A pointer to the returned failing data. Some derivatives do
- * not include failed data as part of the FCCOBx registers. In this
- * case, zeros are returned upon failure.
- *
- * @retval #kStatus_FLASH_Success API was executed successfully.
- * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
- * @retval #kStatus_FLASH_AlignmentError Parameter is not aligned with specified baseline.
- * @retval #kStatus_FLASH_AddressError Address is out of range.
- * @retval #kStatus_FLASH_AccessError Invalid instruction codes and out-of bounds addresses.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandFailure Run-time error during the command execution.
- * @retval #kStatus_FLASH_CommandNotSupported Flash API is not supported.
- * @retval #kStatus_FLASH_EccError A correctable or uncorrectable error during command execution.
- */
-status_t FLASH_VerifyProgram(flash_config_t *config,
- uint32_t start,
- uint32_t lengthInBytes,
- const uint8_t *expectedData,
- uint32_t *failedAddress,
- uint32_t *failedData);
-
-/*@}*/
-
-/*!
- * @name Properties
- * @{
- */
-
-/*!
- * @brief Returns the desired flash property.
- *
- * @param config A pointer to the storage for the driver runtime state.
- * @param whichProperty The desired property from the list of properties in
- * enum flash_property_tag_t
- * @param value A pointer to the value returned for the desired flash property.
- *
- * @retval #kStatus_FLASH_Success API was executed successfully.
- * @retval #kStatus_FLASH_InvalidArgument An invalid argument is provided.
- * @retval #kStatus_FLASH_UnknownProperty An unknown property tag.
- */
-status_t FLASH_GetProperty(flash_config_t *config, flash_property_tag_t whichProperty, uint32_t *value);
-
-/*@}*/
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __FLASH_FLASH_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap_ffr.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap_ffr.h
deleted file mode 100755
index 9d2b2311a..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iap_ffr.h
+++ /dev/null
@@ -1,274 +0,0 @@
-/*
- * Copyright 2018 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef __FSL_IAP_FFR_H_
-#define __FSL_IAP_FFR_H_
-
-#include "fsl_iap.h"
-
-/*!
- * @addtogroup flash_ifr_driver
- * @{
- */
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-/*!
- * @name Flash IFR version
- * @{
- */
-/*! @brief Flash IFR driver version for SDK*/
-#define FSL_FLASH_IFR_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
-/*@}*/
-
-/*! @brief Alignment(down) utility. */
-#if !defined(ALIGN_DOWN)
-#define ALIGN_DOWN(x, a) ((x) & (uint32_t)(-((int32_t)(a))))
-#endif
-
-/*! @brief Alignment(up) utility. */
-#if !defined(ALIGN_UP)
-#define ALIGN_UP(x, a) (-((int32_t)((uint32_t)(-((int32_t)(x))) & (uint32_t)(-((int32_t)(a))))))
-#endif
-
-#define FLASH_FFR_MAX_PAGE_SIZE (512u)
-#define FLASH_FFR_HASH_DIGEST_SIZE (32u)
-#define FLASH_FFR_IV_CODE_SIZE (52u)
-
-enum _flash_ffr_page_offset
-{
- kFfrPageOffset_CFPA = 0, /*!< Customer In-Field programmed area*/
- kFfrPageOffset_CFPA_Scratch = 0, /*!< CFPA Scratch page */
- kFfrPageOffset_CFPA_Cfg = 1, /*!< CFPA Configuration area (Ping page)*/
- kFfrPageOffset_CFPA_CfgPong = 2, /*!< Same as CFPA page (Pong page)*/
-
- kFfrPageOffset_CMPA = 3, /*!< Customer Manufacturing programmed area*/
- kFfrPageOffset_CMPA_Cfg = 3, /*!< CMPA Configuration area (Part of CMPA)*/
- kFfrPageOffset_CMPA_Key = 4, /*!< Key Store area (Part of CMPA)*/
-
- kFfrPageOffset_NMPA = 7, /*!< NXP Manufacturing programmed area*/
- kFfrPageOffset_NMPA_Romcp = 7, /*!< ROM patch area (Part of NMPA)*/
- kFfrPageOffset_NMPA_Repair = 9, /*!< Repair area (Part of NMPA)*/
- kFfrPageOffset_NMPA_Cfg = 15, /*!< NMPA configuration area (Part of NMPA)*/
- kFfrPageOffset_NMPA_End = 16, /*!< Reserved (Part of NMPA)*/
-};
-
-enum _flash_ffr_page_num
-{
- kFfrPageNum_CFPA = 3, /*!< Customer In-Field programmed area*/
- kFfrPageNum_CMPA = 4, /*!< Customer Manufacturing programmed area*/
- kFfrPageNum_NMPA = 10, /*!< NXP Manufacturing programmed area*/
-
- kFfrPageNum_CMPA_Cfg = 1,
- kFfrPageNum_CMPA_Key = 3,
- kFfrPageNum_NMPA_Romcp = 2,
-
- kFfrPageNum_SpecArea = kFfrPageNum_CFPA + kFfrPageNum_CMPA,
- kFfrPageNum_Total = (kFfrPageNum_CFPA + kFfrPageNum_CMPA + kFfrPageNum_NMPA),
-};
-
-enum _flash_ffr_block_size
-{
- kFfrBlockSize_Key = 52u,
- kFfrBlockSize_ActivationCode = 1192u,
-};
-
-typedef enum _cfpa_cfg_cmpa_prog_process
-{
- kFfrCmpaProgProcess_Pre = 0x0u,
- kFfrCmpaProgProcess_Post = 0xFFFFFFFFu,
-} cmpa_prog_process_t;
-
-typedef struct _cfpa_cfg_iv_code
-{
- uint32_t keycodeHeader;
- uint8_t reserved[FLASH_FFR_IV_CODE_SIZE];
-} cfpa_cfg_iv_code_t;
-
-typedef struct _cfpa_cfg_info
-{
- uint32_t header; /*!< [0x000-0x003] */
- uint32_t version; /*!< [0x004-0x007 */
- uint32_t secureFwVersion; /*!< [0x008-0x00b */
- uint32_t nsFwVersion; /*!< [0x00c-0x00f] */
- uint32_t imageKeyRevoke; /*!< [0x010-0x013] */
- uint8_t reserved0[4]; /*!< [0x014-0x017] */
- uint32_t rotkhRevoke; /*!< [0x018-0x01b] */
- uint32_t vendorUsage; /*!< [0x01c-0x01f] */
- uint32_t dcfgNsPin; /*!< [0x020-0x013] */
- uint32_t dcfgNsDflt; /*!< [0x024-0x017] */
- uint32_t enableFaMode; /*!< [0x028-0x02b] */
- uint8_t reserved1[4]; /*!< [0x02c-0x02f] */
- cfpa_cfg_iv_code_t ivCodePrinceRegion[3]; /*!< [0x030-0x0d7] */
- uint8_t reserved2[264]; /*!< [0x0d8-0x1df] */
- uint8_t sha256[32]; /*!< [0x1e0-0x1ff] */
-} cfpa_cfg_info_t;
-
-#define FFR_BOOTCFG_BOOTSPEED_MASK (0x18U)
-#define FFR_BOOTCFG_BOOTSPEED_SHIFT (7U)
-#define FFR_BOOTCFG_BOOTSPEED_48MHZ (0x0U)
-#define FFR_BOOTCFG_BOOTSPEED_96MHZ (0x1U)
-
-#define FFR_USBID_VENDORID_MASK (0xFFFFU)
-#define FFR_USBID_VENDORID_SHIFT (0U)
-#define FFR_USBID_PRODUCTID_MASK (0xFFFF0000U)
-#define FFR_USBID_PRODUCTID_SHIFT (16U)
-
-typedef struct _cmpa_cfg_info
-{
- uint32_t bootCfg; /*!< [0x000-0x003] */
- uint32_t spiFlashCfg; /*!< [0x004-0x007] */
- struct
- {
- uint16_t vid;
- uint16_t pid;
- } usbId; /*!< [0x008-0x00b] */
- uint32_t sdioCfg; /*!< [0x00c-0x00f] */
- uint32_t dcfgPin; /*!< [0x010-0x013] */
- uint32_t dcfgDflt; /*!< [0x014-0x017] */
- uint32_t dapVendorUsage; /*!< [0x018-0x01b] */
- uint32_t secureBootCfg; /*!< [0x01c-0x01f] */
- uint32_t princeBaseAddr; /*!< [0x020-0x023] */
- uint32_t princeSr[3]; /*!< [0x024-0x02f] */
- uint8_t reserved0[32]; /*!< [0x030-0x04f] */
- uint32_t rotkh[8]; /*!< [0x050-0x06f] */
- uint8_t reserved1[368]; /*!< [0x070-0x1df] */
- uint8_t sha256[32]; /*!< [0x1e0-0x1ff] */
-} cmpa_cfg_info_t;
-
-typedef struct _cmpa_key_store_header
-{
- uint32_t header;
- uint8_t reserved[4];
-} cmpa_key_store_header_t;
-
-#define FFR_SYSTEM_SPEED_CODE_MASK (0x3U)
-#define FFR_SYSTEM_SPEED_CODE_SHIFT (0U)
-#define FFR_SYSTEM_SPEED_CODE_FRO12MHZ_12MHZ (0x0U)
-#define FFR_SYSTEM_SPEED_CODE_FROHF96MHZ_24MHZ (0x1U)
-#define FFR_SYSTEM_SPEED_CODE_FROHF96MHZ_48MHZ (0x2U)
-#define FFR_SYSTEM_SPEED_CODE_FROHF96MHZ_96MHZ (0x3U)
-
-#define FFR_PERIPHERALCFG_PERI_MASK (0x7FFFFFFFU)
-#define FFR_PERIPHERALCFG_PERI_SHIFT (0U)
-#define FFR_PERIPHERALCFG_COREEN_MASK (0x10000000U)
-#define FFR_PERIPHERALCFG_COREEN_SHIFT (31U)
-
-typedef struct _nmpa_cfg_info
-{
- uint16_t fro32kCfg; /*!< [0x000-0x001] */
- uint8_t reserved0[6]; /*!< [0x002-0x007] */
- uint8_t sysCfg; /*!< [0x008-0x008] */
- uint8_t reserved1[7]; /*!< [0x009-0x00f] */
- struct
- {
- uint32_t data;
- uint32_t reserved[3];
- } GpoInitData[3]; /*!< [0x010-0x03f] */
- uint32_t GpoDataChecksum[4]; /*!< [0x040-0x04f] */
- uint32_t finalTestBatchId[4]; /*!< [0x050-0x05f] */
- uint32_t deviceType; /*!< [0x060-0x063] */
- uint32_t finalTestProgVersion; /*!< [0x064-0x067] */
- uint32_t finalTestDate; /*!< [0x068-0x06b] */
- uint32_t finalTestTime; /*!< [0x06c-0x06f] */
- uint32_t uuid[4]; /*!< [0x070-0x07f] */
- uint8_t reserved2[32]; /*!< [0x080-0x09f] */
- uint32_t peripheralCfg; /*!< [0x0a0-0x0a3] */
- uint32_t ramSizeCfg; /*!< [0x0a4-0x0a7] */
- uint32_t flashSizeCfg; /*!< [0x0a8-0x0ab] */
- uint8_t reserved3[36]; /*!< [0x0ac-0x0cf] */
- uint8_t fro1mCfg; /*!< [0x0d0-0x0d0] */
- uint8_t reserved4[15]; /*!< [0x0d1-0x0df] */
- uint32_t dcdc[4]; /*!< [0x0e0-0x0ef] */
- uint32_t bod; /*!< [0x0f0-0x0f3] */
- uint8_t reserved5[12]; /*!< [0x0f4-0x0ff] */
- uint8_t calcHashReserved[192]; /*!< [0x100-0x1bf] */
- uint8_t sha256[32]; /*!< [0x1c0-0x1df] */
- uint32_t ecidBackup[4]; /*!< [0x1e0-0x1ef] */
- uint32_t pageChecksum[4]; /*!< [0x1f0-0x1ff] */
-} nmpa_cfg_info_t;
-
-typedef struct _ffr_key_store
-{
- uint8_t reserved[3][FLASH_FFR_MAX_PAGE_SIZE];
-} ffr_key_store_t;
-
-typedef enum _ffr_key_type
-{
- kFFR_KeyTypeSbkek = 0x00U,
- kFFR_KeyTypeUser = 0x01U,
- kFFR_KeyTypeUds = 0x02U,
- kFFR_KeyTypePrinceRegion0 = 0x03U,
- kFFR_KeyTypePrinceRegion1 = 0x04U,
- kFFR_KeyTypePrinceRegion2 = 0x05U,
-} ffr_key_type_t;
-
-typedef enum _ffr_bank_type
-{
- kFFR_BankTypeBank0_NMPA = 0x00U,
- kFFR_BankTypeBank1_CMPA = 0x01U,
- kFFR_BankTypeBank2_CFPA = 0x02U
-} ffr_bank_type_t;
-
-/*******************************************************************************
- * API
- ******************************************************************************/
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-/*!
- * @name FFR APIs
- * @{
- */
-
-/*! Initializes the global FFR properties structure members.*/
-status_t FFR_Init(flash_config_t *config);
-
-/*!
- * @brief Enable firewall for all flash banks.
- * FFR region will be locked, After this function executed.
- */
-status_t FFR_Deinit(flash_config_t *config);
-
-/*! APIs to access CFPA pages */
-status_t FFR_InfieldPageWrite(flash_config_t *config, uint8_t *page_data, uint32_t valid_len);
-/*! Generic read function, used by customer to read data stored in 'Customer In-field Page. */
-status_t FFR_GetCustomerInfieldData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
-
-/*! APIs to access CMPA pages */
-/*!
- * @brief This routine will erase "customer factory page" and program the page with passed data.
- * If 'seal_part' parameter is TRUE then the routine will compute SHA256 hash of
- * the page contents and then programs the pages.
- * 1.During development customer code uses this API with 'seal_part' set to FALSE.
- * 2.During manufacturing this parameter should be set to TRUE to seal the part
- * from further modifications
- */
-status_t FFR_CustFactoryPageWrite(flash_config_t *config, uint8_t *page_data, bool seal_part);
-/*! Read data stored in 'Customer Factory CFG Page'. */
-status_t FFR_GetCustomerData(flash_config_t *config, uint8_t *pData, uint32_t offset, uint32_t len);
-status_t FFR_KeystoreWrite(flash_config_t *config, ffr_key_store_t *pKeyStore);
-status_t FFR_KeystoreGetAC(flash_config_t *config, uint8_t *pActivationCode);
-status_t FFR_KeystoreGetKC(flash_config_t *config, uint8_t *pKeyCode, ffr_key_type_t keyIndex);
-
-/*! APIs to access NMPA pages */
-/*! Read data stored in 'NXP Manufacuring Programmed CFG Page'. */
-status_t FFR_GetUUID(flash_config_t *config, uint8_t *uuid);
-
-#ifdef __cplusplus
-}
-#endif
-
-/*@}*/
-
-#endif /*! __FSL_FLASH_FFR_H_ */
diff --git a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iocon.h b/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iocon.h
deleted file mode 100755
index cf0cbd132..000000000
--- a/platform/ext/target/nxp/common/Native_Driver/drivers/fsl_iocon.h
+++ /dev/null
@@ -1,288 +0,0 @@
-/*
- * Copyright (c) 2016, Freescale Semiconductor, Inc.
- * Copyright 2016-2019 NXP
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef _FSL_IOCON_H_
-#define _FSL_IOCON_H_
-
-#include "fsl_common.h"
-
-/*!
- * @addtogroup lpc_iocon
- * @{
- */
-
-/*! @file */
-
-/*******************************************************************************
- * Definitions
- ******************************************************************************/
-
-/* Component ID definition, used by tools. */
-#ifndef FSL_COMPONENT_ID
-#define FSL_COMPONENT_ID "platform.drivers.lpc_iocon"
-#endif
-
-/*! @name Driver version */
-/*@{*/
-/*! @brief IOCON driver version 2.1.1. */
-#define FSL_IOCON_DRIVER_VERSION (MAKE_VERSION(2, 1, 1))
-/*@}*/
-
-/**
- * @brief Array of IOCON pin definitions passed to IOCON_SetPinMuxing() must be in this format
- */
-typedef struct _iocon_group
-{
- uint32_t port : 8; /* Pin port */
- uint32_t pin : 8; /* Pin number */
- uint32_t ionumber : 8; /* IO number */
- uint32_t modefunc : 16; /* Function and mode */
-} iocon_group_t;
-
-/**
- * @brief IOCON function and mode sele