First commit by adding drivers and Os core.
This commit is contained in:
commit
54b2ffcb7b
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
*.uvprojx
|
||||||
|
*.uvoptx
|
||||||
|
**/RTE
|
||||||
|
**/Objects
|
||||||
|
**/Listings
|
||||||
|
**/DebugConfig
|
||||||
|
osProject.uvguix.nxf54496
|
||||||
104
LPC55S69_cm33_core0_flash.scf
Normal file
104
LPC55S69_cm33_core0_flash.scf
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
#!armclang --target=arm-arm-none-eabi -march=armv8-m.main -E -x c
|
||||||
|
/*
|
||||||
|
** ###################################################################
|
||||||
|
** Processors: LPC55S69JBD100_cm33_core0
|
||||||
|
** LPC55S69JBD64_cm33_core0
|
||||||
|
** LPC55S69JEV59_cm33_core0
|
||||||
|
** LPC55S69JEV98_cm33_core0
|
||||||
|
**
|
||||||
|
** Compiler: Keil ARM C/C++ Compiler
|
||||||
|
** Reference manual: LPC55S6x/LPC55S2x/LPC552x User manual(UM11126) Rev.1.3 16 May 2019
|
||||||
|
** Version: rev. 1.1, 2019-05-16
|
||||||
|
** Build: b231019
|
||||||
|
**
|
||||||
|
** Abstract:
|
||||||
|
** Linker file for the Keil ARM C/C++ Compiler
|
||||||
|
**
|
||||||
|
** Copyright 2016 Freescale Semiconductor, Inc.
|
||||||
|
** Copyright 2016-2023 NXP
|
||||||
|
** SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
**
|
||||||
|
** http: www.nxp.com
|
||||||
|
** mail: support@nxp.com
|
||||||
|
**
|
||||||
|
** ###################################################################
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/* USB BDT size */
|
||||||
|
#define usb_bdt_size 0x0
|
||||||
|
/* Sizes */
|
||||||
|
#if (defined(__stack_size__))
|
||||||
|
#define Stack_Size __stack_size__
|
||||||
|
#else
|
||||||
|
#define Stack_Size 0x0400
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined(__heap_size__))
|
||||||
|
#define Heap_Size __heap_size__
|
||||||
|
#else
|
||||||
|
#define Heap_Size 0x0400
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define m_interrupts_start 0x00000000
|
||||||
|
#define m_interrupts_size 0x00000200
|
||||||
|
|
||||||
|
#define m_text_start 0x00000200
|
||||||
|
#define m_text_size 0x00071E00
|
||||||
|
|
||||||
|
#define m_core1_image_start 0x00072000
|
||||||
|
#define m_core1_image_size 0x0002B800
|
||||||
|
|
||||||
|
#if (defined(__use_shmem__))
|
||||||
|
#define m_data_start 0x20000000
|
||||||
|
#define m_data_size 0x00031800
|
||||||
|
#define m_rpmsg_sh_mem_start 0x20031800
|
||||||
|
#define m_rpmsg_sh_mem_size 0x00001800
|
||||||
|
#else
|
||||||
|
#define m_data_start 0x20000000
|
||||||
|
#define m_data_size 0x00033000
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define m_usb_sram_start 0x40100000
|
||||||
|
#define m_usb_sram_size 0x00004000
|
||||||
|
|
||||||
|
|
||||||
|
LR_m_text m_interrupts_start m_interrupts_size+m_text_size { ; load region size_region
|
||||||
|
|
||||||
|
VECTOR_ROM m_interrupts_start m_interrupts_size { ; load address = execution address
|
||||||
|
* (.isr_vector,+FIRST)
|
||||||
|
}
|
||||||
|
|
||||||
|
ER_m_text m_text_start FIXED m_text_size { ; load address = execution address
|
||||||
|
* (InRoot$$Sections)
|
||||||
|
.ANY (+RO)
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (defined(__use_shmem__))
|
||||||
|
RPMSG_SH_MEM m_rpmsg_sh_mem_start UNINIT m_rpmsg_sh_mem_size { ; Shared memory used by RPMSG
|
||||||
|
* (rpmsg_sh_mem_section)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RW_m_data m_data_start m_data_size-Stack_Size-Heap_Size { ; RW data
|
||||||
|
.ANY (+RW +ZI)
|
||||||
|
}
|
||||||
|
ARM_LIB_HEAP +0 EMPTY Heap_Size { ; Heap region growing up
|
||||||
|
}
|
||||||
|
ARM_LIB_STACK m_data_start+m_data_size EMPTY -Stack_Size { ; Stack region growing down
|
||||||
|
}
|
||||||
|
|
||||||
|
RW_m_usb_bdt m_usb_sram_start UNINIT usb_bdt_size {
|
||||||
|
* (*m_usb_bdt)
|
||||||
|
}
|
||||||
|
|
||||||
|
RW_m_usb_ram (m_usb_sram_start + usb_bdt_size) UNINIT (m_usb_sram_size - usb_bdt_size) {
|
||||||
|
* (*m_usb_global)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LR_CORE1_IMAGE m_core1_image_start {
|
||||||
|
CORE1_REGION m_core1_image_start m_core1_image_size {
|
||||||
|
* (.core1_code)
|
||||||
|
}
|
||||||
|
}
|
||||||
13
RidhaOs/Inc/timebase.h
Normal file
13
RidhaOs/Inc/timebase.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef __TIMEBASE_H__
|
||||||
|
#define __TIMEBASE_H__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t get_tick(void);
|
||||||
|
void delay_s(uint32_t delay);
|
||||||
|
void delay_ms(uint32_t delay);
|
||||||
|
|
||||||
|
void timebase_init(void);
|
||||||
|
|
||||||
|
#endif /* __TIMEBASE_H__ */
|
||||||
72
RidhaOs/Src/timebase.c
Normal file
72
RidhaOs/Src/timebase.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "timebase.h"
|
||||||
|
#include "fsl_device_registers.h"
|
||||||
|
|
||||||
|
#define CTRL_ENABLE (1U<<0)
|
||||||
|
#define CTRL_TICKINT (1U<<1)
|
||||||
|
#define CTRL_CLKSRC (1U<<2)
|
||||||
|
#define CTRL_COUNTFLAG (1U<<16)
|
||||||
|
#define MAX_DELAY 0xFFFFFFFFU
|
||||||
|
|
||||||
|
volatile uint32_t g_curr_tick;
|
||||||
|
volatile uint32_t g_curr_tick_p;
|
||||||
|
volatile uint32_t tick_freq = 1;
|
||||||
|
|
||||||
|
uint8_t tick_freq_div = 1;
|
||||||
|
|
||||||
|
void tick_increment(void)
|
||||||
|
{
|
||||||
|
g_curr_tick += tick_freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delay_s(uint32_t delay)
|
||||||
|
{
|
||||||
|
delay_ms(delay * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void delay_ms(uint32_t delay)
|
||||||
|
{
|
||||||
|
uint32_t tickstart = get_tick();
|
||||||
|
uint32_t wait = delay;
|
||||||
|
if(wait < MAX_DELAY)
|
||||||
|
{
|
||||||
|
wait += (uint32_t)(tick_freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
while((get_tick() - tickstart) < wait){}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t get_tick(void)
|
||||||
|
{
|
||||||
|
__disable_irq();
|
||||||
|
g_curr_tick_p = g_curr_tick;
|
||||||
|
__enable_irq();
|
||||||
|
return g_curr_tick_p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void timebase_init(void)
|
||||||
|
{
|
||||||
|
/* Reload the timer with number of cycles per second */
|
||||||
|
/* Getting SystemCoreClock divide by 1000 to get interrupt every 1ms */
|
||||||
|
SysTick->LOAD = (SystemCoreClock / 1000) - 1;
|
||||||
|
|
||||||
|
/* Clear Systick current value register */
|
||||||
|
SysTick->VAL = 0x00;
|
||||||
|
|
||||||
|
/* Select Internal Clock source */
|
||||||
|
SysTick->CTRL = CTRL_CLKSRC;
|
||||||
|
|
||||||
|
/* Enable interrupt */
|
||||||
|
SysTick->CTRL |= CTRL_TICKINT;
|
||||||
|
|
||||||
|
/* Enable Systick */
|
||||||
|
SysTick->CTRL |= CTRL_ENABLE;
|
||||||
|
|
||||||
|
/* Enable Global Interrupt */
|
||||||
|
__enable_irq();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SysTick_Handler(void){
|
||||||
|
tick_increment();
|
||||||
|
}
|
||||||
829
drivers/Inc/fsl_adapter_uart.h
Normal file
829
drivers/Inc/fsl_adapter_uart.h
Normal file
@ -0,0 +1,829 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-2020 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __HAL_UART_ADAPTER_H__
|
||||||
|
#define __HAL_UART_ADAPTER_H__
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
#if defined(SDK_OS_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 Enable or disable uart hardware FIFO mode (1 - enable, 0 - disable) */
|
||||||
|
#ifndef HAL_UART_ADAPTER_FIFO
|
||||||
|
#define HAL_UART_ADAPTER_FIFO (1U)
|
||||||
|
#endif /* HAL_UART_ADAPTER_FIFO */
|
||||||
|
|
||||||
|
#if (defined(SERIAL_PORT_TYPE_UART_DMA) && (SERIAL_PORT_TYPE_UART_DMA > 0U))
|
||||||
|
#ifndef HAL_UART_DMA_ENABLE
|
||||||
|
#define HAL_UART_DMA_ENABLE (1U)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAL_UART_DMA_ENABLE
|
||||||
|
#define HAL_UART_DMA_ENABLE (0U)
|
||||||
|
#endif /* HAL_UART_DMA_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Enable or disable uart DMA adapter int mode (1 - enable, 0 - disable) */
|
||||||
|
#ifndef HAL_UART_DMA_INIT_ENABLE
|
||||||
|
#define HAL_UART_DMA_INIT_ENABLE (1U)
|
||||||
|
#endif /* HAL_SPI_MASTER_DMA_INIT_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition of uart dma adapter software idleline detection timeout value in ms. */
|
||||||
|
#ifndef HAL_UART_DMA_IDLELINE_TIMEOUT
|
||||||
|
#define HAL_UART_DMA_IDLELINE_TIMEOUT (1U)
|
||||||
|
#endif /* HAL_UART_DMA_IDLELINE_TIMEOUT */
|
||||||
|
|
||||||
|
/*! @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 (92U + HAL_UART_ADAPTER_LOWPOWER * 16U + HAL_UART_DMA_ENABLE * 4U)
|
||||||
|
#define HAL_UART_BLOCK_HANDLE_SIZE (8U + HAL_UART_ADAPTER_LOWPOWER * 16U + HAL_UART_DMA_ENABLE * 4U)
|
||||||
|
#else
|
||||||
|
#define HAL_UART_HANDLE_SIZE (8U + HAL_UART_ADAPTER_LOWPOWER * 16U + HAL_UART_DMA_ENABLE * 4U)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @brief Definition of uart dma adapter handle size. */
|
||||||
|
#if (defined(HAL_UART_DMA_ENABLE) && (HAL_UART_DMA_ENABLE > 0U))
|
||||||
|
#if (defined(FSL_FEATURE_SOC_DMA_COUNT) && (FSL_FEATURE_SOC_DMA_COUNT > 0U))
|
||||||
|
#define HAL_UART_DMA_HANDLE_SIZE (124U + HAL_UART_ADAPTER_LOWPOWER * 36U)
|
||||||
|
#elif (defined(FSL_FEATURE_SOC_EDMA_COUNT) && (FSL_FEATURE_SOC_EDMA_COUNT > 0U))
|
||||||
|
#define HAL_UART_DMA_HANDLE_SIZE (140U + HAL_UART_ADAPTER_LOWPOWER * 36U)
|
||||||
|
#else
|
||||||
|
#error This SOC does not have DMA or EDMA available!
|
||||||
|
#endif
|
||||||
|
#endif /* HAL_UART_DMA_ENABLE */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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))]
|
||||||
|
|
||||||
|
#if (defined(HAL_UART_DMA_ENABLE) && (HAL_UART_DMA_ENABLE > 0U))
|
||||||
|
#define UART_DMA_HANDLE_DEFINE(name) \
|
||||||
|
uint32_t name[((HAL_UART_DMA_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @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 The handle of uart dma adapter. */
|
||||||
|
typedef void *hal_uart_dma_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 = 0x2U, /*!< Parity even enabled */
|
||||||
|
kHAL_UartParityOdd = 0x3U, /*!< 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 enableRxRTS; /*!< Enable RX RTS */
|
||||||
|
uint8_t enableTxCTS; /*!< Enable TX CTS */
|
||||||
|
uint8_t instance; /*!< Instance (0 - UART0, 1 - UART1, ...), detail information please refer to the
|
||||||
|
SOC corresponding RM.
|
||||||
|
Invalid instance value will cause initialization failure. */
|
||||||
|
#if (defined(HAL_UART_ADAPTER_FIFO) && (HAL_UART_ADAPTER_FIFO > 0u))
|
||||||
|
uint8_t txFifoWatermark;
|
||||||
|
uint8_t rxFifoWatermark;
|
||||||
|
#endif
|
||||||
|
} hal_uart_config_t;
|
||||||
|
|
||||||
|
#if (defined(HAL_UART_DMA_ENABLE) && (HAL_UART_DMA_ENABLE > 0U))
|
||||||
|
/*! @brief UART DMA status */
|
||||||
|
typedef enum _hal_uart_dma_status
|
||||||
|
{
|
||||||
|
kStatus_HAL_UartDmaSuccess = 0U,
|
||||||
|
kStatus_HAL_UartDmaRxIdle = (1U << 1U),
|
||||||
|
kStatus_HAL_UartDmaRxBusy = (1U << 2U),
|
||||||
|
kStatus_HAL_UartDmaTxIdle = (1U << 3U),
|
||||||
|
kStatus_HAL_UartDmaTxBusy = (1U << 4U),
|
||||||
|
kStatus_HAL_UartDmaIdleline = (1U << 5U),
|
||||||
|
kStatus_HAL_UartDmaError = (1U << 6U),
|
||||||
|
} hal_uart_dma_status_t;
|
||||||
|
|
||||||
|
typedef struct _dma_mux_configure_t
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint8_t dma_mux_instance;
|
||||||
|
uint32_t rx_request;
|
||||||
|
uint32_t tx_request;
|
||||||
|
} dma_dmamux_configure;
|
||||||
|
};
|
||||||
|
} dma_mux_configure_t;
|
||||||
|
typedef struct _dma_channel_mux_configure_t
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
uint32_t dma_rx_channel_mux;
|
||||||
|
uint32_t dma_tx_channel_mux;
|
||||||
|
} dma_dmamux_configure;
|
||||||
|
};
|
||||||
|
} dma_channel_mux_configure_t;
|
||||||
|
|
||||||
|
typedef struct _hal_uart_dma_config_t
|
||||||
|
{
|
||||||
|
uint8_t uart_instance;
|
||||||
|
uint8_t dma_instance;
|
||||||
|
uint8_t rx_channel;
|
||||||
|
uint8_t tx_channel;
|
||||||
|
void *dma_mux_configure;
|
||||||
|
void *dma_channel_mux_configure;
|
||||||
|
} hal_uart_dma_config_t;
|
||||||
|
#endif /* HAL_UART_DMA_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief UART transfer callback function. */
|
||||||
|
typedef void (*hal_uart_transfer_callback_t)(hal_uart_handle_t handle, hal_uart_status_t status, void *callbackParam);
|
||||||
|
|
||||||
|
#if (defined(HAL_UART_DMA_ENABLE) && (HAL_UART_DMA_ENABLE > 0U))
|
||||||
|
typedef struct _dma_callback_msg
|
||||||
|
{
|
||||||
|
hal_uart_dma_status_t status;
|
||||||
|
uint8_t *data;
|
||||||
|
uint32_t dataSize;
|
||||||
|
} hal_dma_callback_msg_t;
|
||||||
|
|
||||||
|
/*! @brief UART transfer callback function. */
|
||||||
|
typedef void (*hal_uart_dma_transfer_callback_t)(hal_uart_dma_handle_t handle,
|
||||||
|
hal_dma_callback_msg_t *msg,
|
||||||
|
void *callbackParam);
|
||||||
|
#endif /* HAL_UART_DMA_ENABLE */
|
||||||
|
|
||||||
|
/*! @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.enableRxRTS = 0;
|
||||||
|
* config.enableTxCTS = 0;
|
||||||
|
* 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 uart_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, const hal_uart_config_t *uart_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_HAL_UartRxIdle.
|
||||||
|
*
|
||||||
|
* @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_HAL_UartTxIdle 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_HAL_UartRxIdle.
|
||||||
|
*
|
||||||
|
* @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_HAL_UartTxIdle 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 reCount 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 seCount 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
|
||||||
|
|
||||||
|
#if (defined(HAL_UART_DMA_ENABLE) && (HAL_UART_DMA_ENABLE > 0U))
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Initializes a UART dma instance with the UART dma handle and the user configuration structure.
|
||||||
|
*
|
||||||
|
* This function configures the UART dma 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_DMA_HANDLE_SIZE allocated
|
||||||
|
* by the caller. Example below shows how to use this API to configure the UART.
|
||||||
|
* @code
|
||||||
|
*
|
||||||
|
* Init TimerManager, only used in UART without Idleline interrupt
|
||||||
|
* timer_config_t timerConfig;
|
||||||
|
* timerConfig.srcClock_Hz = 16000000;
|
||||||
|
* timerConfig.instance = 0;
|
||||||
|
* TM_Init(&timerConfig);
|
||||||
|
*
|
||||||
|
* Init the DMA module
|
||||||
|
* DMA_Init(DMA0);
|
||||||
|
*
|
||||||
|
* Define a uart dma handle
|
||||||
|
* UART_HANDLE_DEFINE(g_uartHandle);
|
||||||
|
* UART_DMA_HANDLE_DEFINE(g_UartDmaHandle);
|
||||||
|
*
|
||||||
|
* Configure uart settings
|
||||||
|
* hal_uart_config_t uartConfig;
|
||||||
|
* uartConfig.srcClock_Hz = 48000000;
|
||||||
|
* uartConfig.baudRate_Bps = 115200;
|
||||||
|
* uartConfig.parityMode = kHAL_UartParityDisabled;
|
||||||
|
* uartConfig.stopBitCount = kHAL_UartOneStopBit;
|
||||||
|
* uartConfig.enableRx = 1;
|
||||||
|
* uartConfig.enableTx = 1;
|
||||||
|
* uartConfig.enableRxRTS = 0;
|
||||||
|
* uartConfig.enableTxCTS = 0;
|
||||||
|
* uartConfig.instance = 0;
|
||||||
|
*
|
||||||
|
* Init uart
|
||||||
|
* HAL_UartInit((hal_uart_handle_t *)g_uartHandle, &uartConfig);
|
||||||
|
*
|
||||||
|
* Configure uart dma settings
|
||||||
|
* hal_uart_dma_config_t dmaConfig;
|
||||||
|
* dmaConfig.uart_instance = 0;
|
||||||
|
* dmaConfig.dma_instance = 0;
|
||||||
|
* dmaConfig.rx_channel = 0;
|
||||||
|
* dmaConfig.tx_channel = 1;
|
||||||
|
*
|
||||||
|
* Init uart dma
|
||||||
|
* HAL_UartDMAInit((hal_uart_handle_t *)g_uartHandle, (hal_uart_dma_handle_t *)g_uartDmaHandle, &dmaConfig);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @param dmaHandle Pointer to point to a memory space of size #HAL_UART_DMA_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_DMA_HANDLE_DEFINE(handle);
|
||||||
|
* or
|
||||||
|
* uint32_t handle[((HAL_UART_DMA_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))];
|
||||||
|
* @param dmaConfig Pointer to user-defined configuration structure.
|
||||||
|
* @retval kStatus_HAL_UartDmaError UART dma initialization failed.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess UART dma initialization succeed.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMAInit(hal_uart_handle_t handle,
|
||||||
|
hal_uart_dma_handle_t dmaHandle,
|
||||||
|
hal_uart_dma_config_t *dmaConfig);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Deinitializes a UART DMA instance.
|
||||||
|
*
|
||||||
|
* This function will abort uart dma receive/send transfer and deinitialize UART.
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess UART DMA de-initialization succeed
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMADeinit(hal_uart_handle_t handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Installs a callback and callback parameter.
|
||||||
|
*
|
||||||
|
* This function is used to install the callback and callback parameter for UART DMA module.
|
||||||
|
* When any status of the UART DMA 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_UartDmaSuccess Successfully install the callback.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMATransferInstallCallback(hal_uart_handle_t handle,
|
||||||
|
hal_uart_dma_transfer_callback_t callback,
|
||||||
|
void *callbackParam);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Receives a buffer of data using an dma method.
|
||||||
|
*
|
||||||
|
* This function receives data using an dma 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 DMA driver.
|
||||||
|
* When all data is received, the UART DMA adapter notifies the upper layer
|
||||||
|
* through a callback function and passes the status parameter @ref kStatus_HAL_UartDmaRxIdle.
|
||||||
|
*
|
||||||
|
* When an idleline is detected, the UART DMA adapter notifies the upper layer through a callback function,
|
||||||
|
* and passes the status parameter @ref kStatus_HAL_UartDmaIdleline. For the UARTs without hardware idleline
|
||||||
|
* interrupt(like usart), it will use a software idleline detection method with the help of TimerManager.
|
||||||
|
*
|
||||||
|
* When the soc support cache, uplayer should do cache maintain operations for transfer buffer before call this API.
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @param data data Start address of the buffer to store the received data.
|
||||||
|
* @param length Size of the buffer.
|
||||||
|
* @param receiveAll Idleline interrupt will not end transfer process if set true.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess Successfully start the data receive.
|
||||||
|
* @retval kStatus_HAL_UartDmaRxBusy Previous receive request is not finished.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMATransferReceive(hal_uart_handle_t handle,
|
||||||
|
uint8_t *data,
|
||||||
|
size_t length,
|
||||||
|
bool receiveAll);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Transmits a buffer of data using an dma method.
|
||||||
|
*
|
||||||
|
* This function sends data using an dma 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 by DMA, the UART DMA driver calls the callback
|
||||||
|
* function and passes the @ref kStatus_HAL_UartDmaTxIdle as status parameter.
|
||||||
|
*
|
||||||
|
* When the soc support cache, uplayer should do cache maintain operations for transfer buffer before call this API.
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @param data data Start address of the data to write.
|
||||||
|
* @param length Size of the data to write.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess Successfully start the data transmission.
|
||||||
|
* @retval kStatus_HAL_UartDmaTxBusy Previous send request is not finished.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMATransferSend(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 reCount Receive bytes count.
|
||||||
|
* @retval kStatus_HAL_UartDmaError An error occurred.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess Get successfully through the parameter \p reCount.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMAGetReceiveCount(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 DMA method.
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @param seCount Send bytes count.
|
||||||
|
* @retval kStatus_HAL_UartDmaError An error occurred.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess Get successfully through the parameter \p seCount.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMAGetSendCount(hal_uart_handle_t handle, uint32_t *seCount);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Aborts the DMA-driven data receiving.
|
||||||
|
*
|
||||||
|
* This function aborts the DMA-driven data receiving.
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @retval kStatus_HAL_UartDmaSuccess Get successfully abort the receiving.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMAAbortReceive(hal_uart_handle_t handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Aborts the DMA-driven data sending.
|
||||||
|
*
|
||||||
|
* This function aborts the DMA-driven data sending.
|
||||||
|
*
|
||||||
|
* @param handle UART handle pointer.
|
||||||
|
* @retval kStatus_Success Get successfully abort the sending.
|
||||||
|
*/
|
||||||
|
hal_uart_dma_status_t HAL_UartDMAAbortSend(hal_uart_handle_t handle);
|
||||||
|
#endif /* HAL_UART_DMA_ENABLE */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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__ */
|
||||||
51
drivers/Inc/fsl_assert.h
Normal file
51
drivers/Inc/fsl_assert.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2023 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FSL_ASSERT_H_
|
||||||
|
#define _FSL_ASSERT_H_
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup assert
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Prototypes
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*! @name Initialization*/
|
||||||
|
/* @{ */
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Assert hook that can be redifined
|
||||||
|
*
|
||||||
|
* @param failedExpr Expression that caused the assert
|
||||||
|
* @param file File where the exception occured.
|
||||||
|
* @param line Line on the file where the exception occured.
|
||||||
|
*/
|
||||||
|
int fsl_assert_hook(const char *failedExpr, const char *file, int line);
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif /* _FSL_DEBUGCONSOLE_H_ */
|
||||||
|
|
||||||
1506
drivers/Inc/fsl_clock.h
Normal file
1506
drivers/Inc/fsl_clock.h
Normal file
File diff suppressed because it is too large
Load Diff
345
drivers/Inc/fsl_common.h
Normal file
345
drivers/Inc/fsl_common.h
Normal file
@ -0,0 +1,345 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2022 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__) || (defined(__CC_ARM) || defined(__ARMCC_VERSION)) || defined(__GNUC__)
|
||||||
|
#include <stddef.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "fsl_device_registers.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup ksdk_common
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Configurations
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @brief Macro to use the default weak IRQ handler in drivers. */
|
||||||
|
#ifndef FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ
|
||||||
|
#define FSL_DRIVER_TRANSFER_DOUBLE_WEAK_IRQ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @brief Construct a status code value from a group and code number. */
|
||||||
|
#define MAKE_STATUS(group, code) ((((group)*100L) + (code)))
|
||||||
|
|
||||||
|
/*! @brief Construct the version number for drivers.
|
||||||
|
*
|
||||||
|
* The driver version is a 32-bit number, for both 32-bit platforms(such as Cortex M)
|
||||||
|
* and 16-bit platforms(such as DSC).
|
||||||
|
*
|
||||||
|
* @verbatim
|
||||||
|
|
||||||
|
| Unused || Major Version || Minor Version || Bug Fix |
|
||||||
|
31 25 24 17 16 9 8 0
|
||||||
|
|
||||||
|
@endverbatim
|
||||||
|
*/
|
||||||
|
#define MAKE_VERSION(major, minor, bugfix) (((major)*65536L) + ((minor)*256L) + (bugfix))
|
||||||
|
|
||||||
|
/*! @name Driver version */
|
||||||
|
/*! @{ */
|
||||||
|
/*! @brief common driver version. */
|
||||||
|
#define FSL_COMMON_DRIVER_VERSION (MAKE_VERSION(2, 4, 1))
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*! @name 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. */
|
||||||
|
#define DEBUG_CONSOLE_DEVICE_TYPE_QSCI 10U /*!< Debug console based on QSCI. */
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*! @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_SFA = 103, /*!< Group number for SFA status codes*/
|
||||||
|
kStatusGroup_SPC = 104, /*!< Group number for SPC status codes. */
|
||||||
|
kStatusGroup_PUF = 105, /*!< Group number for PUF status codes. */
|
||||||
|
kStatusGroup_TOUCH_PANEL = 106, /*!< Group number for touch panel status codes */
|
||||||
|
kStatusGroup_VBAT = 107, /*!< Group number for VBAT status codes */
|
||||||
|
kStatusGroup_XSPI = 108, /*!< Group number for XSPI status codes */
|
||||||
|
kStatusGroup_PNGDEC = 109, /*!< Group number for PNGDEC status codes */
|
||||||
|
kStatusGroup_JPEGDEC = 110, /*!< Group number for JPEGDEC 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_HAL_I2S = 129, /*!< Group number for HAL I2S status codes. */
|
||||||
|
kStatusGroup_HAL_ADC_SENSOR = 130, /*!< Group number for HAL ADC SENSOR 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. */
|
||||||
|
kStatusGroup_SDIOSLV = 151, /*!< Group number for SDIOSLV status codes. */
|
||||||
|
kStatusGroup_MECC = 152, /*!< Group number for MECC status codes. */
|
||||||
|
kStatusGroup_ENET_QOS = 153, /*!< Group number for ENET_QOS status codes. */
|
||||||
|
kStatusGroup_LOG = 154, /*!< Group number for LOG status codes. */
|
||||||
|
kStatusGroup_I3CBUS = 155, /*!< Group number for I3CBUS status codes. */
|
||||||
|
kStatusGroup_QSCI = 156, /*!< Group number for QSCI status codes. */
|
||||||
|
kStatusGroup_ELEMU = 157, /*!< Group number for ELEMU status codes. */
|
||||||
|
kStatusGroup_QUEUEDSPI = 158, /*!< Group number for QSPI status codes. */
|
||||||
|
kStatusGroup_POWER_MANAGER = 159, /*!< Group number for POWER_MANAGER status codes. */
|
||||||
|
kStatusGroup_IPED = 160, /*!< Group number for IPED status codes. */
|
||||||
|
kStatusGroup_ELS_PKC = 161, /*!< Group number for ELS PKC status codes. */
|
||||||
|
kStatusGroup_CSS_PKC = 162, /*!< Group number for CSS PKC status codes. */
|
||||||
|
kStatusGroup_HOSTIF = 163, /*!< Group number for HOSTIF status codes. */
|
||||||
|
kStatusGroup_CLIF = 164, /*!< Group number for CLIF status codes. */
|
||||||
|
kStatusGroup_BMA = 165, /*!< Group number for BMA status codes. */
|
||||||
|
kStatusGroup_NETC = 166, /*!< Group number for NETC status codes. */
|
||||||
|
kStatusGroup_ELE = 167, /*!< Group number for ELE status codes. */
|
||||||
|
kStatusGroup_GLIKEY = 168, /*!< Group number for GLIKEY status codes. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*! \public
|
||||||
|
* @brief Generic status return codes.
|
||||||
|
*/
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
kStatus_Success = MAKE_STATUS(kStatusGroup_Generic, 0), /*!< Generic status for Success. */
|
||||||
|
kStatus_Fail = MAKE_STATUS(kStatusGroup_Generic, 1), /*!< Generic status for Fail. */
|
||||||
|
kStatus_ReadOnly = MAKE_STATUS(kStatusGroup_Generic, 2), /*!< Generic status for read only failure. */
|
||||||
|
kStatus_OutOfRange = MAKE_STATUS(kStatusGroup_Generic, 3), /*!< Generic status for out of range access. */
|
||||||
|
kStatus_InvalidArgument = MAKE_STATUS(kStatusGroup_Generic, 4), /*!< Generic status for invalid argument check. */
|
||||||
|
kStatus_Timeout = MAKE_STATUS(kStatusGroup_Generic, 5), /*!< Generic status for timeout. */
|
||||||
|
kStatus_NoTransferInProgress =
|
||||||
|
MAKE_STATUS(kStatusGroup_Generic, 6), /*!< Generic status for no transfer in progress. */
|
||||||
|
kStatus_Busy = MAKE_STATUS(kStatusGroup_Generic, 7), /*!< Generic status for module is busy. */
|
||||||
|
kStatus_NoData =
|
||||||
|
MAKE_STATUS(kStatusGroup_Generic, 8), /*!< Generic status for no data is found for the operation. */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*! @brief Type used for all status and error return values. */
|
||||||
|
typedef int32_t status_t;
|
||||||
|
|
||||||
|
#ifdef __ZEPHYR__
|
||||||
|
#include <zephyr/sys/util.h>
|
||||||
|
#else
|
||||||
|
/*!
|
||||||
|
* @name Min/max macros
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#if !defined(MIN)
|
||||||
|
/*! Computes the minimum of \a a and \a b. */
|
||||||
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(MAX)
|
||||||
|
/*! Computes the maximum of \a a and \a b. */
|
||||||
|
#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
|
||||||
|
#endif /* __ZEPHYR__ */
|
||||||
|
|
||||||
|
/*! @name UINT16_MAX/UINT32_MAX value */
|
||||||
|
/*! @{ */
|
||||||
|
#if !defined(UINT16_MAX)
|
||||||
|
/*! Max value of uint16_t type. */
|
||||||
|
#define UINT16_MAX ((uint16_t)-1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(UINT32_MAX)
|
||||||
|
/*! Max value of uint32_t type. */
|
||||||
|
#define UINT32_MAX ((uint32_t)-1)
|
||||||
|
#endif
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*! Macro to get upper 32 bits of a 64-bit value */
|
||||||
|
#if !defined(UINT64_H)
|
||||||
|
#define UINT64_H(X) ((uint32_t)((((uint64_t) (X)) >> 32U) & 0x0FFFFFFFFULL))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! Macro to get lower 32 bits of a 64-bit value */
|
||||||
|
#if !defined(UINT64_L)
|
||||||
|
#define UINT64_L(X) ((uint32_t)(((uint64_t) (X)) & 0x0FFFFFFFFULL))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def SUPPRESS_FALL_THROUGH_WARNING()
|
||||||
|
*
|
||||||
|
* 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__) && !defined(__ARMCC_VERSION)
|
||||||
|
#define SUPPRESS_FALL_THROUGH_WARNING() __attribute__((fallthrough))
|
||||||
|
#else
|
||||||
|
#define SUPPRESS_FALL_THROUGH_WARNING()
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* API
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !((defined(__DSC__) && defined(__CW__)))
|
||||||
|
/*!
|
||||||
|
* @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);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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 delayTime_us Delay time in unit of microsecond.
|
||||||
|
* @param coreClock_Hz Core clock frequency with Hz.
|
||||||
|
*/
|
||||||
|
void SDK_DelayAtLeastUs(uint32_t delayTime_us, uint32_t coreClock_Hz);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#if (defined(__DSC__) && defined(__CW__))
|
||||||
|
#include "fsl_common_dsc.h"
|
||||||
|
#elif defined(__XTENSA__)
|
||||||
|
#include "fsl_common_dsp.h"
|
||||||
|
#else
|
||||||
|
#include "fsl_common_arm.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* FSL_COMMON_H_ */
|
||||||
898
drivers/Inc/fsl_common_arm.h
Normal file
898
drivers/Inc/fsl_common_arm.h
Normal file
@ -0,0 +1,898 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2022 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FSL_COMMON_ARM_H_
|
||||||
|
#define FSL_COMMON_ARM_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For CMSIS pack RTE.
|
||||||
|
* CMSIS pack RTE generates "RTC_Components.h" which contains the statements
|
||||||
|
* of the related <RTE_Components_h> element for all selected software components.
|
||||||
|
*/
|
||||||
|
#ifdef _RTE_
|
||||||
|
#include "RTE_Components.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup ksdk_common
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! @name Atomic modification
|
||||||
|
*
|
||||||
|
* These macros are used for atomic access, such as read-modify-write
|
||||||
|
* to the peripheral registers.
|
||||||
|
*
|
||||||
|
* Take @ref SDK_ATOMIC_LOCAL_CLEAR_AND_SET as an example: the parameter @c addr
|
||||||
|
* means the address of the peripheral register or variable you want to modify
|
||||||
|
* atomically, the parameter @c clearBits is the bits to clear, the parameter
|
||||||
|
* @c setBits it the bits to set.
|
||||||
|
* For example, to set a 32-bit register bit1:bit0 to 0b10, use like this:
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
volatile uint32_t * reg = (volatile uint32_t *)REG_ADDR;
|
||||||
|
|
||||||
|
SDK_ATOMIC_LOCAL_CLEAR_AND_SET(reg, 0x03, 0x02);
|
||||||
|
@endcode
|
||||||
|
*
|
||||||
|
* In this example, the register bit1:bit0 are cleared and bit1 is set, as a result,
|
||||||
|
* register bit1:bit0 = 0b10.
|
||||||
|
*
|
||||||
|
* @note For the platforms don't support exclusive load and store, these macros
|
||||||
|
* disable the global interrupt to pretect the modification.
|
||||||
|
*
|
||||||
|
* @note These macros only guarantee the local processor atomic operations. For
|
||||||
|
* the multi-processor devices, use hardware semaphore such as SEMA42 to
|
||||||
|
* guarantee exclusive access if necessary.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def SDK_ATOMIC_LOCAL_ADD(addr, val)
|
||||||
|
* Add value \a val from the variable at address \a address.
|
||||||
|
*
|
||||||
|
* @def SDK_ATOMIC_LOCAL_SUB(addr, val)
|
||||||
|
* Subtract value \a val to the variable at address \a address.
|
||||||
|
*
|
||||||
|
* @def SDK_ATOMIC_LOCAL_SET(addr, bits)
|
||||||
|
* Set the bits specifiled by \a bits to the variable at address \a address.
|
||||||
|
*
|
||||||
|
* @def SDK_ATOMIC_LOCAL_CLEAR(addr, bits)
|
||||||
|
* Clear the bits specifiled by \a bits to the variable at address \a address.
|
||||||
|
*
|
||||||
|
* @def SDK_ATOMIC_LOCAL_TOGGLE(addr, bits)
|
||||||
|
* Toggle the bits specifiled by \a bits to the variable at address \a address.
|
||||||
|
*
|
||||||
|
* @def SDK_ATOMIC_LOCAL_CLEAR_AND_SET(addr, clearBits, setBits)
|
||||||
|
* For the variable at address \a address, clear the bits specifiled by \a clearBits
|
||||||
|
* and set the bits specifiled by \a setBits.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
#if ((defined(__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
|
||||||
|
(defined(__ARM_ARCH_7EM__ ) && (__ARM_ARCH_7EM__ == 1)) || \
|
||||||
|
(defined(__ARM_ARCH_8M_MAIN__) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
|
||||||
|
(defined(__ARM_ARCH_8M_BASE__) && (__ARM_ARCH_8M_BASE__ == 1)))
|
||||||
|
/* clang-format on */
|
||||||
|
|
||||||
|
/* If the LDREX and STREX are supported, use them. */
|
||||||
|
#define _SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, val, ops) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
(val) = __LDREXB(addr); \
|
||||||
|
(ops); \
|
||||||
|
} while (0UL != __STREXB((val), (addr)))
|
||||||
|
|
||||||
|
#define _SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, val, ops) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
(val) = __LDREXH(addr); \
|
||||||
|
(ops); \
|
||||||
|
} while (0UL != __STREXH((val), (addr)))
|
||||||
|
|
||||||
|
#define _SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, val, ops) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
(val) = __LDREXW(addr); \
|
||||||
|
(ops); \
|
||||||
|
} while (0UL != __STREXW((val), (addr)))
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalAdd1Byte(volatile uint8_t *addr, uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val += val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalAdd2Byte(volatile uint16_t *addr, uint16_t val)
|
||||||
|
{
|
||||||
|
uint16_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val += val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalAdd4Byte(volatile uint32_t *addr, uint32_t val)
|
||||||
|
{
|
||||||
|
uint32_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val += val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalSub1Byte(volatile uint8_t *addr, uint8_t val)
|
||||||
|
{
|
||||||
|
uint8_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val -= val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalSub2Byte(volatile uint16_t *addr, uint16_t val)
|
||||||
|
{
|
||||||
|
uint16_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val -= val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalSub4Byte(volatile uint32_t *addr, uint32_t val)
|
||||||
|
{
|
||||||
|
uint32_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val -= val);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalSet1Byte(volatile uint8_t *addr, uint8_t bits)
|
||||||
|
{
|
||||||
|
uint8_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val |= bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalSet2Byte(volatile uint16_t *addr, uint16_t bits)
|
||||||
|
{
|
||||||
|
uint16_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val |= bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalSet4Byte(volatile uint32_t *addr, uint32_t bits)
|
||||||
|
{
|
||||||
|
uint32_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val |= bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalClear1Byte(volatile uint8_t *addr, uint8_t bits)
|
||||||
|
{
|
||||||
|
uint8_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val &= ~bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalClear2Byte(volatile uint16_t *addr, uint16_t bits)
|
||||||
|
{
|
||||||
|
uint16_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val &= ~bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalClear4Byte(volatile uint32_t *addr, uint32_t bits)
|
||||||
|
{
|
||||||
|
uint32_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val &= ~bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalToggle1Byte(volatile uint8_t *addr, uint8_t bits)
|
||||||
|
{
|
||||||
|
uint8_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val ^= bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalToggle2Byte(volatile uint16_t *addr, uint16_t bits)
|
||||||
|
{
|
||||||
|
uint16_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val ^= bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalToggle4Byte(volatile uint32_t *addr, uint32_t bits)
|
||||||
|
{
|
||||||
|
uint32_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val ^= bits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalClearAndSet1Byte(volatile uint8_t *addr, uint8_t clearBits, uint8_t setBits)
|
||||||
|
{
|
||||||
|
uint8_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_1BYTE(addr, s_val, s_val = (s_val & ~clearBits) | setBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalClearAndSet2Byte(volatile uint16_t *addr, uint16_t clearBits, uint16_t setBits)
|
||||||
|
{
|
||||||
|
uint16_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_2BYTE(addr, s_val, s_val = (s_val & ~clearBits) | setBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void _SDK_AtomicLocalClearAndSet4Byte(volatile uint32_t *addr, uint32_t clearBits, uint32_t setBits)
|
||||||
|
{
|
||||||
|
uint32_t s_val;
|
||||||
|
|
||||||
|
_SDK_ATOMIC_LOCAL_OPS_4BYTE(addr, s_val, s_val = (s_val & ~clearBits) | setBits);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_ADD(addr, val) \
|
||||||
|
((1UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalAdd1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(val)) : \
|
||||||
|
((2UL == sizeof(*(addr))) ? _SDK_AtomicLocalAdd2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(val)) : \
|
||||||
|
_SDK_AtomicLocalAdd4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(val))))
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_SUB(addr, val) \
|
||||||
|
((1UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalSub1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(val)) : \
|
||||||
|
((2UL == sizeof(*(addr))) ? _SDK_AtomicLocalSub2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(val)) : \
|
||||||
|
_SDK_AtomicLocalSub4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(val))))
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_SET(addr, bits) \
|
||||||
|
((1UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalSet1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(bits)) : \
|
||||||
|
((2UL == sizeof(*(addr))) ? _SDK_AtomicLocalSet2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(bits)) : \
|
||||||
|
_SDK_AtomicLocalSet4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(bits))))
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_CLEAR(addr, bits) \
|
||||||
|
((1UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalClear1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(bits)) : \
|
||||||
|
((2UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalClear2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(bits)) : \
|
||||||
|
_SDK_AtomicLocalClear4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(bits))))
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_TOGGLE(addr, bits) \
|
||||||
|
((1UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalToggle1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(bits)) : \
|
||||||
|
((2UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalToggle2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(bits)) : \
|
||||||
|
_SDK_AtomicLocalToggle4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(bits))))
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_CLEAR_AND_SET(addr, clearBits, setBits) \
|
||||||
|
((1UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalClearAndSet1Byte((volatile uint8_t *)(volatile void *)(addr), (uint8_t)(clearBits), (uint8_t)(setBits)) : \
|
||||||
|
((2UL == sizeof(*(addr))) ? \
|
||||||
|
_SDK_AtomicLocalClearAndSet2Byte((volatile uint16_t *)(volatile void *)(addr), (uint16_t)(clearBits), (uint16_t)(setBits)) : \
|
||||||
|
_SDK_AtomicLocalClearAndSet4Byte((volatile uint32_t *)(volatile void *)(addr), (uint32_t)(clearBits), (uint32_t)(setBits))))
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_ADD(addr, val) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
uint32_t s_atomicOldInt; \
|
||||||
|
s_atomicOldInt = DisableGlobalIRQ(); \
|
||||||
|
*(addr) += (val); \
|
||||||
|
EnableGlobalIRQ(s_atomicOldInt); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_SUB(addr, val) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
uint32_t s_atomicOldInt; \
|
||||||
|
s_atomicOldInt = DisableGlobalIRQ(); \
|
||||||
|
*(addr) -= (val); \
|
||||||
|
EnableGlobalIRQ(s_atomicOldInt); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_SET(addr, bits) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
uint32_t s_atomicOldInt; \
|
||||||
|
s_atomicOldInt = DisableGlobalIRQ(); \
|
||||||
|
*(addr) |= (bits); \
|
||||||
|
EnableGlobalIRQ(s_atomicOldInt); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_CLEAR(addr, bits) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
uint32_t s_atomicOldInt; \
|
||||||
|
s_atomicOldInt = DisableGlobalIRQ(); \
|
||||||
|
*(addr) &= ~(bits); \
|
||||||
|
EnableGlobalIRQ(s_atomicOldInt); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_TOGGLE(addr, bits) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
uint32_t s_atomicOldInt; \
|
||||||
|
s_atomicOldInt = DisableGlobalIRQ(); \
|
||||||
|
*(addr) ^= (bits); \
|
||||||
|
EnableGlobalIRQ(s_atomicOldInt); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#define SDK_ATOMIC_LOCAL_CLEAR_AND_SET(addr, clearBits, setBits) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
uint32_t s_atomicOldInt; \
|
||||||
|
s_atomicOldInt = DisableGlobalIRQ(); \
|
||||||
|
*(addr) = (*(addr) & ~(clearBits)) | (setBits); \
|
||||||
|
EnableGlobalIRQ(s_atomicOldInt); \
|
||||||
|
} while (false)
|
||||||
|
|
||||||
|
#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 ISR exit barrier
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
|
||||||
|
* exception return operation might vector to incorrect interrupt.
|
||||||
|
* For Cortex-M7, if core speed much faster than peripheral register write speed,
|
||||||
|
* the peripheral interrupt flags may be still set after exiting ISR, this results to
|
||||||
|
* the same error similar with errata 83869.
|
||||||
|
*/
|
||||||
|
#if (defined __CORTEX_M) && ((__CORTEX_M == 4U) || (__CORTEX_M == 7U))
|
||||||
|
#define SDK_ISR_EXIT_BARRIER __DSB()
|
||||||
|
#else
|
||||||
|
#define SDK_ISR_EXIT_BARRIER
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*! @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
|
||||||
|
#elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
|
||||||
|
/*! Macro to define a variable with alignbytes alignment */
|
||||||
|
#define SDK_ALIGN(var, alignbytes) __attribute__((aligned(alignbytes))) var
|
||||||
|
#elif defined(__GNUC__) || defined(DOXYGEN_OUTPUT)
|
||||||
|
/*! Macro to define a variable with alignbytes alignment */
|
||||||
|
#define SDK_ALIGN(var, alignbytes) var __attribute__((aligned(alignbytes)))
|
||||||
|
#else
|
||||||
|
#error Toolchain not supported
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! 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_ALIGN(var, 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) SDK_ALIGN(var, FSL_FEATURE_L2CACHE_LINESIZE_BYTE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! Macro to change a value to a given size aligned value */
|
||||||
|
#define SDK_SIZEALIGN(var, alignbytes) \
|
||||||
|
((unsigned int)((var) + ((alignbytes)-1U)) & (unsigned int)(~(unsigned int)((alignbytes)-1U)))
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Non-cacheable region definition macros
|
||||||
|
*
|
||||||
|
* For initialized non-zero non-cacheable variables, please use "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 use "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.
|
||||||
|
*
|
||||||
|
* @note 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.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def AT_NONCACHEABLE_SECTION(var)
|
||||||
|
* Define a variable \a var, and place it in non-cacheable section.
|
||||||
|
*
|
||||||
|
* @def AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes)
|
||||||
|
* Define a variable \a var, and place it in non-cacheable section, the start address
|
||||||
|
* of the variable is aligned to \a alignbytes.
|
||||||
|
*
|
||||||
|
* @def AT_NONCACHEABLE_SECTION_INIT(var)
|
||||||
|
* Define a variable \a var with initial value, and place it in non-cacheable section.
|
||||||
|
*
|
||||||
|
* @def AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes)
|
||||||
|
* Define a variable \a var with initial value, and place it in non-cacheable section,
|
||||||
|
* the start address of the variable is aligned to \a alignbytes.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if ((!(defined(FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION) && FSL_FEATURE_HAS_NO_NONCACHEABLE_SECTION)) && \
|
||||||
|
defined(FSL_FEATURE_L1ICACHE_LINESIZE_BYTE))
|
||||||
|
|
||||||
|
#if (defined(__ICCARM__))
|
||||||
|
#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"
|
||||||
|
|
||||||
|
#elif (defined(__CC_ARM) || defined(__ARMCC_VERSION))
|
||||||
|
#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
|
||||||
|
#if (defined(__CC_ARM))
|
||||||
|
#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
|
||||||
|
#else
|
||||||
|
#define AT_NONCACHEABLE_SECTION(var) __attribute__((section(".bss.NonCacheable"))) var
|
||||||
|
#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) \
|
||||||
|
__attribute__((section(".bss.NonCacheable"))) __attribute__((aligned(alignbytes))) var
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#elif (defined(__GNUC__)) || defined(DOXYGEN_OUTPUT)
|
||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
#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
|
||||||
|
#error Toolchain not supported.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define AT_NONCACHEABLE_SECTION(var) var
|
||||||
|
#define AT_NONCACHEABLE_SECTION_ALIGN(var, alignbytes) SDK_ALIGN(var, alignbytes)
|
||||||
|
#define AT_NONCACHEABLE_SECTION_INIT(var) var
|
||||||
|
#define AT_NONCACHEABLE_SECTION_ALIGN_INIT(var, alignbytes) SDK_ALIGN(var, alignbytes)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Time sensitive region
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @def AT_QUICKACCESS_SECTION_CODE(func)
|
||||||
|
* Place function in a section which can be accessed quickly by core.
|
||||||
|
*
|
||||||
|
* @def AT_QUICKACCESS_SECTION_DATA(var)
|
||||||
|
* Place data in a section which can be accessed quickly by core.
|
||||||
|
*
|
||||||
|
* @def AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes)
|
||||||
|
* Place data in a section which can be accessed quickly by core, and the variable
|
||||||
|
* address is set to align with \a alignbytes.
|
||||||
|
*/
|
||||||
|
#if (defined(__ICCARM__))
|
||||||
|
#define AT_QUICKACCESS_SECTION_CODE(func) func @"CodeQuickAccess"
|
||||||
|
#define AT_QUICKACCESS_SECTION_DATA(var) var @"DataQuickAccess"
|
||||||
|
#define AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes) \
|
||||||
|
SDK_PRAGMA(data_alignment = alignbytes) var @"DataQuickAccess"
|
||||||
|
#elif (defined(__CC_ARM) || defined(__ARMCC_VERSION))
|
||||||
|
#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
|
||||||
|
#define AT_QUICKACCESS_SECTION_DATA(var) __attribute__((section("DataQuickAccess"))) var
|
||||||
|
#define AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes) \
|
||||||
|
__attribute__((section("DataQuickAccess"))) __attribute__((aligned(alignbytes))) var
|
||||||
|
#elif (defined(__GNUC__)) || defined(DOXYGEN_OUTPUT)
|
||||||
|
#define AT_QUICKACCESS_SECTION_CODE(func) __attribute__((section("CodeQuickAccess"), __noinline__)) func
|
||||||
|
#define AT_QUICKACCESS_SECTION_DATA(var) __attribute__((section("DataQuickAccess"))) var
|
||||||
|
#define AT_QUICKACCESS_SECTION_DATA_ALIGN(var, alignbytes) \
|
||||||
|
__attribute__((section("DataQuickAccess"))) var __attribute__((aligned(alignbytes)))
|
||||||
|
#else
|
||||||
|
#error Toolchain not supported.
|
||||||
|
#endif /* defined(__ICCARM__) */
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Ram Function
|
||||||
|
* @{
|
||||||
|
*
|
||||||
|
* @def RAMFUNCTION_SECTION_CODE(func)
|
||||||
|
* Place function in ram.
|
||||||
|
*/
|
||||||
|
#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__)) || defined(DOXYGEN_OUTPUT)
|
||||||
|
#define RAMFUNCTION_SECTION_CODE(func) __attribute__((section("RamFunction"))) func
|
||||||
|
#else
|
||||||
|
#error Toolchain not supported.
|
||||||
|
#endif /* defined(__ICCARM__) */
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
|
||||||
|
void DefaultISR(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 /* __cplusplus*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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)
|
||||||
|
{
|
||||||
|
status_t status = kStatus_Success;
|
||||||
|
|
||||||
|
if (NotAvail_IRQn == interrupt)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
|
||||||
|
else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(__GIC_PRIO_BITS)
|
||||||
|
GIC_EnableIRQ(interrupt);
|
||||||
|
#else
|
||||||
|
NVIC_EnableIRQ(interrupt);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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)
|
||||||
|
{
|
||||||
|
status_t status = kStatus_Success;
|
||||||
|
|
||||||
|
if (NotAvail_IRQn == interrupt)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
|
||||||
|
else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(__GIC_PRIO_BITS)
|
||||||
|
GIC_DisableIRQ(interrupt);
|
||||||
|
#else
|
||||||
|
NVIC_DisableIRQ(interrupt);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable the IRQ, and also set the interrupt priority.
|
||||||
|
*
|
||||||
|
* Only handle 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 handles 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 to Enable.
|
||||||
|
* @param priNum Priority number set to interrupt controller register.
|
||||||
|
* @retval kStatus_Success Interrupt priority set successfully
|
||||||
|
* @retval kStatus_Fail Failed to set the interrupt priority.
|
||||||
|
*/
|
||||||
|
static inline status_t EnableIRQWithPriority(IRQn_Type interrupt, uint8_t priNum)
|
||||||
|
{
|
||||||
|
status_t status = kStatus_Success;
|
||||||
|
|
||||||
|
if (NotAvail_IRQn == interrupt)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
|
||||||
|
else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(__GIC_PRIO_BITS)
|
||||||
|
GIC_SetPriority(interrupt, priNum);
|
||||||
|
GIC_EnableIRQ(interrupt);
|
||||||
|
#else
|
||||||
|
NVIC_SetPriority(interrupt, priNum);
|
||||||
|
NVIC_EnableIRQ(interrupt);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set the IRQ priority.
|
||||||
|
*
|
||||||
|
* Only handle 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 handles 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 to set.
|
||||||
|
* @param priNum Priority number set to interrupt controller register.
|
||||||
|
*
|
||||||
|
* @retval kStatus_Success Interrupt priority set successfully
|
||||||
|
* @retval kStatus_Fail Failed to set the interrupt priority.
|
||||||
|
*/
|
||||||
|
static inline status_t IRQ_SetPriority(IRQn_Type interrupt, uint8_t priNum)
|
||||||
|
{
|
||||||
|
status_t status = kStatus_Success;
|
||||||
|
|
||||||
|
if (NotAvail_IRQn == interrupt)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
|
||||||
|
else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(__GIC_PRIO_BITS)
|
||||||
|
GIC_SetPriority(interrupt, priNum);
|
||||||
|
#else
|
||||||
|
NVIC_SetPriority(interrupt, priNum);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Clear the pending IRQ flag.
|
||||||
|
*
|
||||||
|
* Only handle 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 handles the LEVEL1 interrupts. The number of LEVEL1 interrupts
|
||||||
|
* is indicated by the feature macro FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS.
|
||||||
|
*
|
||||||
|
* @param interrupt The flag which IRQ to clear.
|
||||||
|
*
|
||||||
|
* @retval kStatus_Success Interrupt priority set successfully
|
||||||
|
* @retval kStatus_Fail Failed to set the interrupt priority.
|
||||||
|
*/
|
||||||
|
static inline status_t IRQ_ClearPendingIRQ(IRQn_Type interrupt)
|
||||||
|
{
|
||||||
|
status_t status = kStatus_Success;
|
||||||
|
|
||||||
|
if (NotAvail_IRQn == interrupt)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS) && (FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS > 0)
|
||||||
|
else if ((int32_t)interrupt >= (int32_t)FSL_FEATURE_NUMBER_OF_LEVEL1_INT_VECTORS)
|
||||||
|
{
|
||||||
|
status = kStatus_Fail;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if defined(__GIC_PRIO_BITS)
|
||||||
|
GIC_ClearPendingIRQ(interrupt);
|
||||||
|
#else
|
||||||
|
NVIC_ClearPendingIRQ(interrupt);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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)
|
||||||
|
{
|
||||||
|
uint32_t mask;
|
||||||
|
|
||||||
|
#if defined(CPSR_I_Msk)
|
||||||
|
mask = __get_CPSR() & CPSR_I_Msk;
|
||||||
|
#elif defined(DAIF_I_BIT)
|
||||||
|
mask = __get_DAIF() & DAIF_I_BIT;
|
||||||
|
#else
|
||||||
|
mask = __get_PRIMASK();
|
||||||
|
#endif
|
||||||
|
__disable_irq();
|
||||||
|
|
||||||
|
return mask;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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(CPSR_I_Msk)
|
||||||
|
__set_CPSR((__get_CPSR() & ~CPSR_I_Msk) | primask);
|
||||||
|
#elif defined(DAIF_I_BIT)
|
||||||
|
if (0UL == primask)
|
||||||
|
{
|
||||||
|
__enable_irq();
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
__set_PRIMASK(primask);
|
||||||
|
#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))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When FSL_FEATURE_POWERLIB_EXTEND is defined to non-zero value,
|
||||||
|
* powerlib should be used instead of these functions.
|
||||||
|
*/
|
||||||
|
#if !(defined(FSL_FEATURE_POWERLIB_EXTEND) && (FSL_FEATURE_POWERLIB_EXTEND != 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_POWERLIB_EXTEND */
|
||||||
|
#endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
|
||||||
|
|
||||||
|
#if defined(DWT)
|
||||||
|
/*!
|
||||||
|
* @brief Enable the counter to get CPU cycles.
|
||||||
|
*/
|
||||||
|
void MSDK_EnableCpuCycleCounter(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get the current CPU cycle count.
|
||||||
|
*
|
||||||
|
* @return Current CPU cycle count.
|
||||||
|
*/
|
||||||
|
uint32_t MSDK_GetCpuCycleCount(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus*/
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif /* FSL_COMMON_ARM_H_ */
|
||||||
219
drivers/Inc/fsl_component_generic_list.h
Normal file
219
drivers/Inc/fsl_component_generic_list.h
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-2020, 2022 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GENERIC_LIST_H_
|
||||||
|
#define _GENERIC_LIST_H_
|
||||||
|
|
||||||
|
#ifndef SDK_COMPONENT_DEPENDENCY_FSL_COMMON
|
||||||
|
#define SDK_COMPONENT_DEPENDENCY_FSL_COMMON (1U)
|
||||||
|
#endif
|
||||||
|
#if (defined(SDK_COMPONENT_DEPENDENCY_FSL_COMMON) && (SDK_COMPONENT_DEPENDENCY_FSL_COMMON > 0U))
|
||||||
|
#include "fsl_common.h"
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
/*!
|
||||||
|
* @addtogroup GenericList
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**********************************************************************************
|
||||||
|
* Include
|
||||||
|
***********************************************************************************/
|
||||||
|
|
||||||
|
/**********************************************************************************
|
||||||
|
* Public macro definitions
|
||||||
|
***********************************************************************************/
|
||||||
|
/*! @brief Definition to determine whether use list light. */
|
||||||
|
#ifndef GENERIC_LIST_LIGHT
|
||||||
|
#define GENERIC_LIST_LIGHT (1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @brief Definition to determine whether enable list duplicated checking. */
|
||||||
|
#ifndef GENERIC_LIST_DUPLICATED_CHECKING
|
||||||
|
#define GENERIC_LIST_DUPLICATED_CHECKING (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**********************************************************************************
|
||||||
|
* Public type definitions
|
||||||
|
***********************************************************************************/
|
||||||
|
/*! @brief The list status */
|
||||||
|
#if (defined(SDK_COMPONENT_DEPENDENCY_FSL_COMMON) && (SDK_COMPONENT_DEPENDENCY_FSL_COMMON > 0U))
|
||||||
|
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 */
|
||||||
|
kLIST_NotSupport = MAKE_STATUS(kStatusGroup_LIST, 5), /*!< Not Support */
|
||||||
|
} list_status_t;
|
||||||
|
#else
|
||||||
|
typedef enum _list_status
|
||||||
|
{
|
||||||
|
kLIST_Ok = 0, /*!< Success */
|
||||||
|
kLIST_DuplicateError = 1, /*!< Duplicate Error */
|
||||||
|
kLIST_Full = 2, /*!< FULL */
|
||||||
|
kLIST_Empty = 3, /*!< Empty */
|
||||||
|
kLIST_OrphanElement = 4, /*!< Orphan Element */
|
||||||
|
kLIST_NotSupport = 5, /*!< Not Support */
|
||||||
|
} list_status_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @brief The list structure*/
|
||||||
|
typedef struct list_label
|
||||||
|
{
|
||||||
|
struct list_element_tag *head; /*!< list head */
|
||||||
|
struct list_element_tag *tail; /*!< list tail */
|
||||||
|
uint32_t size; /*!< list size */
|
||||||
|
uint32_t max; /*!< list max number of elements */
|
||||||
|
} list_label_t, *list_handle_t;
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
/*! @brief The list element*/
|
||||||
|
typedef struct list_element_tag
|
||||||
|
{
|
||||||
|
struct list_element_tag *next; /*!< next list element */
|
||||||
|
struct list_label *list; /*!< pointer to the list */
|
||||||
|
} list_element_t, *list_element_handle_t;
|
||||||
|
#else
|
||||||
|
/*! @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;
|
||||||
|
#endif
|
||||||
|
/**********************************************************************************
|
||||||
|
* 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 listElement - 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 listElement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Links element to the head of the list.
|
||||||
|
*
|
||||||
|
* @param list - Handle of the list.
|
||||||
|
* @param listElement - 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 listElement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Links element to the tail of the list.
|
||||||
|
*
|
||||||
|
* @param list - Handle of the list.
|
||||||
|
* @param listElement - 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 listElement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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 listElement - 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 listElement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets previous element handle for given element handle.
|
||||||
|
*
|
||||||
|
* @param listElement - 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 listElement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Unlinks an element from its list.
|
||||||
|
*
|
||||||
|
* @param listElement - 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 listElement);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Links an element in the previous position relative to a given member of a list.
|
||||||
|
*
|
||||||
|
* @param listElement - 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 listElement, 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_*/
|
||||||
295
drivers/Inc/fsl_debug_console.h
Normal file
295
drivers/Inc/fsl_debug_console.h
Normal file
@ -0,0 +1,295 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017-2018, 2020, 2022 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*
|
||||||
|
* Debug console shall provide input and output functions to scan and print formatted data.
|
||||||
|
* o Support a format specifier for PRINTF follows this prototype "%[flags][width][.precision][length]specifier"
|
||||||
|
* - [flags] :'-', '+', '#', ' ', '0'
|
||||||
|
* - [width]: number (0,1...)
|
||||||
|
* - [.precision]: number (0,1...)
|
||||||
|
* - [length]: do not support
|
||||||
|
* - [specifier]: 'd', 'i', 'f', 'F', 'x', 'X', 'o', 'p', 'u', 'c', 's', 'n'
|
||||||
|
* o Support a format specifier for SCANF follows this prototype " %[*][width][length]specifier"
|
||||||
|
* - [*]: is supported.
|
||||||
|
* - [width]: number (0,1...)
|
||||||
|
* - [length]: 'h', 'hh', 'l','ll','L'. ignore ('j','z','t')
|
||||||
|
* - [specifier]: 'd', 'i', 'u', 'f', 'F', 'e', 'E', 'g', 'G', 'a', 'A', 'o', 'c', 's'
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FSL_DEBUGCONSOLE_H_
|
||||||
|
#define _FSL_DEBUGCONSOLE_H_
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup debugconsolelite
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @brief Definition select redirect toolchain printf, scanf to uart or not. */
|
||||||
|
#define DEBUGCONSOLE_REDIRECT_TO_TOOLCHAIN 0U /*!< Select toolchain printf and scanf. */
|
||||||
|
#define DEBUGCONSOLE_REDIRECT_TO_SDK 1U /*!< Select SDK version printf, scanf. */
|
||||||
|
#define DEBUGCONSOLE_DISABLE 2U /*!< Disable debugconsole function. */
|
||||||
|
|
||||||
|
/*! @brief Definition to select sdk or toolchain printf, scanf. */
|
||||||
|
#ifndef SDK_DEBUGCONSOLE
|
||||||
|
#define SDK_DEBUGCONSOLE DEBUGCONSOLE_REDIRECT_TO_SDK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SDK_DEBUGCONSOLE) && !(SDK_DEBUGCONSOLE)
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#include <stdarg.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @brief Definition to printf the float number. */
|
||||||
|
#ifndef PRINTF_FLOAT_ENABLE
|
||||||
|
#define PRINTF_FLOAT_ENABLE 0U
|
||||||
|
#endif /* PRINTF_FLOAT_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to scanf the float number. */
|
||||||
|
#ifndef SCANF_FLOAT_ENABLE
|
||||||
|
#define SCANF_FLOAT_ENABLE 0U
|
||||||
|
#endif /* SCANF_FLOAT_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to support advanced format specifier for printf. */
|
||||||
|
#ifndef PRINTF_ADVANCED_ENABLE
|
||||||
|
#define PRINTF_ADVANCED_ENABLE 0U
|
||||||
|
#endif /* PRINTF_ADVANCED_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to support advanced format specifier for scanf. */
|
||||||
|
#ifndef SCANF_ADVANCED_ENABLE
|
||||||
|
#define SCANF_ADVANCED_ENABLE 0U
|
||||||
|
#endif /* SCANF_ADVANCED_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to select redirect toolchain printf, scanf to uart or not.
|
||||||
|
*
|
||||||
|
* if SDK_DEBUGCONSOLE defined to 0,it represents select toolchain printf, scanf.
|
||||||
|
* if SDK_DEBUGCONSOLE defined to 1,it represents select SDK version printf, scanf.
|
||||||
|
* if SDK_DEBUGCONSOLE defined to 2,it represents disable debugconsole function.
|
||||||
|
*/
|
||||||
|
#if SDK_DEBUGCONSOLE == DEBUGCONSOLE_DISABLE /* Disable debug console */
|
||||||
|
static inline int DbgConsole_Disabled(void)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
#define PRINTF(...) DbgConsole_Disabled()
|
||||||
|
#define SCANF(...) DbgConsole_Disabled()
|
||||||
|
#define PUTCHAR(...) DbgConsole_Disabled()
|
||||||
|
#define GETCHAR() DbgConsole_Disabled()
|
||||||
|
#elif SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK /* Select printf, scanf, putchar, getchar of SDK version. */
|
||||||
|
#define PRINTF DbgConsole_Printf
|
||||||
|
#define SCANF DbgConsole_Scanf
|
||||||
|
#define PUTCHAR DbgConsole_Putchar
|
||||||
|
#define GETCHAR DbgConsole_Getchar
|
||||||
|
#elif SDK_DEBUGCONSOLE == \
|
||||||
|
DEBUGCONSOLE_REDIRECT_TO_TOOLCHAIN /* Select printf, scanf, putchar, getchar of toolchain. \ */
|
||||||
|
#define PRINTF printf
|
||||||
|
#define SCANF scanf
|
||||||
|
#define PUTCHAR putchar
|
||||||
|
#define GETCHAR getchar
|
||||||
|
#endif /* SDK_DEBUGCONSOLE */
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*! @brief serial port type
|
||||||
|
*
|
||||||
|
* The serial port type aligned with the definition in serial manager, but please note
|
||||||
|
* only kSerialPort_Uart can be supported in debug console lite.
|
||||||
|
*/
|
||||||
|
#ifndef _SERIAL_PORT_T_
|
||||||
|
#define _SERIAL_PORT_T_
|
||||||
|
typedef enum _serial_port_type
|
||||||
|
{
|
||||||
|
kSerialPort_None = 0U, /*!< Serial port is none */
|
||||||
|
kSerialPort_Uart = 1U, /*!< Serial port UART */
|
||||||
|
kSerialPort_UsbCdc, /*!< Serial port USB CDC */
|
||||||
|
kSerialPort_Swo, /*!< Serial port SWO */
|
||||||
|
kSerialPort_Virtual, /*!< Serial port Virtual */
|
||||||
|
kSerialPort_Rpmsg, /*!< Serial port RPMSG */
|
||||||
|
kSerialPort_UartDma, /*!< Serial port UART DMA*/
|
||||||
|
kSerialPort_SpiMaster, /*!< Serial port SPIMASTER*/
|
||||||
|
kSerialPort_SpiSlave, /*!< Serial port SPISLAVE*/
|
||||||
|
} serial_port_type_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup debugconsolelite
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*******************************************************************************
|
||||||
|
* Prototypes
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*! @name Initialization*/
|
||||||
|
/* @{ */
|
||||||
|
|
||||||
|
#if ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART))
|
||||||
|
/*!
|
||||||
|
* @brief Initializes the peripheral used for debug messages.
|
||||||
|
*
|
||||||
|
* Call this function to enable debug log messages to be output via the specified peripheral,
|
||||||
|
* frequency of peripheral source clock, and base address at the specified baud rate.
|
||||||
|
* After this function has returned, stdout and stdin are connected to the selected peripheral.
|
||||||
|
*
|
||||||
|
* @param instance The instance of the module.If the device is kSerialPort_Uart,
|
||||||
|
* the instance is UART peripheral instance. The UART hardware peripheral
|
||||||
|
* type is determined by UART adapter. For example, if the instance is 1,
|
||||||
|
* if the lpuart_adapter.c is added to the current project, the UART periheral
|
||||||
|
* is LPUART1.
|
||||||
|
* If the uart_adapter.c is added to the current project, the UART periheral
|
||||||
|
* is UART1.
|
||||||
|
* @param baudRate The desired baud rate in bits per second.
|
||||||
|
* @param device Low level device type for the debug console, can be one of the following.
|
||||||
|
* @arg kSerialPort_Uart.
|
||||||
|
* @param clkSrcFreq Frequency of peripheral source clock.
|
||||||
|
*
|
||||||
|
* @return Indicates whether initialization was successful or not.
|
||||||
|
* @retval kStatus_Success Execution successfully
|
||||||
|
* @retval kStatus_Fail Execution failure
|
||||||
|
*/
|
||||||
|
status_t DbgConsole_Init(uint8_t instance, uint32_t baudRate, serial_port_type_t device, uint32_t clkSrcFreq);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief De-initializes the peripheral used for debug messages.
|
||||||
|
*
|
||||||
|
* Call this function to disable debug log messages to be output via the specified peripheral
|
||||||
|
* base address and at the specified baud rate.
|
||||||
|
*
|
||||||
|
* @return Indicates whether de-initialization was successful or not.
|
||||||
|
*/
|
||||||
|
status_t DbgConsole_Deinit(void);
|
||||||
|
/*!
|
||||||
|
* @brief Prepares to enter low power consumption.
|
||||||
|
*
|
||||||
|
* This function is used to prepare to enter low power consumption.
|
||||||
|
*
|
||||||
|
* @return Indicates whether de-initialization was successful or not.
|
||||||
|
*/
|
||||||
|
status_t DbgConsole_EnterLowpower(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Restores from low power consumption.
|
||||||
|
*
|
||||||
|
* This function is used to restore from low power consumption.
|
||||||
|
*
|
||||||
|
* @return Indicates whether de-initialization was successful or not.
|
||||||
|
*/
|
||||||
|
status_t DbgConsole_ExitLowpower(void);
|
||||||
|
|
||||||
|
#else
|
||||||
|
/*!
|
||||||
|
* Use an error to replace the DbgConsole_Init when SDK_DEBUGCONSOLE is not DEBUGCONSOLE_REDIRECT_TO_SDK and
|
||||||
|
* SDK_DEBUGCONSOLE_UART is not defined.
|
||||||
|
*/
|
||||||
|
static inline status_t DbgConsole_Init(uint8_t instance,
|
||||||
|
uint32_t baudRate,
|
||||||
|
serial_port_type_t device,
|
||||||
|
uint32_t clkSrcFreq)
|
||||||
|
{
|
||||||
|
(void)instance;
|
||||||
|
(void)baudRate;
|
||||||
|
(void)device;
|
||||||
|
(void)clkSrcFreq;
|
||||||
|
return (status_t)kStatus_Fail;
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
* Use an error to replace the DbgConsole_Deinit when SDK_DEBUGCONSOLE is not DEBUGCONSOLE_REDIRECT_TO_SDK and
|
||||||
|
* SDK_DEBUGCONSOLE_UART is not defined.
|
||||||
|
*/
|
||||||
|
static inline status_t DbgConsole_Deinit(void)
|
||||||
|
{
|
||||||
|
return (status_t)kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Use an error to replace the DbgConsole_EnterLowpower when SDK_DEBUGCONSOLE is not DEBUGCONSOLE_REDIRECT_TO_SDK and
|
||||||
|
* SDK_DEBUGCONSOLE_UART is not defined.
|
||||||
|
*/
|
||||||
|
static inline status_t DbgConsole_EnterLowpower(void)
|
||||||
|
{
|
||||||
|
return (status_t)kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Use an error to replace the DbgConsole_ExitLowpower when SDK_DEBUGCONSOLE is not DEBUGCONSOLE_REDIRECT_TO_SDK and
|
||||||
|
* SDK_DEBUGCONSOLE_UART is not defined.
|
||||||
|
*/
|
||||||
|
static inline status_t DbgConsole_ExitLowpower(void)
|
||||||
|
{
|
||||||
|
return (status_t)kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* ((SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK) || defined(SDK_DEBUGCONSOLE_UART)) */
|
||||||
|
|
||||||
|
#if (defined(SDK_DEBUGCONSOLE) && (SDK_DEBUGCONSOLE == DEBUGCONSOLE_REDIRECT_TO_SDK))
|
||||||
|
/*!
|
||||||
|
* @brief Writes formatted output to the standard output stream.
|
||||||
|
*
|
||||||
|
* Call this function to write a formatted output to the standard output stream.
|
||||||
|
*
|
||||||
|
* @param fmt_s Format control string.
|
||||||
|
* @return Returns the number of characters printed or a negative value if an error occurs.
|
||||||
|
*/
|
||||||
|
int DbgConsole_Printf(const char *fmt_s, ...);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Writes formatted output to the standard output stream.
|
||||||
|
*
|
||||||
|
* Call this function to write a formatted output to the standard output stream.
|
||||||
|
*
|
||||||
|
* @param fmt_s Format control string.
|
||||||
|
* @param formatStringArg Format arguments.
|
||||||
|
* @return Returns the number of characters printed or a negative value if an error occurs.
|
||||||
|
*/
|
||||||
|
int DbgConsole_Vprintf(const char *fmt_s, va_list formatStringArg);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Writes a character to stdout.
|
||||||
|
*
|
||||||
|
* Call this function to write a character to stdout.
|
||||||
|
*
|
||||||
|
* @param dbgConsoleCh Character to be written.
|
||||||
|
* @return Returns the character written.
|
||||||
|
*/
|
||||||
|
int DbgConsole_Putchar(int dbgConsoleCh);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Reads formatted data from the standard input stream.
|
||||||
|
*
|
||||||
|
* Call this function to read formatted data from the standard input stream.
|
||||||
|
*
|
||||||
|
* @param fmt_s Format control string.
|
||||||
|
* @return Returns the number of fields successfully converted and assigned.
|
||||||
|
*/
|
||||||
|
int DbgConsole_Scanf(char *fmt_s, ...);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Reads a character from standard input.
|
||||||
|
*
|
||||||
|
* Call this function to read a character from standard input.
|
||||||
|
*
|
||||||
|
* @return Returns the character read.
|
||||||
|
*/
|
||||||
|
int DbgConsole_Getchar(void);
|
||||||
|
|
||||||
|
#endif /* SDK_DEBUGCONSOLE */
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
#endif /* _FSL_DEBUGCONSOLE_H_ */
|
||||||
64
drivers/Inc/fsl_flexcomm.h
Normal file
64
drivers/Inc/fsl_flexcomm.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 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 *flexcommHandle);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif /* FSL_FLEXCOMM_H_*/
|
||||||
611
drivers/Inc/fsl_power.h
Normal file
611
drivers/Inc/fsl_power.h
Normal file
@ -0,0 +1,611 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017, NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
#ifndef _FSL_POWER_H_
|
||||||
|
#define _FSL_POWER_H_
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
#include "fsl_device_registers.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup power
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @name Driver version */
|
||||||
|
/*@{*/
|
||||||
|
/*! @brief power driver version 2.0.1. */
|
||||||
|
#define FSL_POWER_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
|
/* Power mode configuration API parameter */
|
||||||
|
typedef enum _power_mode_config
|
||||||
|
{
|
||||||
|
kPmu_Sleep = 0U,
|
||||||
|
kPmu_Deep_Sleep = 1U,
|
||||||
|
kPmu_PowerDown = 2U,
|
||||||
|
kPmu_Deep_PowerDown = 3U,
|
||||||
|
} power_mode_cfg_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Analog components power modes control during low power modes
|
||||||
|
*/
|
||||||
|
typedef enum pd_bits
|
||||||
|
{
|
||||||
|
kPDRUNCFG_PD_DCDC = (1UL << 0),
|
||||||
|
kPDRUNCFG_PD_BIAS = (1UL << 1),
|
||||||
|
kPDRUNCFG_PD_BODCORE = (1UL << 2),
|
||||||
|
kPDRUNCFG_PD_BODVBAT = (1UL << 3),
|
||||||
|
kPDRUNCFG_PD_FRO1M = (1UL << 4),
|
||||||
|
kPDRUNCFG_PD_FRO192M = (1UL << 5),
|
||||||
|
kPDRUNCFG_PD_FRO32K = (1UL << 6),
|
||||||
|
kPDRUNCFG_PD_XTAL32K = (1UL << 7),
|
||||||
|
kPDRUNCFG_PD_XTAL32M = (1UL << 8),
|
||||||
|
kPDRUNCFG_PD_PLL0 = (1UL << 9),
|
||||||
|
kPDRUNCFG_PD_PLL1 = (1UL << 10),
|
||||||
|
kPDRUNCFG_PD_USB0_PHY = (1UL << 11),
|
||||||
|
kPDRUNCFG_PD_USB1_PHY = (1UL << 12),
|
||||||
|
kPDRUNCFG_PD_COMP = (1UL << 13),
|
||||||
|
kPDRUNCFG_PD_TEMPSENS = (1UL << 14),
|
||||||
|
kPDRUNCFG_PD_GPADC = (1UL << 15),
|
||||||
|
kPDRUNCFG_PD_LDOMEM = (1UL << 16),
|
||||||
|
kPDRUNCFG_PD_LDODEEPSLEEP = (1UL << 17),
|
||||||
|
kPDRUNCFG_PD_LDOUSBHS = (1UL << 18),
|
||||||
|
kPDRUNCFG_PD_LDOGPADC = (1UL << 19),
|
||||||
|
kPDRUNCFG_PD_LDOXO32M = (1UL << 20),
|
||||||
|
kPDRUNCFG_PD_LDOFLASHNV = (1UL << 21),
|
||||||
|
kPDRUNCFG_PD_RNG = (1UL << 22),
|
||||||
|
kPDRUNCFG_PD_PLL0_SSCG = (1UL << 23),
|
||||||
|
kPDRUNCFG_PD_ROM = (1UL << 24),
|
||||||
|
/*
|
||||||
|
This enum member has no practical meaning,it is used to avoid MISRA issue,
|
||||||
|
user should not trying to use it.
|
||||||
|
*/
|
||||||
|
kPDRUNCFG_ForceUnsigned = 0x80000000U,
|
||||||
|
} pd_bit_t;
|
||||||
|
|
||||||
|
/*! @brief BOD VBAT level */
|
||||||
|
typedef enum _power_bod_vbat_level
|
||||||
|
{
|
||||||
|
kPOWER_BodVbatLevel1000mv = 0, /*!< Brown out detector VBAT level 1V */
|
||||||
|
kPOWER_BodVbatLevel1100mv = 1, /*!< Brown out detector VBAT level 1.1V */
|
||||||
|
kPOWER_BodVbatLevel1200mv = 2, /*!< Brown out detector VBAT level 1.2V */
|
||||||
|
kPOWER_BodVbatLevel1300mv = 3, /*!< Brown out detector VBAT level 1.3V */
|
||||||
|
kPOWER_BodVbatLevel1400mv = 4, /*!< Brown out detector VBAT level 1.4V */
|
||||||
|
kPOWER_BodVbatLevel1500mv = 5, /*!< Brown out detector VBAT level 1.5V */
|
||||||
|
kPOWER_BodVbatLevel1600mv = 6, /*!< Brown out detector VBAT level 1.6V */
|
||||||
|
kPOWER_BodVbatLevel1650mv = 7, /*!< Brown out detector VBAT level 1.65V */
|
||||||
|
kPOWER_BodVbatLevel1700mv = 8, /*!< Brown out detector VBAT level 1.7V */
|
||||||
|
kPOWER_BodVbatLevel1750mv = 9, /*!< Brown out detector VBAT level 1.75V */
|
||||||
|
kPOWER_BodVbatLevel1800mv = 10, /*!< Brown out detector VBAT level 1.8V */
|
||||||
|
kPOWER_BodVbatLevel1900mv = 11, /*!< Brown out detector VBAT level 1.9V */
|
||||||
|
kPOWER_BodVbatLevel2000mv = 12, /*!< Brown out detector VBAT level 2V */
|
||||||
|
kPOWER_BodVbatLevel2100mv = 13, /*!< Brown out detector VBAT level 2.1V */
|
||||||
|
kPOWER_BodVbatLevel2200mv = 14, /*!< Brown out detector VBAT level 2.2V */
|
||||||
|
kPOWER_BodVbatLevel2300mv = 15, /*!< Brown out detector VBAT level 2.3V */
|
||||||
|
kPOWER_BodVbatLevel2400mv = 16, /*!< Brown out detector VBAT level 2.4V */
|
||||||
|
kPOWER_BodVbatLevel2500mv = 17, /*!< Brown out detector VBAT level 2.5V */
|
||||||
|
kPOWER_BodVbatLevel2600mv = 18, /*!< Brown out detector VBAT level 2.6V */
|
||||||
|
kPOWER_BodVbatLevel2700mv = 19, /*!< Brown out detector VBAT level 2.7V */
|
||||||
|
kPOWER_BodVbatLevel2806mv = 20, /*!< Brown out detector VBAT level 2.806V */
|
||||||
|
kPOWER_BodVbatLevel2900mv = 21, /*!< Brown out detector VBAT level 2.9V */
|
||||||
|
kPOWER_BodVbatLevel3000mv = 22, /*!< Brown out detector VBAT level 3.0V */
|
||||||
|
kPOWER_BodVbatLevel3100mv = 23, /*!< Brown out detector VBAT level 3.1V */
|
||||||
|
kPOWER_BodVbatLevel3200mv = 24, /*!< Brown out detector VBAT level 3.2V */
|
||||||
|
kPOWER_BodVbatLevel3300mv = 25, /*!< Brown out detector VBAT level 3.3V */
|
||||||
|
} power_bod_vbat_level_t;
|
||||||
|
|
||||||
|
/*! @brief BOD Hysteresis control */
|
||||||
|
typedef enum _power_bod_hyst
|
||||||
|
{
|
||||||
|
kPOWER_BodHystLevel25mv = 0U, /*!< BOD Hysteresis control level 25mv */
|
||||||
|
kPOWER_BodHystLevel50mv = 1U, /*!< BOD Hysteresis control level 50mv */
|
||||||
|
kPOWER_BodHystLevel75mv = 2U, /*!< BOD Hysteresis control level 75mv */
|
||||||
|
kPOWER_BodHystLevel100mv = 3U, /*!< BOD Hysteresis control level 100mv */
|
||||||
|
} power_bod_hyst_t;
|
||||||
|
|
||||||
|
/*! @brief BOD core level */
|
||||||
|
typedef enum _power_bod_core_level
|
||||||
|
{
|
||||||
|
kPOWER_BodCoreLevel600mv = 0, /*!< Brown out detector core level 600mV */
|
||||||
|
kPOWER_BodCoreLevel650mv = 1, /*!< Brown out detector core level 650mV */
|
||||||
|
kPOWER_BodCoreLevel700mv = 2, /*!< Brown out detector core level 700mV */
|
||||||
|
kPOWER_BodCoreLevel750mv = 3, /*!< Brown out detector core level 750mV */
|
||||||
|
kPOWER_BodCoreLevel800mv = 4, /*!< Brown out detector core level 800mV */
|
||||||
|
kPOWER_BodCoreLevel850mv = 5, /*!< Brown out detector core level 850mV */
|
||||||
|
kPOWER_BodCoreLevel900mv = 6, /*!< Brown out detector core level 900mV */
|
||||||
|
kPOWER_BodCoreLevel950mv = 7, /*!< Brown out detector core level 950mV */
|
||||||
|
} power_bod_core_level_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Device Reset Causes
|
||||||
|
*/
|
||||||
|
typedef enum _power_device_reset_cause
|
||||||
|
{
|
||||||
|
kRESET_CAUSE_POR = 0UL, /*!< Power On Reset */
|
||||||
|
kRESET_CAUSE_PADRESET = 1UL, /*!< Hardware Pin Reset */
|
||||||
|
kRESET_CAUSE_BODRESET = 2UL, /*!< Brown-out Detector reset (either BODVBAT or BODCORE) */
|
||||||
|
kRESET_CAUSE_ARMSYSTEMRESET = 3UL, /*!< ARM System Reset */
|
||||||
|
kRESET_CAUSE_WDTRESET = 4UL, /*!< Watchdog Timer Reset */
|
||||||
|
kRESET_CAUSE_SWRRESET = 5UL, /*!< Software Reset */
|
||||||
|
kRESET_CAUSE_CDOGRESET = 6UL, /*!< Code Watchdog Reset */
|
||||||
|
/* Reset causes in DEEP-POWER-DOWN low power mode */
|
||||||
|
kRESET_CAUSE_DPDRESET_WAKEUPIO = 7UL, /*!< Any of the 4 wake-up pins */
|
||||||
|
kRESET_CAUSE_DPDRESET_RTC = 8UL, /*!< Real Time Counter (RTC) */
|
||||||
|
kRESET_CAUSE_DPDRESET_OSTIMER = 9UL, /*!< OS Event Timer (OSTIMER) */
|
||||||
|
kRESET_CAUSE_DPDRESET_WAKEUPIO_RTC = 10UL, /*!< Any of the 4 wake-up pins and RTC (it is not possible to distinguish
|
||||||
|
which of these 2 events occured first) */
|
||||||
|
kRESET_CAUSE_DPDRESET_WAKEUPIO_OSTIMER = 11UL, /*!< Any of the 4 wake-up pins and OSTIMER (it is not possible to
|
||||||
|
distinguish which of these 2 events occured first) */
|
||||||
|
kRESET_CAUSE_DPDRESET_RTC_OSTIMER = 12UL, /*!< Real Time Counter or OS Event Timer (it is not possible to
|
||||||
|
distinguish which of these 2 events occured first) */
|
||||||
|
kRESET_CAUSE_DPDRESET_WAKEUPIO_RTC_OSTIMER = 13UL, /*!< Any of the 4 wake-up pins (it is not possible to distinguish
|
||||||
|
which of these 3 events occured first) */
|
||||||
|
/* Miscallenous */
|
||||||
|
kRESET_CAUSE_NOT_RELEVANT =
|
||||||
|
14UL, /*!< No reset cause (for example, this code is used when waking up from DEEP-SLEEP low power mode) */
|
||||||
|
kRESET_CAUSE_NOT_DETERMINISTIC = 15UL, /*!< Unknown Reset Cause. Should be treated like "Hardware Pin Reset" from an
|
||||||
|
application point of view. */
|
||||||
|
} power_device_reset_cause_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Device Boot Modes
|
||||||
|
*/
|
||||||
|
typedef enum _power_device_boot_mode
|
||||||
|
{
|
||||||
|
kBOOT_MODE_POWER_UP =
|
||||||
|
0UL, /*!< All non Low Power Mode wake up (Power On Reset, Pin Reset, BoD Reset, ARM System Reset ... ) */
|
||||||
|
kBOOT_MODE_LP_DEEP_SLEEP = 1UL, /*!< Wake up from DEEP-SLEEP Low Power mode */
|
||||||
|
kBOOT_MODE_LP_POWER_DOWN = 2UL, /*!< Wake up from POWER-DOWN Low Power mode */
|
||||||
|
kBOOT_MODE_LP_DEEP_POWER_DOWN = 4UL, /*!< Wake up from DEEP-POWER-DOWN Low Power mode */
|
||||||
|
} power_device_boot_mode_t;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief SRAM instances retention control during low power modes
|
||||||
|
*/
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAMX0 \
|
||||||
|
(1UL << 0) /*!< Enable SRAMX_0 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAMX1 \
|
||||||
|
(1UL << 1) /*!< Enable SRAMX_1 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAMX2 \
|
||||||
|
(1UL << 2) /*!< Enable SRAMX_2 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAMX3 \
|
||||||
|
(1UL << 3) /*!< Enable SRAMX_3 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM00 \
|
||||||
|
(1UL << 4) /*!< Enable SRAM0_0 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM01 \
|
||||||
|
(1UL << 5) /*!< Enable SRAM0_1 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM10 \
|
||||||
|
(1UL << 6) /*!< Enable SRAM1_0 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM20 \
|
||||||
|
(1UL << 7) /*!< Enable SRAM2_0 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM30 \
|
||||||
|
(1UL << 8) /*!< Enable SRAM3_0 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM31 \
|
||||||
|
(1UL << 9) /*!< Enable SRAM3_1 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM40 \
|
||||||
|
(1UL << 10) /*!< Enable SRAM4_0 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM41 \
|
||||||
|
(1UL << 11) /*!< Enable SRAM4_1 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM42 \
|
||||||
|
(1UL << 12) /*!< Enable SRAM4_2 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM43 \
|
||||||
|
(1UL << 13) /*!< Enable SRAM4_3 retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM_USB_HS \
|
||||||
|
(1UL << 14) /*!< Enable SRAM USB HS retention when entering in Low power modes */
|
||||||
|
#define LOWPOWER_SRAMRETCTRL_RETEN_RAM_PUF \
|
||||||
|
(1UL << 15) /*!< Enable SRAM PUFF retention when entering in Low power modes */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Low Power Modes Wake up sources
|
||||||
|
*/
|
||||||
|
#define WAKEUP_SYS (1ULL << 0) /*!< [SLEEP, DEEP SLEEP ] */ /* WWDT0_IRQ and BOD_IRQ*/
|
||||||
|
#define WAKEUP_SDMA0 (1ULL << 1) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_GLOBALINT0 (1ULL << 2) /*!< [SLEEP, DEEP SLEEP, POWER DOWN ] */
|
||||||
|
#define WAKEUP_GPIO_GLOBALINT1 (1ULL << 3) /*!< [SLEEP, DEEP SLEEP, POWER DOWN ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_0 (1ULL << 4) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_1 (1ULL << 5) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_2 (1ULL << 6) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_3 (1ULL << 7) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_UTICK (1ULL << 8) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_MRT (1ULL << 9) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_CTIMER0 (1ULL << 10) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_CTIMER1 (1ULL << 11) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_SCT (1ULL << 12) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_CTIMER3 (1ULL << 13) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM0 (1ULL << 14) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM1 (1ULL << 15) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM2 (1ULL << 16) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM3 (1ULL << 17) /*!< [SLEEP, DEEP SLEEP, POWER DOWN ] */
|
||||||
|
#define WAKEUP_FLEXCOMM4 (1ULL << 18) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM5 (1ULL << 19) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM6 (1ULL << 20) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_FLEXCOMM7 (1ULL << 21) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_ADC (1ULL << 22) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_ACMP_CAPT (1ULL << 24) /*!< [SLEEP, DEEP SLEEP, POWER DOWN ] */
|
||||||
|
// reserved (1ULL << 25)
|
||||||
|
// reserved (1ULL << 26)
|
||||||
|
#define WAKEUP_USB0_NEEDCLK (1ULL << 27) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_USB0 (1ULL << 28) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_RTC_LITE_ALARM_WAKEUP (1ULL << 29) /*!< [SLEEP, DEEP SLEEP, POWER DOWN, DEEP POWER DOWN] */
|
||||||
|
#define WAKEUP_EZH_ARCH_B (1ULL << 30) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_WAKEUP_MAILBOX (1ULL << 31) /*!< [SLEEP, DEEP SLEEP, POWER DOWN ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_4 (1ULL << 32) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_5 (1ULL << 33) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_6 (1ULL << 34) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_GPIO_INT0_7 (1ULL << 35) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_CTIMER2 (1ULL << 36) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_CTIMER4 (1ULL << 37) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_OS_EVENT_TIMER (1ULL << 38) /*!< [SLEEP, DEEP SLEEP, POWER DOWN, DEEP POWER DOWN] */
|
||||||
|
// reserved (1ULL << 39)
|
||||||
|
// reserved (1ULL << 40)
|
||||||
|
// reserved (1ULL << 41)
|
||||||
|
#define WAKEUP_SDIO (1ULL << 42) /*!< [SLEEP, ] */
|
||||||
|
// reserved (1ULL << 43)
|
||||||
|
// reserved (1ULL << 44)
|
||||||
|
// reserved (1ULL << 45)
|
||||||
|
// reserved (1ULL << 46)
|
||||||
|
#define WAKEUP_USB1 (1ULL << 47) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_USB1_NEEDCLK (1ULL << 48) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_SEC_HYPERVISOR_CALL (1ULL << 49) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_SEC_GPIO_INT0_0 (1ULL << 50) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_SEC_GPIO_INT0_1 (1ULL << 51) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_PLU (1ULL << 52) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_SEC_VIO (1ULL << 53)
|
||||||
|
#define WAKEUP_SHA (1ULL << 54) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_CASPER (1ULL << 55) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_PUFF (1ULL << 56) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_PQ (1ULL << 57) /*!< [SLEEP, ] */
|
||||||
|
#define WAKEUP_SDMA1 (1ULL << 58) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
#define WAKEUP_LSPI_HS (1ULL << 59) /*!< [SLEEP, DEEP SLEEP ] */
|
||||||
|
// reserved WAKEUP_PVTVF0_AMBER (1ULL << 60)
|
||||||
|
// reserved WAKEUP_PVTVF0_RED (1ULL << 61)
|
||||||
|
// reserved WAKEUP_PVTVF1_AMBER (1ULL << 62)
|
||||||
|
#define WAKEUP_ALLWAKEUPIOS (1ULL << 63) /*!< [ , DEEP POWER DOWN] */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sleep Postpone
|
||||||
|
*/
|
||||||
|
#define LOWPOWER_HWWAKE_FORCED (1UL << 0) /*!< Force peripheral clocking to stay on during deep-sleep mode. */
|
||||||
|
#define LOWPOWER_HWWAKE_PERIPHERALS \
|
||||||
|
(1UL << 1) /*!< Wake for Flexcomms. Any Flexcomm FIFO reaching the level specified by its own TXLVL will cause \
|
||||||
|
peripheral clocking to wake up temporarily while the related status is asserted */
|
||||||
|
#define LOWPOWER_HWWAKE_SDMA0 \
|
||||||
|
(1UL << 3) /*!< Wake for DMA0. DMA0 being busy will cause peripheral clocking to remain running until DMA \
|
||||||
|
completes. Used in conjonction with LOWPOWER_HWWAKE_PERIPHERALS */
|
||||||
|
#define LOWPOWER_HWWAKE_SDMA1 \
|
||||||
|
(1UL << 5) /*!< Wake for DMA1. DMA0 being busy will cause peripheral clocking to remain running until DMA \
|
||||||
|
completes. Used in conjonction with LOWPOWER_HWWAKE_PERIPHERALS */
|
||||||
|
#define LOWPOWER_HWWAKE_ENABLE_FRO192M \
|
||||||
|
(1UL << 31) /*!< Need to be set if FRO192M is disable - via PDCTRL0 - in Deep Sleep mode and any of \
|
||||||
|
LOWPOWER_HWWAKE_PERIPHERALS, LOWPOWER_HWWAKE_SDMA0 or LOWPOWER_HWWAKE_SDMA1 is set */
|
||||||
|
|
||||||
|
#define LOWPOWER_CPURETCTRL_ENA_DISABLE 0 /*!< In POWER DOWN mode, CPU Retention is disabled */
|
||||||
|
#define LOWPOWER_CPURETCTRL_ENA_ENABLE 1 /*!< In POWER DOWN mode, CPU Retention is enabled */
|
||||||
|
/**
|
||||||
|
* @brief Wake up I/O sources
|
||||||
|
*/
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_PIO0_INDEX 0 /*!< Pin P1( 1) */
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_PIO1_INDEX 2 /*!< Pin P0(28) */
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_PIO2_INDEX 4 /*!< Pin P1(18) */
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_PIO3_INDEX 6 /*!< Pin P1(30) */
|
||||||
|
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_DISABLE 0 /*!< Wake up is disable */
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_RISING 1 /*!< Wake up on rising edge */
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_FALLING 2 /*!< Wake up on falling edge */
|
||||||
|
#define LOWPOWER_WAKEUPIOSRC_RISING_FALLING 3 /*!< Wake up on both rising or falling edges */
|
||||||
|
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO0_PULLUPDOWN_INDEX 8 /*!< Wake-up I/O 0 pull-up/down configuration index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO1_PULLUPDOWN_INDEX 9 /*!< Wake-up I/O 1 pull-up/down configuration index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO2_PULLUPDOWN_INDEX 10 /*!< Wake-up I/O 2 pull-up/down configuration index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO3_PULLUPDOWN_INDEX 11 /*!< Wake-up I/O 3 pull-up/down configuration index */
|
||||||
|
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO0_PULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO0_PULLUPDOWN_INDEX) /*!< Wake-up I/O 0 pull-up/down mask */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO1_PULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO1_PULLUPDOWN_INDEX) /*!< Wake-up I/O 1 pull-up/down mask */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO2_PULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO2_PULLUPDOWN_INDEX) /*!< Wake-up I/O 2 pull-up/down mask */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO3_PULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO3_PULLUPDOWN_INDEX) /*!< Wake-up I/O 3 pull-up/down mask */
|
||||||
|
|
||||||
|
#define LOWPOWER_WAKEUPIO_PULLDOWN 0 /*!< Select pull-down */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PULLUP 1 /*!< Select pull-up */
|
||||||
|
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO0_DISABLEPULLUPDOWN_INDEX \
|
||||||
|
12 /*!< Wake-up I/O 0 pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO1_DISABLEPULLUPDOWN_INDEX \
|
||||||
|
13 /*!< Wake-up I/O 1 pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO2_DISABLEPULLUPDOWN_INDEX \
|
||||||
|
14 /*!< Wake-up I/O 2 pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO3_DISABLEPULLUPDOWN_INDEX \
|
||||||
|
15 /*!< Wake-up I/O 3 pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO0_DISABLEPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO0_DISABLEPULLUPDOWN_INDEX) /*!< Wake-up I/O 0 pull-up/down disable/enable mask */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO1_DISABLEPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO1_DISABLEPULLUPDOWN_INDEX) /*!< Wake-up I/O 1 pull-up/down disable/enable mask */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO2_DISABLEPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO2_DISABLEPULLUPDOWN_INDEX) /*!< Wake-up I/O 2 pull-up/down disable/enable mask */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO3_DISABLEPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO3_DISABLEPULLUPDOWN_INDEX) /*!< Wake-up I/O 3 pull-up/down disable/enable mask */
|
||||||
|
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO0_USEEXTERNALPULLUPDOWN_INDEX \
|
||||||
|
(16) /*!< Wake-up I/O 0 use external pull-up/down disable/enable control index*/
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO1_USEEXTERNALPULLUPDOWN_INDEX \
|
||||||
|
(17) /*!< Wake-up I/O 1 use external pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO2_USEEXTERNALPULLUPDOWN_INDEX \
|
||||||
|
(18) /*!< Wake-up I/O 2 use external pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO3_USEEXTERNALPULLUPDOWN_INDEX \
|
||||||
|
(19) /*!< Wake-up I/O 3 use external pull-up/down disable/enable control index */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO0_USEEXTERNALPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO0_USEEXTERNALPULLUPDOWN_INDEX) /*!< Wake-up I/O 0 use external pull-up/down \
|
||||||
|
disable/enable mask, 0: disable, 1: enable */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO1_USEEXTERNALPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO1_USEEXTERNALPULLUPDOWN_INDEX) /*!< Wake-up I/O 1 use external pull-up/down \
|
||||||
|
disable/enable mask, 0: disable, 1: enable */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO2_USEEXTERNALPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO2_USEEXTERNALPULLUPDOWN_INDEX) /*!< Wake-up I/O 2 use external pull-up/down \
|
||||||
|
disable/enable mask, 0: disable, 1: enable */
|
||||||
|
#define LOWPOWER_WAKEUPIO_PIO3_USEEXTERNALPULLUPDOWN_MASK \
|
||||||
|
(1UL << LOWPOWER_WAKEUPIO_PIO3_USEEXTERNALPULLUPDOWN_INDEX) /*!< Wake-up I/O 3 use external pull-up/down \
|
||||||
|
disable/enable mask, 0: disable, 1: enable */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
/*******************************************************************************
|
||||||
|
* API
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief API to enable PDRUNCFG bit in the Syscon. Note that enabling the bit powers down the peripheral
|
||||||
|
*
|
||||||
|
* @param en peripheral for which to enable the PDRUNCFG bit
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
static inline void POWER_EnablePD(pd_bit_t en)
|
||||||
|
{
|
||||||
|
/* PDRUNCFGSET */
|
||||||
|
PMC->PDRUNCFGSET0 = (uint32_t)en;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief API to disable PDRUNCFG bit in the Syscon. Note that disabling the bit powers up the peripheral
|
||||||
|
*
|
||||||
|
* @param en peripheral for which to disable the PDRUNCFG bit
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
static inline void POWER_DisablePD(pd_bit_t en)
|
||||||
|
{
|
||||||
|
/* PDRUNCFGCLR */
|
||||||
|
PMC->PDRUNCFGCLR0 = (uint32_t)en;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief set BOD VBAT level.
|
||||||
|
*
|
||||||
|
* @param level BOD detect level
|
||||||
|
* @param hyst BoD Hysteresis control
|
||||||
|
* @param enBodVbatReset VBAT brown out detect reset
|
||||||
|
*/
|
||||||
|
static inline void POWER_SetBodVbatLevel(power_bod_vbat_level_t level, power_bod_hyst_t hyst, bool enBodVbatReset)
|
||||||
|
{
|
||||||
|
PMC->BODVBAT = (PMC->BODVBAT & (~(PMC_BODVBAT_TRIGLVL_MASK | PMC_BODVBAT_HYST_MASK))) | PMC_BODVBAT_TRIGLVL(level) |
|
||||||
|
PMC_BODVBAT_HYST(hyst);
|
||||||
|
PMC->RESETCTRL =
|
||||||
|
(PMC->RESETCTRL & (~PMC_RESETCTRL_BODVBATRESETENABLE_MASK)) | PMC_RESETCTRL_BODVBATRESETENABLE(enBodVbatReset);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(PMC_BODCORE_TRIGLVL_MASK)
|
||||||
|
/*!
|
||||||
|
* @brief set BOD core level.
|
||||||
|
*
|
||||||
|
* @param level BOD detect level
|
||||||
|
* @param hyst BoD Hysteresis control
|
||||||
|
* @param enBodCoreReset core brown out detect reset
|
||||||
|
*/
|
||||||
|
static inline void POWER_SetBodCoreLevel(power_bod_core_level_t level, power_bod_hyst_t hyst, bool enBodCoreReset)
|
||||||
|
{
|
||||||
|
PMC->BODCORE = (PMC->BODCORE & (~(PMC_BODCORE_TRIGLVL_MASK | PMC_BODCORE_HYST_MASK))) | PMC_BODCORE_TRIGLVL(level) |
|
||||||
|
PMC_BODCORE_HYST(hyst);
|
||||||
|
PMC->RESETCTRL =
|
||||||
|
(PMC->RESETCTRL & (~PMC_RESETCTRL_BODCORERESETENABLE_MASK)) | PMC_RESETCTRL_BODCORERESETENABLE(enBodCoreReset);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief API to enable deep sleep bit in the ARM Core.
|
||||||
|
*
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
static inline void POWER_EnableDeepSleep(void)
|
||||||
|
{
|
||||||
|
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief API to disable deep sleep bit in the ARM Core.
|
||||||
|
*
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
static inline void POWER_DisableDeepSleep(void)
|
||||||
|
{
|
||||||
|
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Shut off the Flash and execute the _WFI(), then power up the Flash after wake-up event
|
||||||
|
* This MUST BE EXECUTED outside the Flash:
|
||||||
|
* either from ROM or from SRAM. The rest could stay in Flash. But, for consistency, it is
|
||||||
|
* preferable to have all functions defined in this file implemented in ROM.
|
||||||
|
*
|
||||||
|
* @return Nothing
|
||||||
|
*/
|
||||||
|
void POWER_CycleCpuAndFlash(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures and enters in DEEP-SLEEP low power mode
|
||||||
|
* @param exclude_from_pd:
|
||||||
|
* @param sram_retention_ctrl:
|
||||||
|
* @param wakeup_interrupts:
|
||||||
|
* @param hardware_wake_ctrl:
|
||||||
|
|
||||||
|
* @return Nothing
|
||||||
|
*
|
||||||
|
* !!! IMPORTANT NOTES :
|
||||||
|
0 - CPU0 & System CLock frequency is switched to FRO12MHz and is NOT restored back by the API.
|
||||||
|
* 1 - CPU0 Interrupt Enable registers (NVIC->ISER) are modified by this function. They are restored back in
|
||||||
|
case of CPU retention or if POWERDOWN is not taken (for instance because an interrupt is pending).
|
||||||
|
* 2 - The Non Maskable Interrupt (NMI) is disabled and its configuration before calling this function will be
|
||||||
|
restored back if POWERDOWN is not taken (for instance because an RTC or OSTIMER interrupt is pending).
|
||||||
|
* 3 - The HARD FAULT handler should execute from SRAM. (The Hard fault handler should initiate a full chip
|
||||||
|
reset) reset)
|
||||||
|
*/
|
||||||
|
void POWER_EnterDeepSleep(uint32_t exclude_from_pd,
|
||||||
|
uint32_t sram_retention_ctrl,
|
||||||
|
uint64_t wakeup_interrupts,
|
||||||
|
uint32_t hardware_wake_ctrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures and enters in POWERDOWN low power mode
|
||||||
|
* @param exclude_from_pd:
|
||||||
|
* @param sram_retention_ctrl:
|
||||||
|
* @param wakeup_interrupts:
|
||||||
|
* @param cpu_retention_ctrl: 0 = CPU retention is disable / 1 = CPU retention is enabled, all other values are
|
||||||
|
RESERVED.
|
||||||
|
|
||||||
|
* @return Nothing
|
||||||
|
*
|
||||||
|
* !!! IMPORTANT NOTES :
|
||||||
|
0 - CPU0 & System CLock frequency is switched to FRO12MHz and is NOT restored back by the API.
|
||||||
|
* 1 - CPU0 Interrupt Enable registers (NVIC->ISER) are modified by this function. They are restored back in
|
||||||
|
case of CPU retention or if POWERDOWN is not taken (for instance because an interrupt is pending).
|
||||||
|
* 2 - The Non Maskable Interrupt (NMI) is disabled and its configuration before calling this function will be
|
||||||
|
restored back if POWERDOWN is not taken (for instance because an RTC or OSTIMER interrupt is pending).
|
||||||
|
* 3 - In case of CPU retention, it is the responsability of the user to make sure that SRAM instance
|
||||||
|
containing the stack used to call this function WILL BE preserved during low power (via parameter
|
||||||
|
"sram_retention_ctrl")
|
||||||
|
* 4 - The HARD FAULT handler should execute from SRAM. (The Hard fault handler should initiate a full chip
|
||||||
|
reset) reset)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void POWER_EnterPowerDown(uint32_t exclude_from_pd,
|
||||||
|
uint32_t sram_retention_ctrl,
|
||||||
|
uint64_t wakeup_interrupts,
|
||||||
|
uint32_t cpu_retention_ctrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures and enters in DEEPPOWERDOWN low power mode
|
||||||
|
* @param exclude_from_pd:
|
||||||
|
* @param sram_retention_ctrl:
|
||||||
|
* @param wakeup_interrupts:
|
||||||
|
* @param wakeup_io_ctrl:
|
||||||
|
|
||||||
|
* @return Nothing
|
||||||
|
*
|
||||||
|
* !!! IMPORTANT NOTES :
|
||||||
|
0 - CPU0 & System CLock frequency is switched to FRO12MHz and is NOT restored back by the API.
|
||||||
|
* 1 - CPU0 Interrupt Enable registers (NVIC->ISER) are modified by this function. They are restored back if
|
||||||
|
DEEPPOWERDOWN is not taken (for instance because an RTC or OSTIMER interrupt is pending).
|
||||||
|
* 2 - The Non Maskable Interrupt (NMI) is disabled and its configuration before calling this function will be
|
||||||
|
restored back if DEEPPOWERDOWN is not taken (for instance because an RTC or OSTIMER interrupt is pending).
|
||||||
|
* 3 - The HARD FAULT handler should execute from SRAM. (The Hard fault handler should initiate a full chip
|
||||||
|
reset)
|
||||||
|
*/
|
||||||
|
void POWER_EnterDeepPowerDown(uint32_t exclude_from_pd,
|
||||||
|
uint32_t sram_retention_ctrl,
|
||||||
|
uint64_t wakeup_interrupts,
|
||||||
|
uint32_t wakeup_io_ctrl);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Configures and enters in SLEEP low power mode
|
||||||
|
* @param :
|
||||||
|
* @return Nothing
|
||||||
|
*/
|
||||||
|
void POWER_EnterSleep(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Power Library API to choose normal regulation and set the voltage for the desired operating frequency.
|
||||||
|
*
|
||||||
|
* @param system_freq_hz - The desired frequency (in Hertz) at which the part would like to operate,
|
||||||
|
* note that the voltage and flash wait states should be set before changing frequency
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
void POWER_SetVoltageForFreq(uint32_t system_freq_hz);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets board-specific trim values for 16MHz XTAL
|
||||||
|
* @param pi32_16MfXtalIecLoadpF_x100 Load capacitance, pF x 100. For example, 6pF becomes 600, 1.2pF becomes 120
|
||||||
|
* @param pi32_16MfXtalPPcbParCappF_x100 PCB +ve parasitic capacitance, pF x 100. For example, 6pF becomes 600, 1.2pF
|
||||||
|
* becomes 120
|
||||||
|
* @param pi32_16MfXtalNPcbParCappF_x100 PCB -ve parasitic capacitance, pF x 100. For example, 6pF becomes 600, 1.2pF
|
||||||
|
* becomes 120
|
||||||
|
* @return none
|
||||||
|
* @note Following default Values can be used:
|
||||||
|
* pi32_32MfXtalIecLoadpF_x100 Load capacitance, pF x 100 : 600
|
||||||
|
* pi32_32MfXtalPPcbParCappF_x100 PCB +ve parasitic capacitance, pF x 100 : 20
|
||||||
|
* pi32_32MfXtalNPcbParCappF_x100 PCB -ve parasitic capacitance, pF x 100 : 40
|
||||||
|
*/
|
||||||
|
extern void POWER_Xtal16mhzCapabankTrim(int32_t pi32_16MfXtalIecLoadpF_x100,
|
||||||
|
int32_t pi32_16MfXtalPPcbParCappF_x100,
|
||||||
|
int32_t pi32_16MfXtalNPcbParCappF_x100);
|
||||||
|
/**
|
||||||
|
* @brief Sets board-specific trim values for 32kHz XTAL
|
||||||
|
* @param pi32_32kfXtalIecLoadpF_x100 Load capacitance, pF x 100. For example, 6pF becomes 600, 1.2pF becomes 120
|
||||||
|
* @param pi32_32kfXtalPPcbParCappF_x100 PCB +ve parasitic capacitance, pF x 100. For example, 6pF becomes 600, 1.2pF
|
||||||
|
becomes 120
|
||||||
|
* @param pi32_32kfXtalNPcbParCappF_x100 PCB -ve parasitic capacitance, pF x 100. For example, 6pF becomes 600, 1.2pF
|
||||||
|
becomes 120
|
||||||
|
|
||||||
|
* @return none
|
||||||
|
* @note Following default Values can be used:
|
||||||
|
* pi32_32kfXtalIecLoadpF_x100 Load capacitance, pF x 100 : 600
|
||||||
|
* pi32_32kfXtalPPcbParCappF_x100 PCB +ve parasitic capacitance, pF x 100 : 40
|
||||||
|
* pi32_32kfXtalNPcbParCappF_x100 PCB -ve parasitic capacitance, pF x 100 : 40
|
||||||
|
*/
|
||||||
|
extern void POWER_Xtal32khzCapabankTrim(int32_t pi32_32kfXtalIecLoadpF_x100,
|
||||||
|
int32_t pi32_32kfXtalPPcbParCappF_x100,
|
||||||
|
int32_t pi32_32kfXtalNPcbParCappF_x100);
|
||||||
|
/**
|
||||||
|
* @brief Enables and sets LDO for 16MHz XTAL
|
||||||
|
*
|
||||||
|
* @return none
|
||||||
|
*/
|
||||||
|
extern void POWER_SetXtal16mhzLdo(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Return some key information related to the device reset causes / wake-up sources, for all power modes.
|
||||||
|
* @param p_reset_cause : the device reset cause, according to the definition of power_device_reset_cause_t type.
|
||||||
|
* @param p_boot_mode : the device boot mode, according to the definition of power_device_boot_mode_t type.
|
||||||
|
* @param p_wakeupio_cause: the wake-up pin sources, according to the definition of register PMC->WAKEIOCAUSE[3:0].
|
||||||
|
|
||||||
|
* @return Nothing
|
||||||
|
*
|
||||||
|
* !!! IMPORTANT ERRATA - IMPORTANT ERRATA - IMPORTANT ERRATA !!!
|
||||||
|
* !!! valid ONLY for LPC55S69 (not for LPC55S16 and LPC55S06) !!!
|
||||||
|
* !!! when FALLING EDGE DETECTION is enabled on wake-up pins: !!!
|
||||||
|
* - 1. p_wakeupio_cause is NOT ACCURATE
|
||||||
|
* - 2. Spurious kRESET_CAUSE_DPDRESET_WAKEUPIO* event is reported when
|
||||||
|
* several wake-up sources are enabled during DEEP-POWER-DOWN
|
||||||
|
* (like enabling wake-up on RTC and Falling edge wake-up pins)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void POWER_GetWakeUpCause(power_device_reset_cause_t *p_reset_cause,
|
||||||
|
power_device_boot_mode_t *p_boot_mode,
|
||||||
|
uint32_t *p_wakeupio_cause);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
#endif /* _FSL_POWER_H_ */
|
||||||
317
drivers/Inc/fsl_reset.h
Normal file
317
drivers/Inc/fsl_reset.h
Normal file
@ -0,0 +1,317 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016, NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FSL_RESET_H_
|
||||||
|
#define _FSL_RESET_H_
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "fsl_device_registers.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup reset
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @name Driver version */
|
||||||
|
/*@{*/
|
||||||
|
/*! @brief reset driver version 2.4.0 */
|
||||||
|
#define FSL_RESET_DRIVER_VERSION (MAKE_VERSION(2, 4, 0))
|
||||||
|
/*@}*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enumeration for peripheral reset control bits
|
||||||
|
*
|
||||||
|
* Defines the enumeration for peripheral reset control bits in PRESETCTRL/ASYNCPRESETCTRL registers
|
||||||
|
*/
|
||||||
|
typedef enum _SYSCON_RSTn
|
||||||
|
{
|
||||||
|
kROM_RST_SHIFT_RSTn = 0 | 1U, /**< ROM reset control */
|
||||||
|
kSRAM1_RST_SHIFT_RSTn = 0 | 3U, /**< SRAM1 reset control */
|
||||||
|
kSRAM2_RST_SHIFT_RSTn = 0 | 4U, /**< SRAM2 reset control */
|
||||||
|
kSRAM3_RST_SHIFT_RSTn = 0 | 5U, /**< SRAM3 reset control */
|
||||||
|
kSRAM4_RST_SHIFT_RSTn = 0 | 6U, /**< SRAM4 reset control */
|
||||||
|
kFLASH_RST_SHIFT_RSTn = 0 | 7U, /**< Flash controller reset control */
|
||||||
|
kFMC_RST_SHIFT_RSTn = 0 | 8U, /**< Flash accelerator reset control */
|
||||||
|
kSPIFI_RST_SHIFT_RSTn = 0 | 10U, /**< SPIFI reset control */
|
||||||
|
kMUX0_RST_SHIFT_RSTn = 0 | 11U, /**< Input mux0 reset control */
|
||||||
|
kIOCON_RST_SHIFT_RSTn = 0 | 13U, /**< IOCON reset control */
|
||||||
|
kGPIO0_RST_SHIFT_RSTn = 0 | 14U, /**< GPIO0 reset control */
|
||||||
|
kGPIO1_RST_SHIFT_RSTn = 0 | 15U, /**< GPIO1 reset control */
|
||||||
|
kGPIO2_RST_SHIFT_RSTn = 0 | 16U, /**< GPIO2 reset control */
|
||||||
|
kGPIO3_RST_SHIFT_RSTn = 0 | 17U, /**< GPIO3 reset control */
|
||||||
|
kPINT_RST_SHIFT_RSTn = 0 | 18U, /**< Pin interrupt (PINT) reset control */
|
||||||
|
kGINT_RST_SHIFT_RSTn = 0 | 19U, /**< Grouped interrupt (PINT) reset control. */
|
||||||
|
kDMA0_RST_SHIFT_RSTn = 0 | 20U, /**< DMA reset control */
|
||||||
|
kCRC_RST_SHIFT_RSTn = 0 | 21U, /**< CRC reset control */
|
||||||
|
kWWDT_RST_SHIFT_RSTn = 0 | 22U, /**< Watchdog timer reset control */
|
||||||
|
kRTC_RST_SHIFT_RSTn = 0 | 23U, /**< RTC reset control */
|
||||||
|
kMAILBOX_RST_SHIFT_RSTn = 0 | 26U, /**< Mailbox reset control */
|
||||||
|
kADC0_RST_SHIFT_RSTn = 0 | 27U, /**< ADC0 reset control */
|
||||||
|
|
||||||
|
kMRT_RST_SHIFT_RSTn = 65536 | 0U, /**< Multi-rate timer (MRT) reset control */
|
||||||
|
kOSTIMER0_RST_SHIFT_RSTn = 65536 | 1U, /**< OSTimer0 reset control */
|
||||||
|
kSCT0_RST_SHIFT_RSTn = 65536 | 2U, /**< SCTimer/PWM 0 (SCT0) reset control */
|
||||||
|
kSCTIPU_RST_SHIFT_RSTn = 65536 | 6U, /**< SCTIPU reset control */
|
||||||
|
kUTICK_RST_SHIFT_RSTn = 65536 | 10U, /**< Micro-tick timer reset control */
|
||||||
|
kFC0_RST_SHIFT_RSTn = 65536 | 11U, /**< Flexcomm Interface 0 reset control */
|
||||||
|
kFC1_RST_SHIFT_RSTn = 65536 | 12U, /**< Flexcomm Interface 1 reset control */
|
||||||
|
kFC2_RST_SHIFT_RSTn = 65536 | 13U, /**< Flexcomm Interface 2 reset control */
|
||||||
|
kFC3_RST_SHIFT_RSTn = 65536 | 14U, /**< Flexcomm Interface 3 reset control */
|
||||||
|
kFC4_RST_SHIFT_RSTn = 65536 | 15U, /**< Flexcomm Interface 4 reset control */
|
||||||
|
kFC5_RST_SHIFT_RSTn = 65536 | 16U, /**< Flexcomm Interface 5 reset control */
|
||||||
|
kFC6_RST_SHIFT_RSTn = 65536 | 17U, /**< Flexcomm Interface 6 reset control */
|
||||||
|
kFC7_RST_SHIFT_RSTn = 65536 | 18U, /**< Flexcomm Interface 7 reset control */
|
||||||
|
kCTIMER2_RST_SHIFT_RSTn = 65536 | 22U, /**< CTimer 2 reset control */
|
||||||
|
kUSB0D_RST_SHIFT_RSTn = 65536 | 25U, /**< USB0 Device reset control */
|
||||||
|
kCTIMER0_RST_SHIFT_RSTn = 65536 | 26U, /**< CTimer 0 reset control */
|
||||||
|
kCTIMER1_RST_SHIFT_RSTn = 65536 | 27U, /**< CTimer 1 reset control */
|
||||||
|
kPVT_RST_SHIFT_RSTn = 65536 | 28U, /**< PVT reset control */
|
||||||
|
kEZHA_RST_SHIFT_RSTn = 65536 | 30U, /**< EZHA reset control */
|
||||||
|
kEZHB_RST_SHIFT_RSTn = 65536 | 31U, /**< EZHB reset control */
|
||||||
|
|
||||||
|
kDMA1_RST_SHIFT_RSTn = 131072 | 1U, /**< DMA1 reset control */
|
||||||
|
kCMP_RST_SHIFT_RSTn = 131072 | 2U, /**< CMP reset control */
|
||||||
|
kSDIO_RST_SHIFT_RSTn = 131072 | 3U, /**< SDIO reset control */
|
||||||
|
kUSB1H_RST_SHIFT_RSTn = 131072 | 4U, /**< USBHS Host reset control */
|
||||||
|
kUSB1D_RST_SHIFT_RSTn = 131072 | 5U, /**< USBHS Device reset control */
|
||||||
|
kUSB1RAM_RST_SHIFT_RSTn = 131072 | 6U, /**< USB RAM reset control */
|
||||||
|
kUSB1_RST_SHIFT_RSTn = 131072 | 7U, /**< USBHS reset control */
|
||||||
|
kFREQME_RST_SHIFT_RSTn = 131072 | 8U, /**< FREQME reset control */
|
||||||
|
kGPIO4_RST_SHIFT_RSTn = 131072 | 9U, /**< GPIO4 reset control */
|
||||||
|
kGPIO5_RST_SHIFT_RSTn = 131072 | 10U, /**< GPIO5 reset control */
|
||||||
|
kAES_RST_SHIFT_RSTn = 131072 | 11U, /**< AES reset control */
|
||||||
|
kOTP_RST_SHIFT_RSTn = 131072 | 12U, /**< OTP reset control */
|
||||||
|
kRNG_RST_SHIFT_RSTn = 131072 | 13U, /**< RNG reset control */
|
||||||
|
kMUX1_RST_SHIFT_RSTn = 131072 | 14U, /**< Input mux1 reset control */
|
||||||
|
kUSB0HMR_RST_SHIFT_RSTn = 131072 | 16U, /**< USB0HMR reset control */
|
||||||
|
kUSB0HSL_RST_SHIFT_RSTn = 131072 | 17U, /**< USB0HSL reset control */
|
||||||
|
kHASHCRYPT_RST_SHIFT_RSTn = 131072 | 18U, /**< HASHCRYPT reset control */
|
||||||
|
kPOWERQUAD_RST_SHIFT_RSTn = 131072 | 19U, /**< PowerQuad reset control */
|
||||||
|
kPLULUT_RST_SHIFT_RSTn = 131072 | 20U, /**< PLU LUT reset control */
|
||||||
|
kCTIMER3_RST_SHIFT_RSTn = 131072 | 21U, /**< CTimer 3 reset control */
|
||||||
|
kCTIMER4_RST_SHIFT_RSTn = 131072 | 22U, /**< CTimer 4 reset control */
|
||||||
|
kPUF_RST_SHIFT_RSTn = 131072 | 23U, /**< PUF reset control */
|
||||||
|
kCASPER_RST_SHIFT_RSTn = 131072 | 24U, /**< CASPER reset control */
|
||||||
|
kCAP0_RST_SHIFT_RSTn = 131072 | 25U, /**< CASPER reset control */
|
||||||
|
kOSTIMER1_RST_SHIFT_RSTn = 131072 | 26U, /**< OSTIMER1 reset control */
|
||||||
|
kANALOGCTL_RST_SHIFT_RSTn = 131072 | 27U, /**< ANALOG_CTL reset control */
|
||||||
|
kHSLSPI_RST_SHIFT_RSTn = 131072 | 28U, /**< HS LSPI reset control */
|
||||||
|
kGPIOSEC_RST_SHIFT_RSTn = 131072 | 29U, /**< GPIO Secure reset control */
|
||||||
|
kGPIOSECINT_RST_SHIFT_RSTn = 131072 | 30U, /**< GPIO Secure int reset control */
|
||||||
|
} SYSCON_RSTn_t;
|
||||||
|
|
||||||
|
/** Array initializers with peripheral reset bits **/
|
||||||
|
#define ADC_RSTS \
|
||||||
|
{ \
|
||||||
|
kADC0_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for ADC peripheral */
|
||||||
|
#define AES_RSTS \
|
||||||
|
{ \
|
||||||
|
kAES_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for AES peripheral */
|
||||||
|
#define CRC_RSTS \
|
||||||
|
{ \
|
||||||
|
kCRC_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for CRC peripheral */
|
||||||
|
#define CTIMER_RSTS \
|
||||||
|
{ \
|
||||||
|
kCTIMER0_RST_SHIFT_RSTn, kCTIMER1_RST_SHIFT_RSTn, kCTIMER2_RST_SHIFT_RSTn, kCTIMER3_RST_SHIFT_RSTn, \
|
||||||
|
kCTIMER4_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for CTIMER peripheral */
|
||||||
|
#define DMA_RSTS_N \
|
||||||
|
{ \
|
||||||
|
kDMA0_RST_SHIFT_RSTn, kDMA1_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for DMA peripheral */
|
||||||
|
|
||||||
|
#define FLEXCOMM_RSTS \
|
||||||
|
{ \
|
||||||
|
kFC0_RST_SHIFT_RSTn, kFC1_RST_SHIFT_RSTn, kFC2_RST_SHIFT_RSTn, kFC3_RST_SHIFT_RSTn, kFC4_RST_SHIFT_RSTn, \
|
||||||
|
kFC5_RST_SHIFT_RSTn, kFC6_RST_SHIFT_RSTn, kFC7_RST_SHIFT_RSTn, kHSLSPI_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for FLEXCOMM peripheral */
|
||||||
|
#define GINT_RSTS \
|
||||||
|
{ \
|
||||||
|
kGINT_RST_SHIFT_RSTn, kGINT_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for GINT peripheral. GINT0 & GINT1 share same slot */
|
||||||
|
#define GPIO_RSTS_N \
|
||||||
|
{ \
|
||||||
|
kGPIO0_RST_SHIFT_RSTn, kGPIO1_RST_SHIFT_RSTn, kGPIO2_RST_SHIFT_RSTn, kGPIO3_RST_SHIFT_RSTn, \
|
||||||
|
kGPIO4_RST_SHIFT_RSTn, kGPIO5_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for GPIO peripheral */
|
||||||
|
#define INPUTMUX_RSTS \
|
||||||
|
{ \
|
||||||
|
kMUX0_RST_SHIFT_RSTn, kMUX1_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for INPUTMUX peripheral */
|
||||||
|
#define IOCON_RSTS \
|
||||||
|
{ \
|
||||||
|
kIOCON_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for IOCON peripheral */
|
||||||
|
#define FLASH_RSTS \
|
||||||
|
{ \
|
||||||
|
kFLASH_RST_SHIFT_RSTn, kFMC_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for Flash peripheral */
|
||||||
|
#define MRT_RSTS \
|
||||||
|
{ \
|
||||||
|
kMRT_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for MRT peripheral */
|
||||||
|
#define OTP_RSTS \
|
||||||
|
{ \
|
||||||
|
kOTP_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for OTP peripheral */
|
||||||
|
#define PINT_RSTS \
|
||||||
|
{ \
|
||||||
|
kPINT_RST_SHIFT_RSTn, kGPIOSECINT_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for PINT peripheral */
|
||||||
|
#define RNG_RSTS \
|
||||||
|
{ \
|
||||||
|
kRNG_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for RNG peripheral */
|
||||||
|
#define SDIO_RST \
|
||||||
|
{ \
|
||||||
|
kSDIO_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for SDIO peripheral */
|
||||||
|
#define SCT_RSTS \
|
||||||
|
{ \
|
||||||
|
kSCT0_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for SCT peripheral */
|
||||||
|
#define SPIFI_RSTS \
|
||||||
|
{ \
|
||||||
|
kSPIFI_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for SPIFI peripheral */
|
||||||
|
#define USB0D_RST \
|
||||||
|
{ \
|
||||||
|
kUSB0D_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for USB0D peripheral */
|
||||||
|
#define USB0HMR_RST \
|
||||||
|
{ \
|
||||||
|
kUSB0HMR_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for USB0HMR peripheral */
|
||||||
|
#define USB0HSL_RST \
|
||||||
|
{ \
|
||||||
|
kUSB0HSL_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for USB0HSL peripheral */
|
||||||
|
#define USB1H_RST \
|
||||||
|
{ \
|
||||||
|
kUSB1H_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for USB1H peripheral */
|
||||||
|
#define USB1D_RST \
|
||||||
|
{ \
|
||||||
|
kUSB1D_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for USB1D peripheral */
|
||||||
|
#define USB1RAM_RST \
|
||||||
|
{ \
|
||||||
|
kUSB1RAM_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for USB1RAM peripheral */
|
||||||
|
#define UTICK_RSTS \
|
||||||
|
{ \
|
||||||
|
kUTICK_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for UTICK peripheral */
|
||||||
|
#define WWDT_RSTS \
|
||||||
|
{ \
|
||||||
|
kWWDT_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for WWDT peripheral */
|
||||||
|
#define CAPT_RSTS_N \
|
||||||
|
{ \
|
||||||
|
kCAP0_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for CAPT peripheral */
|
||||||
|
#define PLU_RSTS_N \
|
||||||
|
{ \
|
||||||
|
kPLULUT_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for PLU peripheral */
|
||||||
|
#define OSTIMER_RSTS \
|
||||||
|
{ \
|
||||||
|
kOSTIMER0_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for OSTIMER peripheral */
|
||||||
|
#define POWERQUAD_RSTS \
|
||||||
|
{ \
|
||||||
|
kPOWERQUAD_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for Powerquad peripheral */
|
||||||
|
#define CASPER_RSTS \
|
||||||
|
{ \
|
||||||
|
kCASPER_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for Casper peripheral */
|
||||||
|
#define HASHCRYPT_RSTS \
|
||||||
|
{ \
|
||||||
|
kHASHCRYPT_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for Hashcrypt peripheral */
|
||||||
|
#define PUF_RSTS \
|
||||||
|
{ \
|
||||||
|
kPUF_RST_SHIFT_RSTn \
|
||||||
|
} /* Reset bits for PUF peripheral */
|
||||||
|
typedef SYSCON_RSTn_t reset_ip_name_t;
|
||||||
|
#define USB1RAM_RSTS USB1RAM_RST
|
||||||
|
#define USB1H_RSTS USB1H_RST
|
||||||
|
#define USB1D_RSTS USB1D_RST
|
||||||
|
#define USB0HSL_RSTS USB0HSL_RST
|
||||||
|
#define USB0HMR_RSTS USB0HMR_RST
|
||||||
|
#define USB0D_RSTS USB0D_RST
|
||||||
|
#define SDIO_RSTS SDIO_RST
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* API
|
||||||
|
******************************************************************************/
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Assert reset to peripheral.
|
||||||
|
*
|
||||||
|
* Asserts reset signal to specified peripheral module.
|
||||||
|
*
|
||||||
|
* @param peripheral Assert reset to this peripheral. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
void RESET_SetPeripheralReset(reset_ip_name_t peripheral);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Clear reset to peripheral.
|
||||||
|
*
|
||||||
|
* Clears reset signal to specified peripheral module, allows it to operate.
|
||||||
|
*
|
||||||
|
* @param peripheral Clear reset to this peripheral. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
void RESET_ClearPeripheralReset(reset_ip_name_t peripheral);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Reset peripheral module.
|
||||||
|
*
|
||||||
|
* Reset peripheral module.
|
||||||
|
*
|
||||||
|
* @param peripheral Peripheral to reset. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
void RESET_PeripheralReset(reset_ip_name_t peripheral);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Release peripheral module.
|
||||||
|
*
|
||||||
|
* Release peripheral module.
|
||||||
|
*
|
||||||
|
* @param peripheral Peripheral to release. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
static inline void RESET_ReleasePeripheralReset(reset_ip_name_t peripheral)
|
||||||
|
{
|
||||||
|
RESET_ClearPeripheralReset(peripheral);
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif /* _FSL_RESET_H_ */
|
||||||
129
drivers/Inc/fsl_str.h
Normal file
129
drivers/Inc/fsl_str.h
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FSL_STR_H
|
||||||
|
#define _FSL_STR_H
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup debugconsole
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @brief Definition to printf the float number. */
|
||||||
|
#ifndef PRINTF_FLOAT_ENABLE
|
||||||
|
#define PRINTF_FLOAT_ENABLE 0U
|
||||||
|
#endif /* PRINTF_FLOAT_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to scanf the float number. */
|
||||||
|
#ifndef SCANF_FLOAT_ENABLE
|
||||||
|
#define SCANF_FLOAT_ENABLE 0U
|
||||||
|
#endif /* SCANF_FLOAT_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to support advanced format specifier for printf. */
|
||||||
|
#ifndef PRINTF_ADVANCED_ENABLE
|
||||||
|
#define PRINTF_ADVANCED_ENABLE 0U
|
||||||
|
#endif /* PRINTF_ADVANCED_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Definition to support advanced format specifier for scanf. */
|
||||||
|
#ifndef SCANF_ADVANCED_ENABLE
|
||||||
|
#define SCANF_ADVANCED_ENABLE 0U
|
||||||
|
#endif /* SCANF_ADVANCED_ENABLE */
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Prototypes
|
||||||
|
******************************************************************************/
|
||||||
|
#if (defined(PRINTF_ADVANCED_ENABLE) && (PRINTF_ADVANCED_ENABLE > 0U))
|
||||||
|
/*! @brief Specification modifier flags for printf. */
|
||||||
|
enum _debugconsole_printf_flag
|
||||||
|
{
|
||||||
|
kPRINTF_Minus = 0x01U, /*!< Minus FLag. */
|
||||||
|
kPRINTF_Plus = 0x02U, /*!< Plus Flag. */
|
||||||
|
kPRINTF_Space = 0x04U, /*!< Space Flag. */
|
||||||
|
kPRINTF_Zero = 0x08U, /*!< Zero Flag. */
|
||||||
|
kPRINTF_Pound = 0x10U, /*!< Pound Flag. */
|
||||||
|
kPRINTF_LengthChar = 0x20U, /*!< Length: Char Flag. */
|
||||||
|
kPRINTF_LengthShortInt = 0x40U, /*!< Length: Short Int Flag. */
|
||||||
|
kPRINTF_LengthLongInt = 0x80U, /*!< Length: Long Int Flag. */
|
||||||
|
kPRINTF_LengthLongLongInt = 0x100U, /*!< Length: Long Long Int Flag. */
|
||||||
|
};
|
||||||
|
#endif /* PRINTF_ADVANCED_ENABLE */
|
||||||
|
|
||||||
|
/*! @brief Specification modifier flags for scanf. */
|
||||||
|
enum _debugconsole_scanf_flag
|
||||||
|
{
|
||||||
|
kSCANF_Suppress = 0x2U, /*!< Suppress Flag. */
|
||||||
|
kSCANF_DestMask = 0x7cU, /*!< Destination Mask. */
|
||||||
|
kSCANF_DestChar = 0x4U, /*!< Destination Char Flag. */
|
||||||
|
kSCANF_DestString = 0x8U, /*!< Destination String FLag. */
|
||||||
|
kSCANF_DestSet = 0x10U, /*!< Destination Set Flag. */
|
||||||
|
kSCANF_DestInt = 0x20U, /*!< Destination Int Flag. */
|
||||||
|
kSCANF_DestFloat = 0x30U, /*!< Destination Float Flag. */
|
||||||
|
kSCANF_LengthMask = 0x1f00U, /*!< Length Mask Flag. */
|
||||||
|
#if (defined(SCANF_ADVANCED_ENABLE) && (SCANF_ADVANCED_ENABLE > 0U))
|
||||||
|
kSCANF_LengthChar = 0x100U, /*!< Length Char Flag. */
|
||||||
|
kSCANF_LengthShortInt = 0x200U, /*!< Length ShortInt Flag. */
|
||||||
|
kSCANF_LengthLongInt = 0x400U, /*!< Length LongInt Flag. */
|
||||||
|
kSCANF_LengthLongLongInt = 0x800U, /*!< Length LongLongInt Flag. */
|
||||||
|
#endif /* SCANF_ADVANCED_ENABLE */
|
||||||
|
#if (defined(SCANF_FLOAT_ENABLE) && (SCANF_FLOAT_ENABLE > 0))
|
||||||
|
kSCANF_LengthLongLongDouble = 0x1000U, /*!< Length LongLongDuoble Flag. */
|
||||||
|
#endif /*PRINTF_FLOAT_ENABLE */
|
||||||
|
kSCANF_TypeSinged = 0x2000U, /*!< TypeSinged Flag. */
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief A function pointer which is used when format printf log.
|
||||||
|
*/
|
||||||
|
typedef void (*printfCb)(char *buf, int32_t *indicator, char val, int len);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief This function outputs its parameters according to a formatted string.
|
||||||
|
*
|
||||||
|
* @note I/O is performed by calling given function pointer using following
|
||||||
|
* (*func_ptr)(c);
|
||||||
|
*
|
||||||
|
* @param[in] fmt Format string for printf.
|
||||||
|
* @param[in] ap Arguments to printf.
|
||||||
|
* @param[in] buf pointer to the buffer
|
||||||
|
* @param cb print callbck function pointer
|
||||||
|
*
|
||||||
|
* @return Number of characters to be print
|
||||||
|
*/
|
||||||
|
int StrFormatPrintf(const char *fmt, va_list ap, char *buf, printfCb cb);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Converts an input line of ASCII characters based upon a provided
|
||||||
|
* string format.
|
||||||
|
*
|
||||||
|
* @param[in] line_ptr The input line of ASCII data.
|
||||||
|
* @param[in] format Format first points to the format string.
|
||||||
|
* @param[in] args_ptr The list of parameters.
|
||||||
|
*
|
||||||
|
* @return Number of input items converted and assigned.
|
||||||
|
* @retval IO_EOF When line_ptr is empty string "".
|
||||||
|
*/
|
||||||
|
int StrFormatScanf(const char *line_ptr, char *format, va_list args_ptr);
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif /* _FSL_STR_H */
|
||||||
971
drivers/Inc/fsl_usart.h
Normal file
971
drivers/Inc/fsl_usart.h
Normal file
@ -0,0 +1,971 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2023 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
#ifndef FSL_USART_H_
|
||||||
|
#define FSL_USART_H_
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @addtogroup usart_driver
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*! @name Driver version */
|
||||||
|
/*! @{ */
|
||||||
|
/*! @brief USART driver version. */
|
||||||
|
#define FSL_USART_DRIVER_VERSION (MAKE_VERSION(2, 8, 4))
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#define USART_FIFOTRIG_TXLVL_GET(base) (((base)->FIFOTRIG & USART_FIFOTRIG_TXLVL_MASK) >> USART_FIFOTRIG_TXLVL_SHIFT)
|
||||||
|
#define USART_FIFOTRIG_RXLVL_GET(base) (((base)->FIFOTRIG & USART_FIFOTRIG_RXLVL_MASK) >> USART_FIFOTRIG_RXLVL_SHIFT)
|
||||||
|
|
||||||
|
/*! @brief Retry times for waiting flag.
|
||||||
|
*
|
||||||
|
* Defining to zero means to keep waiting for the flag until it is assert/deassert in blocking transfer,
|
||||||
|
* otherwise the program will wait until the UART_RETRY_TIMES counts down to 0,
|
||||||
|
* if the flag still remains unchanged then program will return kStatus_USART_Timeout.
|
||||||
|
* It is not advised to use this macro in formal application to prevent any hardware error
|
||||||
|
* because the actual wait period is affected by the compiler and optimization.
|
||||||
|
*/
|
||||||
|
#ifndef UART_RETRY_TIMES
|
||||||
|
#define UART_RETRY_TIMES 0U
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @brief Error codes for the USART driver. */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
kStatus_USART_TxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 0), /*!< Transmitter is busy. */
|
||||||
|
kStatus_USART_RxBusy = MAKE_STATUS(kStatusGroup_LPC_USART, 1), /*!< Receiver is busy. */
|
||||||
|
kStatus_USART_TxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 2), /*!< USART transmitter is idle. */
|
||||||
|
kStatus_USART_RxIdle = MAKE_STATUS(kStatusGroup_LPC_USART, 3), /*!< USART receiver is idle. */
|
||||||
|
kStatus_USART_TxError = MAKE_STATUS(kStatusGroup_LPC_USART, 7), /*!< Error happens on txFIFO. */
|
||||||
|
kStatus_USART_RxError = MAKE_STATUS(kStatusGroup_LPC_USART, 9), /*!< Error happens on rxFIFO. */
|
||||||
|
kStatus_USART_RxRingBufferOverrun = MAKE_STATUS(kStatusGroup_LPC_USART, 8), /*!< Error happens on rx ring buffer */
|
||||||
|
kStatus_USART_NoiseError = MAKE_STATUS(kStatusGroup_LPC_USART, 10), /*!< USART noise error. */
|
||||||
|
kStatus_USART_FramingError = MAKE_STATUS(kStatusGroup_LPC_USART, 11), /*!< USART framing error. */
|
||||||
|
kStatus_USART_ParityError = MAKE_STATUS(kStatusGroup_LPC_USART, 12), /*!< USART parity error. */
|
||||||
|
kStatus_USART_BaudrateNotSupport =
|
||||||
|
MAKE_STATUS(kStatusGroup_LPC_USART, 13), /*!< Baudrate is not support in current clock source */
|
||||||
|
#if UART_RETRY_TIMES
|
||||||
|
kStatus_USART_Timeout = MAKE_STATUS(kStatusGroup_LPC_USART, 14), /*!< USART time out. */
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/*! @brief USART synchronous mode. */
|
||||||
|
typedef enum _usart_sync_mode
|
||||||
|
{
|
||||||
|
kUSART_SyncModeDisabled = 0x0U, /*!< Asynchronous mode. */
|
||||||
|
kUSART_SyncModeSlave = 0x2U, /*!< Synchronous slave mode. */
|
||||||
|
kUSART_SyncModeMaster = 0x3U, /*!< Synchronous master mode. */
|
||||||
|
} usart_sync_mode_t;
|
||||||
|
|
||||||
|
/*! @brief USART parity mode. */
|
||||||
|
typedef enum _usart_parity_mode
|
||||||
|
{
|
||||||
|
kUSART_ParityDisabled = 0x0U, /*!< Parity disabled */
|
||||||
|
kUSART_ParityEven = 0x2U, /*!< Parity enabled, type even, bit setting: PE|PT = 10 */
|
||||||
|
kUSART_ParityOdd = 0x3U, /*!< Parity enabled, type odd, bit setting: PE|PT = 11 */
|
||||||
|
} usart_parity_mode_t;
|
||||||
|
|
||||||
|
/*! @brief USART stop bit count. */
|
||||||
|
typedef enum _usart_stop_bit_count
|
||||||
|
{
|
||||||
|
kUSART_OneStopBit = 0U, /*!< One stop bit */
|
||||||
|
kUSART_TwoStopBit = 1U, /*!< Two stop bits */
|
||||||
|
} usart_stop_bit_count_t;
|
||||||
|
|
||||||
|
/*! @brief USART data size. */
|
||||||
|
typedef enum _usart_data_len
|
||||||
|
{
|
||||||
|
kUSART_7BitsPerChar = 0U, /*!< Seven bit mode */
|
||||||
|
kUSART_8BitsPerChar = 1U, /*!< Eight bit mode */
|
||||||
|
} usart_data_len_t;
|
||||||
|
|
||||||
|
/*! @brief USART clock polarity configuration, used in sync mode.*/
|
||||||
|
typedef enum _usart_clock_polarity
|
||||||
|
{
|
||||||
|
kUSART_RxSampleOnFallingEdge = 0x0U, /*!< Un_RXD is sampled on the falling edge of SCLK. */
|
||||||
|
kUSART_RxSampleOnRisingEdge = 0x1U, /*!< Un_RXD is sampled on the rising edge of SCLK. */
|
||||||
|
} usart_clock_polarity_t;
|
||||||
|
|
||||||
|
/*! @brief txFIFO watermark values */
|
||||||
|
typedef enum _usart_txfifo_watermark
|
||||||
|
{
|
||||||
|
kUSART_TxFifo0 = 0, /*!< USART tx watermark is empty */
|
||||||
|
kUSART_TxFifo1 = 1, /*!< USART tx watermark at 1 item */
|
||||||
|
kUSART_TxFifo2 = 2, /*!< USART tx watermark at 2 items */
|
||||||
|
kUSART_TxFifo3 = 3, /*!< USART tx watermark at 3 items */
|
||||||
|
kUSART_TxFifo4 = 4, /*!< USART tx watermark at 4 items */
|
||||||
|
kUSART_TxFifo5 = 5, /*!< USART tx watermark at 5 items */
|
||||||
|
kUSART_TxFifo6 = 6, /*!< USART tx watermark at 6 items */
|
||||||
|
kUSART_TxFifo7 = 7, /*!< USART tx watermark at 7 items */
|
||||||
|
} usart_txfifo_watermark_t;
|
||||||
|
|
||||||
|
/*! @brief rxFIFO watermark values */
|
||||||
|
typedef enum _usart_rxfifo_watermark
|
||||||
|
{
|
||||||
|
kUSART_RxFifo1 = 0, /*!< USART rx watermark at 1 item */
|
||||||
|
kUSART_RxFifo2 = 1, /*!< USART rx watermark at 2 items */
|
||||||
|
kUSART_RxFifo3 = 2, /*!< USART rx watermark at 3 items */
|
||||||
|
kUSART_RxFifo4 = 3, /*!< USART rx watermark at 4 items */
|
||||||
|
kUSART_RxFifo5 = 4, /*!< USART rx watermark at 5 items */
|
||||||
|
kUSART_RxFifo6 = 5, /*!< USART rx watermark at 6 items */
|
||||||
|
kUSART_RxFifo7 = 6, /*!< USART rx watermark at 7 items */
|
||||||
|
kUSART_RxFifo8 = 7, /*!< USART rx watermark at 8 items */
|
||||||
|
} usart_rxfifo_watermark_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief USART interrupt configuration structure, default settings all disabled.
|
||||||
|
*/
|
||||||
|
enum _usart_interrupt_enable
|
||||||
|
{
|
||||||
|
kUSART_TxErrorInterruptEnable = (USART_FIFOINTENSET_TXERR_MASK),
|
||||||
|
kUSART_RxErrorInterruptEnable = (USART_FIFOINTENSET_RXERR_MASK),
|
||||||
|
kUSART_TxLevelInterruptEnable = (USART_FIFOINTENSET_TXLVL_MASK),
|
||||||
|
kUSART_RxLevelInterruptEnable = (USART_FIFOINTENSET_RXLVL_MASK),
|
||||||
|
kUSART_TxIdleInterruptEnable = (USART_INTENSET_TXIDLEEN_MASK << 16U), /*!< Transmitter idle. */
|
||||||
|
kUSART_CtsChangeInterruptEnable =
|
||||||
|
(USART_INTENSET_DELTACTSEN_MASK << 16U), /*!< Change in the state of the CTS input. */
|
||||||
|
kUSART_RxBreakChangeInterruptEnable =
|
||||||
|
(USART_INTENSET_DELTARXBRKEN_MASK), /*!< Break condition asserted or deasserted. */
|
||||||
|
kUSART_RxStartInterruptEnable = (USART_INTENSET_STARTEN_MASK), /*!< Rx start bit detected. */
|
||||||
|
kUSART_FramingErrorInterruptEnable = (USART_INTENSET_FRAMERREN_MASK), /*!< Framing error detected. */
|
||||||
|
kUSART_ParityErrorInterruptEnable = (USART_INTENSET_PARITYERREN_MASK), /*!< Parity error detected. */
|
||||||
|
kUSART_NoiseErrorInterruptEnable = (USART_INTENSET_RXNOISEEN_MASK), /*!< Noise error detected. */
|
||||||
|
kUSART_AutoBaudErrorInterruptEnable = (USART_INTENSET_ABERREN_MASK), /*!< Auto baudrate error detected. */
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
kUSART_RxTimeoutInterruptEnable = (USART_FIFOINTENSET_RXTIMEOUT_MASK), /*!< Receive timeout detected. */
|
||||||
|
#endif
|
||||||
|
kUSART_AllInterruptEnables =
|
||||||
|
kUSART_TxErrorInterruptEnable | kUSART_RxErrorInterruptEnable | kUSART_TxLevelInterruptEnable |
|
||||||
|
kUSART_RxLevelInterruptEnable | kUSART_TxIdleInterruptEnable | kUSART_CtsChangeInterruptEnable |
|
||||||
|
kUSART_RxBreakChangeInterruptEnable | kUSART_RxStartInterruptEnable | kUSART_FramingErrorInterruptEnable |
|
||||||
|
kUSART_ParityErrorInterruptEnable | kUSART_NoiseErrorInterruptEnable |
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
kUSART_RxTimeoutInterruptEnable |
|
||||||
|
#endif
|
||||||
|
kUSART_AutoBaudErrorInterruptEnable,
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief USART status flags.
|
||||||
|
*
|
||||||
|
* This provides constants for the USART status flags for use in the USART functions.
|
||||||
|
*/
|
||||||
|
enum _usart_flags
|
||||||
|
{
|
||||||
|
kUSART_TxError = (USART_FIFOSTAT_TXERR_MASK), /*!< TEERR bit, sets if TX buffer is error */
|
||||||
|
kUSART_RxError = (USART_FIFOSTAT_RXERR_MASK), /*!< RXERR bit, sets if RX buffer is error */
|
||||||
|
kUSART_TxFifoEmptyFlag = (USART_FIFOSTAT_TXEMPTY_MASK), /*!< TXEMPTY bit, sets if TX buffer is empty */
|
||||||
|
kUSART_TxFifoNotFullFlag = (USART_FIFOSTAT_TXNOTFULL_MASK), /*!< TXNOTFULL bit, sets if TX buffer is not full */
|
||||||
|
kUSART_RxFifoNotEmptyFlag = (USART_FIFOSTAT_RXNOTEMPTY_MASK), /*!< RXNOEMPTY bit, sets if RX buffer is not empty */
|
||||||
|
kUSART_RxFifoFullFlag = (USART_FIFOSTAT_RXFULL_MASK), /*!< RXFULL bit, sets if RX buffer is full */
|
||||||
|
kUSART_RxIdleFlag = (USART_STAT_RXIDLE_MASK << 16U), /*!< Receiver idle. */
|
||||||
|
kUSART_TxIdleFlag = (USART_STAT_TXIDLE_MASK << 16U), /*!< Transmitter idle. */
|
||||||
|
kUSART_CtsAssertFlag = (USART_STAT_CTS_MASK << 16U), /*!< CTS signal high. */
|
||||||
|
kUSART_CtsChangeFlag = (USART_STAT_DELTACTS_MASK << 16U), /*!< CTS signal changed interrupt status. */
|
||||||
|
kUSART_BreakDetectFlag = (USART_STAT_RXBRK_MASK), /*!< Break detected. Self cleared when rx pin goes high again. */
|
||||||
|
kUSART_BreakDetectChangeFlag = (USART_STAT_DELTARXBRK_MASK), /*!< Break detect change interrupt flag. A change in
|
||||||
|
the state of receiver break detection. */
|
||||||
|
kUSART_RxStartFlag = (USART_STAT_START_MASK), /*!< Rx start bit detected interrupt flag. */
|
||||||
|
kUSART_FramingErrorFlag = (USART_STAT_FRAMERRINT_MASK), /*!< Framing error interrupt flag. */
|
||||||
|
kUSART_ParityErrorFlag = (USART_STAT_PARITYERRINT_MASK), /*!< parity error interrupt flag. */
|
||||||
|
kUSART_NoiseErrorFlag = (USART_STAT_RXNOISEINT_MASK), /*!< Noise error interrupt flag. */
|
||||||
|
kUSART_AutobaudErrorFlag = (USART_STAT_ABERR_MASK), /*!< Auto baudrate error interrupt flag, caused by the baudrate
|
||||||
|
counter timeout before the end of start bit. */
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
kUSART_RxTimeoutFlag = (USART_FIFOSTAT_RXTIMEOUT_MASK), /*!< RXTIMEOUT bit, sets if RX FIFO Timeout. */
|
||||||
|
#endif
|
||||||
|
kUSART_AllClearFlags = kUSART_TxError | kUSART_RxError | kUSART_CtsChangeFlag | kUSART_BreakDetectChangeFlag |
|
||||||
|
kUSART_RxStartFlag | kUSART_FramingErrorFlag | kUSART_ParityErrorFlag |
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
kUSART_RxTimeoutFlag |
|
||||||
|
#endif
|
||||||
|
kUSART_NoiseErrorFlag | kUSART_AutobaudErrorFlag,
|
||||||
|
};
|
||||||
|
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
/*! @brief USART receive timeout configuration structure. */
|
||||||
|
typedef struct _usart_rx_timeout_config
|
||||||
|
{
|
||||||
|
bool enable; /*!< Enable RX timeout */
|
||||||
|
bool resetCounterOnEmpty; /*!< Enable RX timeout counter reset when RX FIFO becames empty. */
|
||||||
|
bool resetCounterOnReceive; /*!< Enable RX timeout counter reset when RX FIFO receives data from the transmitter
|
||||||
|
side. */
|
||||||
|
uint32_t counter; /*!< RX timeout counter*/
|
||||||
|
uint8_t prescaler; /*!< RX timeout prescaler*/
|
||||||
|
} usart_rx_timeout_config;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @brief USART configuration structure. */
|
||||||
|
typedef struct _usart_config
|
||||||
|
{
|
||||||
|
uint32_t baudRate_Bps; /*!< USART baud rate */
|
||||||
|
usart_parity_mode_t parityMode; /*!< Parity mode, disabled (default), even, odd */
|
||||||
|
usart_stop_bit_count_t stopBitCount; /*!< Number of stop bits, 1 stop bit (default) or 2 stop bits */
|
||||||
|
usart_data_len_t bitCountPerChar; /*!< Data length - 7 bit, 8 bit */
|
||||||
|
bool loopback; /*!< Enable peripheral loopback */
|
||||||
|
bool enableRx; /*!< Enable RX */
|
||||||
|
bool enableTx; /*!< Enable TX */
|
||||||
|
bool enableContinuousSCLK; /*!< USART continuous Clock generation enable in synchronous master mode. */
|
||||||
|
bool enableMode32k; /*!< USART uses 32 kHz clock from the RTC oscillator as the clock source. */
|
||||||
|
bool enableHardwareFlowControl; /*!< Enable hardware control RTS/CTS */
|
||||||
|
usart_txfifo_watermark_t txWatermark; /*!< txFIFO watermark */
|
||||||
|
usart_rxfifo_watermark_t rxWatermark; /*!< rxFIFO watermark */
|
||||||
|
usart_sync_mode_t syncMode; /*!< Transfer mode select - asynchronous, synchronous master, synchronous slave. */
|
||||||
|
usart_clock_polarity_t clockPolarity; /*!< Selects the clock polarity and sampling edge in synchronous mode. */
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
usart_rx_timeout_config rxTimeout; /*!< rx timeout configuration */
|
||||||
|
#endif
|
||||||
|
} usart_config_t;
|
||||||
|
|
||||||
|
/*! @brief USART transfer structure. */
|
||||||
|
typedef struct _usart_transfer
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Use separate TX and RX data pointer, because TX data is const data.
|
||||||
|
* The member data is kept for backward compatibility.
|
||||||
|
*/
|
||||||
|
union
|
||||||
|
{
|
||||||
|
uint8_t *data; /*!< The buffer of data to be transfer.*/
|
||||||
|
uint8_t *rxData; /*!< The buffer to receive data. */
|
||||||
|
const uint8_t *txData; /*!< The buffer of data to be sent. */
|
||||||
|
};
|
||||||
|
size_t dataSize; /*!< The byte count to be transfer. */
|
||||||
|
} usart_transfer_t;
|
||||||
|
|
||||||
|
/* Forward declaration of the handle typedef. */
|
||||||
|
typedef struct _usart_handle usart_handle_t;
|
||||||
|
|
||||||
|
/*! @brief USART transfer callback function. */
|
||||||
|
typedef void (*usart_transfer_callback_t)(USART_Type *base, usart_handle_t *handle, status_t status, void *userData);
|
||||||
|
|
||||||
|
/*! @brief USART handle structure. */
|
||||||
|
struct _usart_handle
|
||||||
|
{
|
||||||
|
const uint8_t *volatile txData; /*!< Address of remaining data to send. */
|
||||||
|
volatile size_t txDataSize; /*!< Size of the remaining data to send. */
|
||||||
|
size_t txDataSizeAll; /*!< Size of the data to send out. */
|
||||||
|
uint8_t *volatile rxData; /*!< Address of remaining data to receive. */
|
||||||
|
volatile size_t rxDataSize; /*!< Size of the remaining data to receive. */
|
||||||
|
size_t rxDataSizeAll; /*!< Size of the data to receive. */
|
||||||
|
|
||||||
|
uint8_t *rxRingBuffer; /*!< Start address of the receiver ring buffer. */
|
||||||
|
size_t rxRingBufferSize; /*!< Size of the ring buffer. */
|
||||||
|
volatile uint16_t rxRingBufferHead; /*!< Index for the driver to store received data into ring buffer. */
|
||||||
|
volatile uint16_t rxRingBufferTail; /*!< Index for the user to get data from the ring buffer. */
|
||||||
|
|
||||||
|
usart_transfer_callback_t callback; /*!< Callback function. */
|
||||||
|
void *userData; /*!< USART callback function parameter.*/
|
||||||
|
|
||||||
|
volatile uint8_t txState; /*!< TX transfer state. */
|
||||||
|
volatile uint8_t rxState; /*!< RX transfer state */
|
||||||
|
|
||||||
|
uint8_t txWatermark; /*!< txFIFO watermark */
|
||||||
|
uint8_t rxWatermark; /*!< rxFIFO watermark */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*! @brief Typedef for usart interrupt handler. */
|
||||||
|
typedef void (*flexcomm_usart_irq_handler_t)(USART_Type *base, usart_handle_t *handle);
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* API
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif /* _cplusplus */
|
||||||
|
|
||||||
|
/*! @brief Returns instance number for USART peripheral base address. */
|
||||||
|
uint32_t USART_GetInstance(USART_Type *base);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Initialization and deinitialization
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Initializes a USART instance with user configuration structure and peripheral clock.
|
||||||
|
*
|
||||||
|
* This function configures the USART module with the user-defined settings. The user can configure the configuration
|
||||||
|
* structure and also get the default configuration by using the USART_GetDefaultConfig() function.
|
||||||
|
* Example below shows how to use this API to configure USART.
|
||||||
|
* @code
|
||||||
|
* usart_config_t usartConfig;
|
||||||
|
* usartConfig.baudRate_Bps = 115200U;
|
||||||
|
* usartConfig.parityMode = kUSART_ParityDisabled;
|
||||||
|
* usartConfig.stopBitCount = kUSART_OneStopBit;
|
||||||
|
* USART_Init(USART1, &usartConfig, 20000000U);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param config Pointer to user-defined configuration structure.
|
||||||
|
* @param srcClock_Hz USART clock source frequency in HZ.
|
||||||
|
* @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
|
||||||
|
* @retval kStatus_InvalidArgument USART base address is not valid
|
||||||
|
* @retval kStatus_Success Status USART initialize succeed
|
||||||
|
*/
|
||||||
|
status_t USART_Init(USART_Type *base, const usart_config_t *config, uint32_t srcClock_Hz);
|
||||||
|
#if defined(FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG) && FSL_FEATURE_USART_HAS_FIFORXTIMEOUTCFG
|
||||||
|
/*!
|
||||||
|
* @brief Calculate the USART instance RX timeout prescaler and counter.
|
||||||
|
*
|
||||||
|
* This function for calculate the USART RXFIFO timeout config. This function is used to calculate
|
||||||
|
* suitable prescaler and counter for target_us.
|
||||||
|
* @code
|
||||||
|
* usart_config_t config;
|
||||||
|
* config.rxWatermark = kUSART_RxFifo2;
|
||||||
|
* config.rxTimeout.enable = true;
|
||||||
|
* config.rxTimeout.resetCounterOnEmpty = true;
|
||||||
|
* config.rxTimeout.resetCounterOnReceive = true;
|
||||||
|
* USART_CalcTimeoutConfig(200U, &config.rxTimeout.prescaler, &config.rxTimeout.counter,
|
||||||
|
* CLOCK_GetFreq(kCLOCK_BusClk));
|
||||||
|
* @endcode
|
||||||
|
* @param target_us Time for rx timeout unit us.
|
||||||
|
* @param rxTimeoutPrescaler The prescaler to be setted after function.
|
||||||
|
* @param rxTimeoutcounter The counter to be setted after function.
|
||||||
|
* @param srcClock_Hz The clockSrc for rx timeout.
|
||||||
|
*/
|
||||||
|
void USART_CalcTimeoutConfig(uint32_t target_us,
|
||||||
|
uint8_t *rxTimeoutPrescaler,
|
||||||
|
uint32_t *rxTimeoutcounter,
|
||||||
|
uint32_t srcClock_Hz);
|
||||||
|
/*!
|
||||||
|
* @brief Sets the USART instance RX timeout config.
|
||||||
|
*
|
||||||
|
* This function configures the USART RXFIFO timeout config. This function is used to config
|
||||||
|
* the USART RXFIFO timeout config after the USART module is initialized by the USART_Init.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param config pointer to receive timeout configuration structure.
|
||||||
|
*/
|
||||||
|
void USART_SetRxTimeoutConfig(USART_Type *base, const usart_rx_timeout_config *config);
|
||||||
|
#endif
|
||||||
|
/*!
|
||||||
|
* @brief Deinitializes a USART instance.
|
||||||
|
*
|
||||||
|
* This function waits for TX complete, disables TX and RX, and disables the USART clock.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
*/
|
||||||
|
void USART_Deinit(USART_Type *base);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets the default configuration structure.
|
||||||
|
*
|
||||||
|
* This function initializes the USART configuration structure to a default value. The default
|
||||||
|
* values are:
|
||||||
|
* usartConfig->baudRate_Bps = 115200U;
|
||||||
|
* usartConfig->parityMode = kUSART_ParityDisabled;
|
||||||
|
* usartConfig->stopBitCount = kUSART_OneStopBit;
|
||||||
|
* usartConfig->bitCountPerChar = kUSART_8BitsPerChar;
|
||||||
|
* usartConfig->loopback = false;
|
||||||
|
* usartConfig->enableTx = false;
|
||||||
|
* usartConfig->enableRx = false;
|
||||||
|
*
|
||||||
|
* @param config Pointer to configuration structure.
|
||||||
|
*/
|
||||||
|
void USART_GetDefaultConfig(usart_config_t *config);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets the USART instance baud rate.
|
||||||
|
*
|
||||||
|
* This function configures the USART module baud rate. This function is used to update
|
||||||
|
* the USART module baud rate after the USART module is initialized by the USART_Init.
|
||||||
|
* @code
|
||||||
|
* USART_SetBaudRate(USART1, 115200U, 20000000U);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param baudrate_Bps USART baudrate to be set.
|
||||||
|
* @param srcClock_Hz USART clock source frequency in HZ.
|
||||||
|
* @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
|
||||||
|
* @retval kStatus_Success Set baudrate succeed.
|
||||||
|
* @retval kStatus_InvalidArgument One or more arguments are invalid.
|
||||||
|
*/
|
||||||
|
status_t USART_SetBaudRate(USART_Type *base, uint32_t baudrate_Bps, uint32_t srcClock_Hz);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable 32 kHz mode which USART uses clock from the RTC oscillator as the clock source
|
||||||
|
*
|
||||||
|
* Please note that in order to use a 32 kHz clock to operate USART properly, the RTC oscillator
|
||||||
|
* and its 32 kHz output must be manully enabled by user, by calling RTC_Init and setting
|
||||||
|
* SYSCON_RTCOSCCTRL_EN bit to 1.
|
||||||
|
* And in 32kHz clocking mode the USART can only work at 9600 baudrate or at the baudrate that
|
||||||
|
* 9600 can evenly divide, eg: 4800, 3200.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param baudRate_Bps USART baudrate to be set..
|
||||||
|
* @param enableMode32k true is 32k mode, false is normal mode.
|
||||||
|
* @param srcClock_Hz USART clock source frequency in HZ.
|
||||||
|
* @retval kStatus_USART_BaudrateNotSupport Baudrate is not support in current clock source.
|
||||||
|
* @retval kStatus_Success Set baudrate succeed.
|
||||||
|
* @retval kStatus_InvalidArgument One or more arguments are invalid.
|
||||||
|
*/
|
||||||
|
status_t USART_Enable32kMode(USART_Type *base, uint32_t baudRate_Bps, bool enableMode32k, uint32_t srcClock_Hz);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable 9-bit data mode for USART.
|
||||||
|
*
|
||||||
|
* This function set the 9-bit mode for USART module. The 9th bit is not used for parity thus can be modified by user.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param enable true to enable, false to disable.
|
||||||
|
*/
|
||||||
|
void USART_Enable9bitMode(USART_Type *base, bool enable);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set the USART slave address.
|
||||||
|
*
|
||||||
|
* This function configures the address for USART module that works as slave in 9-bit data mode. When the address
|
||||||
|
* detection is enabled, the frame it receices with MSB being 1 is considered as an address frame, otherwise it is
|
||||||
|
* considered as data frame. Once the address frame matches slave's own addresses, this slave is addressed. This
|
||||||
|
* address frame and its following data frames are stored in the receive buffer, otherwise the frames will be discarded.
|
||||||
|
* To un-address a slave, just send an address frame with unmatched address.
|
||||||
|
*
|
||||||
|
* @note Any USART instance joined in the multi-slave system can work as slave. The position of the address mark is the
|
||||||
|
* same as the parity bit when parity is enabled for 8 bit and 9 bit data formats.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param address USART slave address.
|
||||||
|
*/
|
||||||
|
static inline void USART_SetMatchAddress(USART_Type *base, uint8_t address)
|
||||||
|
{
|
||||||
|
/* Configure match address. */
|
||||||
|
base->ADDR = (uint32_t)address;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable the USART match address feature.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param match true to enable match address, false to disable.
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableMatchAddress(USART_Type *base, bool match)
|
||||||
|
{
|
||||||
|
/* Configure match address enable bit. */
|
||||||
|
if (match)
|
||||||
|
{
|
||||||
|
base->CFG |= (uint32_t)USART_CFG_AUTOADDR_MASK;
|
||||||
|
base->CTL |= (uint32_t)USART_CTL_ADDRDET_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base->CFG &= ~(uint32_t)USART_CFG_AUTOADDR_MASK;
|
||||||
|
base->CTL &= ~(uint32_t)USART_CTL_ADDRDET_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Status
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get USART status flags.
|
||||||
|
*
|
||||||
|
* This function get all USART status flags, the flags are returned as the logical
|
||||||
|
* OR value of the enumerators @ref _usart_flags. To check a specific status,
|
||||||
|
* compare the return value with enumerators in @ref _usart_flags.
|
||||||
|
* For example, to check whether the TX is empty:
|
||||||
|
* @code
|
||||||
|
* if (kUSART_TxFifoNotFullFlag & USART_GetStatusFlags(USART1))
|
||||||
|
* {
|
||||||
|
* ...
|
||||||
|
* }
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @return USART status flags which are ORed by the enumerators in the _usart_flags.
|
||||||
|
*/
|
||||||
|
static inline uint32_t USART_GetStatusFlags(USART_Type *base)
|
||||||
|
{
|
||||||
|
return (base->FIFOSTAT & 0xFF0000FFUL) | (base->STAT & 0xFFUL) << 16U | (base->STAT & 0xFFFF00UL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Clear USART status flags.
|
||||||
|
*
|
||||||
|
* This function clear supported USART status flags
|
||||||
|
* Flags that can be cleared or set are:
|
||||||
|
* kUSART_TxError
|
||||||
|
* kUSART_RxError
|
||||||
|
* For example:
|
||||||
|
* @code
|
||||||
|
* USART_ClearStatusFlags(USART1, kUSART_TxError | kUSART_RxError)
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param mask status flags to be cleared.
|
||||||
|
*/
|
||||||
|
static inline void USART_ClearStatusFlags(USART_Type *base, uint32_t mask)
|
||||||
|
{
|
||||||
|
mask &= (uint32_t)kUSART_AllClearFlags;
|
||||||
|
/* Clear the clearable status in STAT register. */
|
||||||
|
base->STAT = (mask & 0xFFFF00UL) | ((mask & 0xFF0000UL) >> 16U);
|
||||||
|
/* Only TXERR, RXERR fields support write. Remaining fields should be set to zero */
|
||||||
|
base->FIFOSTAT = mask & (USART_FIFOSTAT_TXERR_MASK | USART_FIFOSTAT_RXERR_MASK);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Interrupts
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*!
|
||||||
|
* @brief Enables USART interrupts according to the provided mask.
|
||||||
|
*
|
||||||
|
* This function enables the USART interrupts according to the provided mask. The mask
|
||||||
|
* is a logical OR of enumeration members. See @ref _usart_interrupt_enable.
|
||||||
|
* For example, to enable TX empty interrupt and RX full interrupt:
|
||||||
|
* @code
|
||||||
|
* USART_EnableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param mask The interrupts to enable. Logical OR of @ref _usart_interrupt_enable.
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableInterrupts(USART_Type *base, uint32_t mask)
|
||||||
|
{
|
||||||
|
mask &= (uint32_t)kUSART_AllInterruptEnables;
|
||||||
|
base->INTENSET = (mask & 0x1FF00UL) | ((mask & 0xFF0000UL) >> 16U);
|
||||||
|
base->FIFOINTENSET = mask & 0xF00000FUL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Disables USART interrupts according to a provided mask.
|
||||||
|
*
|
||||||
|
* This function disables the USART interrupts according to a provided mask. The mask
|
||||||
|
* is a logical OR of enumeration members. See @ref _usart_interrupt_enable.
|
||||||
|
* This example shows how to disable the TX empty interrupt and RX full interrupt:
|
||||||
|
* @code
|
||||||
|
* USART_DisableInterrupts(USART1, kUSART_TxLevelInterruptEnable | kUSART_RxLevelInterruptEnable);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param mask The interrupts to disable. Logical OR of @ref _usart_interrupt_enable.
|
||||||
|
*/
|
||||||
|
static inline void USART_DisableInterrupts(USART_Type *base, uint32_t mask)
|
||||||
|
{
|
||||||
|
mask &= (uint32_t)kUSART_AllInterruptEnables;
|
||||||
|
base->INTENCLR = (mask & 0x1FF00UL) | ((mask & 0xFF0000UL) >> 16U);
|
||||||
|
base->FIFOINTENCLR = mask & 0xFUL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Returns enabled USART interrupts.
|
||||||
|
*
|
||||||
|
* This function returns the enabled USART interrupts.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
*/
|
||||||
|
static inline uint32_t USART_GetEnabledInterrupts(USART_Type *base)
|
||||||
|
{
|
||||||
|
return (base->INTENSET & 0x1FF00UL) | ((base->INTENSET & 0xFFUL) << 16UL) | (base->FIFOINTENSET & 0xFUL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable DMA for Tx
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableTxDMA(USART_Type *base, bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
base->FIFOCFG |= USART_FIFOCFG_DMATX_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base->FIFOCFG &= ~(USART_FIFOCFG_DMATX_MASK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable DMA for Rx
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableRxDMA(USART_Type *base, bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
base->FIFOCFG |= USART_FIFOCFG_DMARX_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base->FIFOCFG &= ~(USART_FIFOCFG_DMARX_MASK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable CTS.
|
||||||
|
* This function will determine whether CTS is used for flow control.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param enable Enable CTS or not, true for enable and false for disable.
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableCTS(USART_Type *base, bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
base->CFG |= USART_CFG_CTSEN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base->CFG &= ~USART_CFG_CTSEN_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Continuous Clock generation.
|
||||||
|
* By default, SCLK is only output while data is being transmitted in synchronous mode.
|
||||||
|
* Enable this funciton, SCLK will run continuously in synchronous mode, allowing
|
||||||
|
* characters to be received on Un_RxD independently from transmission on Un_TXD).
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param enable Enable Continuous Clock generation mode or not, true for enable and false for disable.
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableContinuousSCLK(USART_Type *base, bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
base->CTL |= USART_CTL_CC_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base->CTL &= ~USART_CTL_CC_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable Continuous Clock generation bit auto clear.
|
||||||
|
* While enable this cuntion, the Continuous Clock bit is automatically cleared when a complete
|
||||||
|
* character has been received. This bit is cleared at the same time.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param enable Enable auto clear or not, true for enable and false for disable.
|
||||||
|
*/
|
||||||
|
static inline void USART_EnableAutoClearSCLK(USART_Type *base, bool enable)
|
||||||
|
{
|
||||||
|
if (enable)
|
||||||
|
{
|
||||||
|
base->CTL |= USART_CTL_CLRCCONRX_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
base->CTL &= ~USART_CTL_CLRCCONRX_MASK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets the rx FIFO watermark.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param water Rx FIFO watermark.
|
||||||
|
*/
|
||||||
|
static inline void USART_SetRxFifoWatermark(USART_Type *base, uint8_t water)
|
||||||
|
{
|
||||||
|
assert(water <= (USART_FIFOTRIG_RXLVL_MASK >> USART_FIFOTRIG_RXLVL_SHIFT));
|
||||||
|
base->FIFOTRIG = (base->FIFOTRIG & ~USART_FIFOTRIG_RXLVL_MASK) | USART_FIFOTRIG_RXLVL(water);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets the tx FIFO watermark.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param water Tx FIFO watermark.
|
||||||
|
*/
|
||||||
|
static inline void USART_SetTxFifoWatermark(USART_Type *base, uint8_t water)
|
||||||
|
{
|
||||||
|
assert(water <= (USART_FIFOTRIG_TXLVL_MASK >> USART_FIFOTRIG_TXLVL_SHIFT));
|
||||||
|
base->FIFOTRIG = (base->FIFOTRIG & ~USART_FIFOTRIG_TXLVL_MASK) | USART_FIFOTRIG_TXLVL(water);
|
||||||
|
}
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Bus Operations
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Writes to the FIFOWR register.
|
||||||
|
*
|
||||||
|
* This function writes data to the txFIFO directly. The upper layer must ensure
|
||||||
|
* that txFIFO has space for data to write before calling this function.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param data The byte to write.
|
||||||
|
*/
|
||||||
|
static inline void USART_WriteByte(USART_Type *base, uint8_t data)
|
||||||
|
{
|
||||||
|
base->FIFOWR = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Reads the FIFORD register directly.
|
||||||
|
*
|
||||||
|
* This function reads data from the rxFIFO directly. The upper layer must
|
||||||
|
* ensure that the rxFIFO is not empty before calling this function.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @return The byte read from USART data register.
|
||||||
|
*/
|
||||||
|
static inline uint8_t USART_ReadByte(USART_Type *base)
|
||||||
|
{
|
||||||
|
return (uint8_t)base->FIFORD;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets the rx FIFO data count.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @return rx FIFO data count.
|
||||||
|
*/
|
||||||
|
static inline uint8_t USART_GetRxFifoCount(USART_Type *base)
|
||||||
|
{
|
||||||
|
return (uint8_t)((base->FIFOSTAT & USART_FIFOSTAT_RXLVL_MASK) >> USART_FIFOSTAT_RXLVL_SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Gets the tx FIFO data count.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @return tx FIFO data count.
|
||||||
|
*/
|
||||||
|
static inline uint8_t USART_GetTxFifoCount(USART_Type *base)
|
||||||
|
{
|
||||||
|
return (uint8_t)((base->FIFOSTAT & USART_FIFOSTAT_TXLVL_MASK) >> USART_FIFOSTAT_TXLVL_SHIFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Transmit an address frame in 9-bit data mode.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param address USART slave address.
|
||||||
|
*/
|
||||||
|
void USART_SendAddress(USART_Type *base, uint8_t address);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param data Start address of the data to write.
|
||||||
|
* @param length Size of the data to write.
|
||||||
|
* @retval kStatus_USART_Timeout Transmission timed out and was aborted.
|
||||||
|
* @retval kStatus_InvalidArgument Invalid argument.
|
||||||
|
* @retval kStatus_Success Successfully wrote all data.
|
||||||
|
*/
|
||||||
|
status_t USART_WriteBlocking(USART_Type *base, const uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Read 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 read data from the TX register.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param data Start address of the buffer to store the received data.
|
||||||
|
* @param length Size of the buffer.
|
||||||
|
* @retval kStatus_USART_FramingError Receiver overrun happened while receiving data.
|
||||||
|
* @retval kStatus_USART_ParityError Noise error happened while receiving data.
|
||||||
|
* @retval kStatus_USART_NoiseError Framing error happened while receiving data.
|
||||||
|
* @retval kStatus_USART_RxError Overflow or underflow rxFIFO happened.
|
||||||
|
* @retval kStatus_USART_Timeout Transmission timed out and was aborted.
|
||||||
|
* @retval kStatus_Success Successfully received all data.
|
||||||
|
*/
|
||||||
|
status_t USART_ReadBlocking(USART_Type *base, uint8_t *data, size_t length);
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @name Transactional
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Initializes the USART handle.
|
||||||
|
*
|
||||||
|
* This function initializes the USART handle which can be used for other USART
|
||||||
|
* transactional APIs. Usually, for a specified USART instance,
|
||||||
|
* call this API once to get the initialized handle.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @param callback The callback function.
|
||||||
|
* @param userData The parameter of the callback function.
|
||||||
|
*/
|
||||||
|
status_t USART_TransferCreateHandle(USART_Type *base,
|
||||||
|
usart_handle_t *handle,
|
||||||
|
usart_transfer_callback_t callback,
|
||||||
|
void *userData);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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 IRQ handler, the USART driver calls the callback
|
||||||
|
* function and passes the @ref kStatus_USART_TxIdle as status parameter.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @param xfer USART transfer structure. See #usart_transfer_t.
|
||||||
|
* @retval kStatus_Success Successfully start the data transmission.
|
||||||
|
* @retval kStatus_USART_TxBusy Previous transmission still not finished, data not all written to TX register yet.
|
||||||
|
* @retval kStatus_InvalidArgument Invalid argument.
|
||||||
|
*/
|
||||||
|
status_t USART_TransferSendNonBlocking(USART_Type *base, usart_handle_t *handle, usart_transfer_t *xfer);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Sets up the RX ring buffer.
|
||||||
|
*
|
||||||
|
* This function sets up the RX ring buffer to a specific USART handle.
|
||||||
|
*
|
||||||
|
* When the RX ring buffer is used, data received are stored into the ring buffer even when the
|
||||||
|
* user doesn't call the USART_TransferReceiveNonBlocking() API. If there is already data received
|
||||||
|
* in the ring buffer, the user can get the received data from the ring buffer directly.
|
||||||
|
*
|
||||||
|
* @note When using the RX ring buffer, one byte is reserved for internal use. In other
|
||||||
|
* words, if @p ringBufferSize is 32, then only 31 bytes are used for saving data.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @param ringBuffer Start address of the ring buffer for background receiving. Pass NULL to disable the ring buffer.
|
||||||
|
* @param ringBufferSize size of the ring buffer.
|
||||||
|
*/
|
||||||
|
void USART_TransferStartRingBuffer(USART_Type *base,
|
||||||
|
usart_handle_t *handle,
|
||||||
|
uint8_t *ringBuffer,
|
||||||
|
size_t ringBufferSize);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Aborts the background transfer and uninstalls the ring buffer.
|
||||||
|
*
|
||||||
|
* This function aborts the background transfer and uninstalls the ring buffer.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
*/
|
||||||
|
void USART_TransferStopRingBuffer(USART_Type *base, usart_handle_t *handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get the length of received data in RX ring buffer.
|
||||||
|
*
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @return Length of received data in RX ring buffer.
|
||||||
|
*/
|
||||||
|
size_t USART_TransferGetRxRingBufferLength(usart_handle_t *handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Aborts the interrupt-driven data transmit.
|
||||||
|
*
|
||||||
|
* This function aborts the interrupt driven data sending. The user can get the remainBtyes to find out
|
||||||
|
* how many bytes are still not sent out.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
*/
|
||||||
|
void USART_TransferAbortSend(USART_Type *base, usart_handle_t *handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get the number of bytes that have been sent out to bus.
|
||||||
|
*
|
||||||
|
* This function gets the number of bytes that have been sent out to bus by interrupt method.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @param count Send bytes count.
|
||||||
|
* @retval kStatus_NoTransferInProgress No send in progress.
|
||||||
|
* @retval kStatus_InvalidArgument Parameter is invalid.
|
||||||
|
* @retval kStatus_Success Get successfully through the parameter \p count;
|
||||||
|
*/
|
||||||
|
status_t USART_TransferGetSendCount(USART_Type *base, usart_handle_t *handle, uint32_t *count);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @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 without waiting for all data to be received.
|
||||||
|
* If the RX ring buffer is used and not empty, the data in the ring buffer is copied and
|
||||||
|
* the parameter @p receivedBytes shows how many bytes are copied from the ring buffer.
|
||||||
|
* After copying, if the data in the ring buffer is not enough to read, the receive
|
||||||
|
* request is saved by the USART driver. When the new data arrives, the receive request
|
||||||
|
* is serviced first. When all data is received, the USART driver notifies the upper layer
|
||||||
|
* through a callback function and passes the status parameter @ref kStatus_USART_RxIdle.
|
||||||
|
* For example, the upper layer needs 10 bytes but there are only 5 bytes in the ring buffer.
|
||||||
|
* The 5 bytes are copied to the xfer->data and this function returns with the
|
||||||
|
* parameter @p receivedBytes set to 5. For the left 5 bytes, newly arrived data is
|
||||||
|
* saved from the xfer->data[5]. When 5 bytes are received, the USART driver notifies the upper layer.
|
||||||
|
* If the RX ring buffer is not enabled, this function enables the RX and RX interrupt
|
||||||
|
* to receive data to the xfer->data. When all data is received, the upper layer is notified.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @param xfer USART transfer structure, see #usart_transfer_t.
|
||||||
|
* @param receivedBytes Bytes received from the ring buffer directly.
|
||||||
|
* @retval kStatus_Success Successfully queue the transfer into transmit queue.
|
||||||
|
* @retval kStatus_USART_RxBusy Previous receive request is not finished.
|
||||||
|
* @retval kStatus_InvalidArgument Invalid argument.
|
||||||
|
*/
|
||||||
|
status_t USART_TransferReceiveNonBlocking(USART_Type *base,
|
||||||
|
usart_handle_t *handle,
|
||||||
|
usart_transfer_t *xfer,
|
||||||
|
size_t *receivedBytes);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Aborts the interrupt-driven data receiving.
|
||||||
|
*
|
||||||
|
* This function aborts the interrupt-driven data receiving. The user can get the remainBytes to find out
|
||||||
|
* how many bytes not received yet.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
*/
|
||||||
|
void USART_TransferAbortReceive(USART_Type *base, usart_handle_t *handle);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get the number of bytes that have been received.
|
||||||
|
*
|
||||||
|
* This function gets the number of bytes that have been received.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
* @param count Receive bytes count.
|
||||||
|
* @retval kStatus_NoTransferInProgress No receive in progress.
|
||||||
|
* @retval kStatus_InvalidArgument Parameter is invalid.
|
||||||
|
* @retval kStatus_Success Get successfully through the parameter \p count;
|
||||||
|
*/
|
||||||
|
status_t USART_TransferGetReceiveCount(USART_Type *base, usart_handle_t *handle, uint32_t *count);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief USART IRQ handle function.
|
||||||
|
*
|
||||||
|
* This function handles the USART transmit and receive IRQ request.
|
||||||
|
*
|
||||||
|
* @param base USART peripheral base address.
|
||||||
|
* @param handle USART handle pointer.
|
||||||
|
*/
|
||||||
|
void USART_TransferHandleIRQ(USART_Type *base, usart_handle_t *handle);
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! @}*/
|
||||||
|
|
||||||
|
#endif /* FSL_USART_H_ */
|
||||||
10
drivers/Inc/led.h
Normal file
10
drivers/Inc/led.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef __LED_H_
|
||||||
|
#define __LED_H_
|
||||||
|
|
||||||
|
#include "fsl_device_registers.h"
|
||||||
|
void led_init(void);
|
||||||
|
void led_on(void);
|
||||||
|
void led_off(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __LED__H__ */
|
||||||
7
drivers/Inc/uart.h
Normal file
7
drivers/Inc/uart.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef __UART_H__
|
||||||
|
#define __UART_H__
|
||||||
|
|
||||||
|
extern void uart_init(void);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* __UART_H__ */
|
||||||
1101
drivers/Src/fsl_adapter_usart.c
Normal file
1101
drivers/Src/fsl_adapter_usart.c
Normal file
File diff suppressed because it is too large
Load Diff
88
drivers/Src/fsl_assert.c
Normal file
88
drivers/Src/fsl_assert.c
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2017, 2022-2023 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
#include "fsl_assert.h"
|
||||||
|
#include "fsl_debug_console.h"
|
||||||
|
|
||||||
|
/* User can implement its own asser handler (dump logs, registers, etc) by reimplementing the function fsl_assert_hook() */
|
||||||
|
__attribute__ ((weak)) int fsl_assert_hook(const char *failedExpr, const char *file, int line)
|
||||||
|
{
|
||||||
|
(void)failedExpr;
|
||||||
|
(void)file;
|
||||||
|
(void)line;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#if (defined(__CC_ARM)) || (defined(__ARMCC_VERSION)) || (defined(__ICCARM__))
|
||||||
|
void __aeabi_assert(const char *failedExpr, const char *file, int line)
|
||||||
|
{
|
||||||
|
#if SDK_DEBUGCONSOLE == DEBUGCONSOLE_DISABLE
|
||||||
|
PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
|
||||||
|
#else
|
||||||
|
(void)PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" \n", failedExpr, file, line);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
(void)fsl_assert_hook(failedExpr, file, line);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
__BKPT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#elif (defined(__GNUC__))
|
||||||
|
#if defined(__REDLIB__)
|
||||||
|
void __assertion_failed(char *failedExpr)
|
||||||
|
{
|
||||||
|
const char *file = NULL;
|
||||||
|
int line = -1;
|
||||||
|
|
||||||
|
(void)PRINTF("ASSERT ERROR \" %s \n", failedExpr);
|
||||||
|
|
||||||
|
(void)fsl_assert_hook(failedExpr, file, line);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
__BKPT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
void __assert_func(const char *file, int line, const char *func, const char *failedExpr)
|
||||||
|
{
|
||||||
|
(void)PRINTF("ASSERT ERROR \" %s \": file \"%s\" Line \"%d\" function name \"%s\" \n", failedExpr, file, line,
|
||||||
|
func);
|
||||||
|
|
||||||
|
(void)fsl_assert_hook(failedExpr, file, line);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
__BKPT(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* defined(__REDLIB__) */
|
||||||
|
#else /* (defined(__CC_ARM) || (defined(__ICCARM__)) || (defined(__ARMCC_VERSION)) */
|
||||||
|
|
||||||
|
#if (defined(__DSC__) && defined(__CW__))
|
||||||
|
|
||||||
|
void __msl_assertion_failed(char const *failedExpr, char const *file, char const *func, int line)
|
||||||
|
{
|
||||||
|
PRINTF("\r\nASSERT ERROR\r\n");
|
||||||
|
PRINTF(" File : %s\r\n", file);
|
||||||
|
PRINTF(" Function : %s\r\n", func); /*compiler not support func name yet*/
|
||||||
|
PRINTF(" Line : %u\r\n", (uint32_t)line);
|
||||||
|
PRINTF(" failedExpr: %s\r\n", failedExpr);
|
||||||
|
asm(DEBUGHLT);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* (defined(__DSC__) && defined (__CW__)) */
|
||||||
|
|
||||||
|
#endif /* (defined(__CC_ARM) || (defined(__ICCARM__)) || (defined(__ARMCC_VERSION)) */
|
||||||
|
#endif /* NDEBUG */
|
||||||
2137
drivers/Src/fsl_clock.c
Normal file
2137
drivers/Src/fsl_clock.c
Normal file
File diff suppressed because it is too large
Load Diff
85
drivers/Src/fsl_common.c
Normal file
85
drivers/Src/fsl_common.c
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2021 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
|
||||||
|
|
||||||
|
#if !((defined(__DSC__) && defined(__CW__)))
|
||||||
|
void *SDK_Malloc(size_t size, size_t alignbytes)
|
||||||
|
{
|
||||||
|
mem_align_cb_t *p_cb = NULL;
|
||||||
|
uint32_t alignedsize;
|
||||||
|
|
||||||
|
/* Check overflow. */
|
||||||
|
alignedsize = (uint32_t)(unsigned int)SDK_SIZEALIGN(size, alignbytes);
|
||||||
|
if (alignedsize < size)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alignedsize > SIZE_MAX - alignbytes - sizeof(mem_align_cb_t))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
alignedsize += alignbytes + (uint32_t)sizeof(mem_align_cb_t);
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
void *pointer_value;
|
||||||
|
uintptr_t unsigned_value;
|
||||||
|
} p_align_addr, p_addr;
|
||||||
|
|
||||||
|
p_addr.pointer_value = malloc((size_t)alignedsize);
|
||||||
|
|
||||||
|
if (p_addr.pointer_value == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_align_addr.unsigned_value = SDK_SIZEALIGN(p_addr.unsigned_value + sizeof(mem_align_cb_t), alignbytes);
|
||||||
|
|
||||||
|
p_cb = (mem_align_cb_t *)(p_align_addr.unsigned_value - 4U);
|
||||||
|
p_cb->identifier = SDK_MEM_MAGIC_NUMBER;
|
||||||
|
p_cb->offset = (uint16_t)(p_align_addr.unsigned_value - p_addr.unsigned_value);
|
||||||
|
|
||||||
|
return p_align_addr.pointer_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDK_Free(void *ptr)
|
||||||
|
{
|
||||||
|
union
|
||||||
|
{
|
||||||
|
void *pointer_value;
|
||||||
|
uintptr_t unsigned_value;
|
||||||
|
} p_free;
|
||||||
|
p_free.pointer_value = ptr;
|
||||||
|
mem_align_cb_t *p_cb = (mem_align_cb_t *)(p_free.unsigned_value - 4U);
|
||||||
|
|
||||||
|
if (p_cb->identifier != SDK_MEM_MAGIC_NUMBER)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
p_free.unsigned_value = p_free.unsigned_value - p_cb->offset;
|
||||||
|
|
||||||
|
free(p_free.pointer_value);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
257
drivers/Src/fsl_common_arm.c
Normal file
257
drivers/Src/fsl_common_arm.c
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016-2021, 2023 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
|
||||||
|
/* Component ID definition, used by tools. */
|
||||||
|
#ifndef FSL_COMPONENT_ID
|
||||||
|
#define FSL_COMPONENT_ID "platform.drivers.common_arm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __GIC_PRIO_BITS
|
||||||
|
#if defined(ENABLE_RAM_VECTOR_TABLE)
|
||||||
|
uint32_t InstallIRQHandler(IRQn_Type irq, uint32_t irqHandler)
|
||||||
|
{
|
||||||
|
#ifdef __VECTOR_TABLE
|
||||||
|
#undef __VECTOR_TABLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* 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$$VECTOR_RAM$$ZI$$Limit[];
|
||||||
|
|
||||||
|
#define __VECTOR_TABLE Image$$VECTOR_ROM$$Base
|
||||||
|
#define __VECTOR_RAM Image$$VECTOR_RAM$$Base
|
||||||
|
#define __RAM_VECTOR_TABLE_SIZE (((uint32_t)Image$$VECTOR_RAM$$ZI$$Limit - (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[(int32_t)irq + 16];
|
||||||
|
/* make sure the __VECTOR_RAM is noncachable */
|
||||||
|
__VECTOR_RAM[(int32_t)irq + 16] = irqHandler;
|
||||||
|
|
||||||
|
EnableGlobalIRQ(irqMaskValue);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif /* ENABLE_RAM_VECTOR_TABLE. */
|
||||||
|
#endif /* __GIC_PRIO_BITS. */
|
||||||
|
|
||||||
|
#if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When FSL_FEATURE_POWERLIB_EXTEND is defined to non-zero value,
|
||||||
|
* powerlib should be used instead of these functions.
|
||||||
|
*/
|
||||||
|
#if !(defined(FSL_FEATURE_POWERLIB_EXTEND) && (FSL_FEATURE_POWERLIB_EXTEND != 0))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When the SYSCON STARTER registers are discontinuous, these functions are
|
||||||
|
* implemented in fsl_power.c.
|
||||||
|
*/
|
||||||
|
#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] = 1UL << intNumber;
|
||||||
|
(void)EnableIRQ(interrupt); /* also enable interrupt at NVIC */
|
||||||
|
}
|
||||||
|
|
||||||
|
void DisableDeepSleepIRQ(IRQn_Type interrupt)
|
||||||
|
{
|
||||||
|
uint32_t intNumber = (uint32_t)interrupt;
|
||||||
|
|
||||||
|
(void)DisableIRQ(interrupt); /* also disable interrupt at NVIC */
|
||||||
|
uint32_t index = 0;
|
||||||
|
|
||||||
|
while (intNumber >= 32u)
|
||||||
|
{
|
||||||
|
index++;
|
||||||
|
intNumber -= 32u;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCON->STARTERCLR[index] = 1UL << intNumber;
|
||||||
|
}
|
||||||
|
#endif /* FSL_FEATURE_SYSCON_STARTER_DISCONTINUOUS */
|
||||||
|
#endif /* FSL_FEATURE_POWERLIB_EXTEND */
|
||||||
|
#endif /* FSL_FEATURE_SOC_SYSCON_COUNT */
|
||||||
|
|
||||||
|
#if defined(DWT)
|
||||||
|
/* Use WDT. */
|
||||||
|
void MSDK_EnableCpuCycleCounter(void)
|
||||||
|
{
|
||||||
|
/* Make sure the DWT trace fucntion is enabled. */
|
||||||
|
if (CoreDebug_DEMCR_TRCENA_Msk != (CoreDebug_DEMCR_TRCENA_Msk & CoreDebug->DEMCR))
|
||||||
|
{
|
||||||
|
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* CYCCNT not supported on this device. */
|
||||||
|
assert(DWT_CTRL_NOCYCCNT_Msk != (DWT->CTRL & DWT_CTRL_NOCYCCNT_Msk));
|
||||||
|
|
||||||
|
/* Read CYCCNT directly if CYCCENT has already been enabled, otherwise enable CYCCENT first. */
|
||||||
|
if (DWT_CTRL_CYCCNTENA_Msk != (DWT_CTRL_CYCCNTENA_Msk & DWT->CTRL))
|
||||||
|
{
|
||||||
|
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t MSDK_GetCpuCycleCount(void)
|
||||||
|
{
|
||||||
|
return DWT->CYCCNT;
|
||||||
|
}
|
||||||
|
#endif /* defined(DWT) */
|
||||||
|
|
||||||
|
#if !(defined(SDK_DELAY_USE_DWT) && defined(DWT))
|
||||||
|
/* Use software loop. */
|
||||||
|
#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
|
||||||
|
}
|
||||||
|
#elif defined(__ARM_ARCH_8A__) /* This macro is ARMv8-A specific */
|
||||||
|
static void DelayLoop(uint32_t count)
|
||||||
|
{
|
||||||
|
__ASM volatile(" MOV X0, %0" : : "r"(count));
|
||||||
|
__ASM volatile(
|
||||||
|
"loop%=: \n"
|
||||||
|
" SUB X0, X0, #1 \n"
|
||||||
|
" CMP X0, #0 \n"
|
||||||
|
|
||||||
|
" BNE loop%= \n"
|
||||||
|
:
|
||||||
|
:
|
||||||
|
: "r0");
|
||||||
|
}
|
||||||
|
/* 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__) && !defined(__ARMCC_VERSION)
|
||||||
|
" SUB R0, R0, #1 \n"
|
||||||
|
#else
|
||||||
|
" SUBS R0, R0, #1 \n"
|
||||||
|
#endif
|
||||||
|
" CMP R0, #0 \n"
|
||||||
|
|
||||||
|
" BNE loop%= \n"
|
||||||
|
:
|
||||||
|
:
|
||||||
|
: "r0");
|
||||||
|
}
|
||||||
|
#endif /* defined(__CC_ARM) */
|
||||||
|
#endif /* defined(SDK_DELAY_USE_DWT) && defined(DWT) */
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Delay at least for some time.
|
||||||
|
* Please note that, if not uses DWT, this API will use while loop for delay, different run-time environments have
|
||||||
|
* effect on the delay time. If precise delay is needed, please enable DWT delay. The two parmeters delayTime_us and
|
||||||
|
* coreClock_Hz have limitation. For example, in the platform with 1GHz coreClock_Hz, the delayTime_us only supports
|
||||||
|
* up to 4294967 in current code. If long time delay is needed, please implement a new delay function.
|
||||||
|
*
|
||||||
|
* @param delayTime_us Delay time in unit of microsecond.
|
||||||
|
* @param coreClock_Hz Core clock frequency with Hz.
|
||||||
|
*/
|
||||||
|
void SDK_DelayAtLeastUs(uint32_t delayTime_us, uint32_t coreClock_Hz)
|
||||||
|
{
|
||||||
|
uint64_t count;
|
||||||
|
|
||||||
|
if (delayTime_us > 0U)
|
||||||
|
{
|
||||||
|
count = USEC_TO_COUNT(delayTime_us, coreClock_Hz);
|
||||||
|
|
||||||
|
assert(count <= UINT32_MAX);
|
||||||
|
|
||||||
|
#if defined(SDK_DELAY_USE_DWT) && defined(DWT) /* Use DWT for better accuracy */
|
||||||
|
|
||||||
|
MSDK_EnableCpuCycleCounter();
|
||||||
|
/* Calculate the count ticks. */
|
||||||
|
count += MSDK_GetCpuCycleCount();
|
||||||
|
|
||||||
|
if (count > UINT32_MAX)
|
||||||
|
{
|
||||||
|
count -= UINT32_MAX;
|
||||||
|
/* Wait for cyccnt overflow. */
|
||||||
|
while (count < MSDK_GetCpuCycleCount())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wait for cyccnt reach count value. */
|
||||||
|
while (count > MSDK_GetCpuCycleCount())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#if defined(__CORTEX_Axx) && ((__CORTEX_Axx == 53) || (__CORTEX_Axx == 55))
|
||||||
|
/*
|
||||||
|
* Cortex-A53/A55 execution throughput:
|
||||||
|
* - SUB/CMP: 2 instructions per cycle
|
||||||
|
* - BNE: 1 instruction per cycle
|
||||||
|
* So, each loop takes 2 CPU cycles.
|
||||||
|
*/
|
||||||
|
count = count / 2U;
|
||||||
|
#elif (__CORTEX_M == 7)
|
||||||
|
/* 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 1.5. Other M cores use
|
||||||
|
* divide 4. By the way, divide 1.5 or 4 could let the count lose precision, but it does
|
||||||
|
* not matter because other instructions outside while loop is enough to fill the time.
|
||||||
|
*/
|
||||||
|
count = count / 3U * 2U;
|
||||||
|
#else
|
||||||
|
count = count / 4U;
|
||||||
|
#endif
|
||||||
|
DelayLoop((uint32_t)count);
|
||||||
|
#endif /* defined(SDK_DELAY_USE_DWT) && defined(DWT) */
|
||||||
|
}
|
||||||
|
}
|
||||||
499
drivers/Src/fsl_component_generic_list.c
Normal file
499
drivers/Src/fsl_component_generic_list.c
Normal file
@ -0,0 +1,499 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018-2019, 2022 NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
*************************************************************************************
|
||||||
|
* Include
|
||||||
|
*************************************************************************************
|
||||||
|
********************************************************************************** */
|
||||||
|
#include "fsl_component_generic_list.h"
|
||||||
|
|
||||||
|
#if defined(OSA_USED)
|
||||||
|
#include "fsl_os_abstraction.h"
|
||||||
|
#if (defined(USE_RTOS) && (USE_RTOS > 0U))
|
||||||
|
#define LIST_ENTER_CRITICAL() \
|
||||||
|
OSA_SR_ALLOC(); \
|
||||||
|
OSA_ENTER_CRITICAL()
|
||||||
|
#define LIST_EXIT_CRITICAL() OSA_EXIT_CRITICAL()
|
||||||
|
#else
|
||||||
|
#define LIST_ENTER_CRITICAL() uint32_t regPrimask = DisableGlobalIRQ();
|
||||||
|
#define LIST_EXIT_CRITICAL() EnableGlobalIRQ(regPrimask);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define LIST_ENTER_CRITICAL() uint32_t regPrimask = DisableGlobalIRQ();
|
||||||
|
#define LIST_EXIT_CRITICAL() EnableGlobalIRQ(regPrimask);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static list_status_t LIST_Error_Check(list_handle_t list, list_element_handle_t newElement)
|
||||||
|
{
|
||||||
|
list_status_t listStatus = kLIST_Ok;
|
||||||
|
#if (defined(GENERIC_LIST_DUPLICATED_CHECKING) && (GENERIC_LIST_DUPLICATED_CHECKING > 0U))
|
||||||
|
list_element_handle_t element = list->head;
|
||||||
|
#endif
|
||||||
|
if ((list->max != 0U) && (list->max == list->size))
|
||||||
|
{
|
||||||
|
listStatus = kLIST_Full; /*List is full*/
|
||||||
|
}
|
||||||
|
#if (defined(GENERIC_LIST_DUPLICATED_CHECKING) && (GENERIC_LIST_DUPLICATED_CHECKING > 0U))
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (element != NULL) /*Scan list*/
|
||||||
|
{
|
||||||
|
/* Determine if element is duplicated */
|
||||||
|
if (element == newElement)
|
||||||
|
{
|
||||||
|
listStatus = kLIST_DuplicateError;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
element = element->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return listStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
*************************************************************************************
|
||||||
|
* Public functions
|
||||||
|
*************************************************************************************
|
||||||
|
********************************************************************************** */
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \brief Initializes 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 = 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 listElement)
|
||||||
|
{
|
||||||
|
return listElement->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 listElement)
|
||||||
|
{
|
||||||
|
LIST_ENTER_CRITICAL();
|
||||||
|
list_status_t listStatus = kLIST_Ok;
|
||||||
|
|
||||||
|
listStatus = LIST_Error_Check(list, listElement);
|
||||||
|
if (listStatus == kLIST_Ok) /* Avoiding list status error */
|
||||||
|
{
|
||||||
|
if (list->size == 0U)
|
||||||
|
{
|
||||||
|
list->head = listElement;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list->tail->next = listElement;
|
||||||
|
}
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
#else
|
||||||
|
listElement->prev = list->tail;
|
||||||
|
#endif
|
||||||
|
listElement->list = list;
|
||||||
|
listElement->next = NULL;
|
||||||
|
list->tail = listElement;
|
||||||
|
list->size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_EXIT_CRITICAL();
|
||||||
|
return listStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \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 listElement)
|
||||||
|
{
|
||||||
|
LIST_ENTER_CRITICAL();
|
||||||
|
list_status_t listStatus = kLIST_Ok;
|
||||||
|
|
||||||
|
listStatus = LIST_Error_Check(list, listElement);
|
||||||
|
if (listStatus == kLIST_Ok) /* Avoiding list status error */
|
||||||
|
{
|
||||||
|
/* Links element to the head of the list */
|
||||||
|
if (list->size == 0U)
|
||||||
|
{
|
||||||
|
list->tail = listElement;
|
||||||
|
}
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
#else
|
||||||
|
else
|
||||||
|
{
|
||||||
|
list->head->prev = listElement;
|
||||||
|
}
|
||||||
|
listElement->prev = NULL;
|
||||||
|
#endif
|
||||||
|
listElement->list = list;
|
||||||
|
listElement->next = list->head;
|
||||||
|
list->head = listElement;
|
||||||
|
list->size++;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_EXIT_CRITICAL();
|
||||||
|
return listStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \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 listElement;
|
||||||
|
|
||||||
|
LIST_ENTER_CRITICAL();
|
||||||
|
|
||||||
|
if ((NULL == list) || (list->size == 0U))
|
||||||
|
{
|
||||||
|
listElement = NULL; /*LIST_ is empty*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listElement = list->head;
|
||||||
|
list->size--;
|
||||||
|
if (list->size == 0U)
|
||||||
|
{
|
||||||
|
list->tail = NULL;
|
||||||
|
}
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
#else
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listElement->next->prev = NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
listElement->list = NULL;
|
||||||
|
list->head = listElement->next; /*Is NULL if element is head*/
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_EXIT_CRITICAL();
|
||||||
|
return listElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \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 listElement)
|
||||||
|
{
|
||||||
|
return listElement->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 listElement)
|
||||||
|
{
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
return NULL;
|
||||||
|
#else
|
||||||
|
return listElement->prev;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \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 listElement)
|
||||||
|
{
|
||||||
|
list_status_t listStatus = kLIST_Ok;
|
||||||
|
LIST_ENTER_CRITICAL();
|
||||||
|
|
||||||
|
if (listElement->list == NULL)
|
||||||
|
{
|
||||||
|
listStatus = kLIST_OrphanElement; /*Element was previusly removed or never added*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
list_element_handle_t element_list = listElement->list->head;
|
||||||
|
list_element_handle_t element_Prev = NULL;
|
||||||
|
while (NULL != element_list)
|
||||||
|
{
|
||||||
|
if (listElement->list->head == listElement)
|
||||||
|
{
|
||||||
|
listElement->list->head = element_list->next;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (element_list->next == listElement)
|
||||||
|
{
|
||||||
|
element_Prev = element_list;
|
||||||
|
element_list->next = listElement->next;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
element_list = element_list->next;
|
||||||
|
}
|
||||||
|
if (listElement->next == NULL)
|
||||||
|
{
|
||||||
|
listElement->list->tail = element_Prev;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (listElement->prev == NULL) /*Element is head or solo*/
|
||||||
|
{
|
||||||
|
listElement->list->head = listElement->next; /*is null if solo*/
|
||||||
|
}
|
||||||
|
if (listElement->next == NULL) /*Element is tail or solo*/
|
||||||
|
{
|
||||||
|
listElement->list->tail = listElement->prev; /*is null if solo*/
|
||||||
|
}
|
||||||
|
if (listElement->prev != NULL) /*Element is not head*/
|
||||||
|
{
|
||||||
|
listElement->prev->next = listElement->next;
|
||||||
|
}
|
||||||
|
if (listElement->next != NULL) /*Element is not tail*/
|
||||||
|
{
|
||||||
|
listElement->next->prev = listElement->prev;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
listElement->list->size--;
|
||||||
|
listElement->list = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_EXIT_CRITICAL();
|
||||||
|
return listStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \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 listElement, list_element_handle_t newElement)
|
||||||
|
{
|
||||||
|
list_status_t listStatus = kLIST_Ok;
|
||||||
|
LIST_ENTER_CRITICAL();
|
||||||
|
|
||||||
|
if (listElement->list == NULL)
|
||||||
|
{
|
||||||
|
listStatus = kLIST_OrphanElement; /*Element was previusly removed or never added*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listStatus = LIST_Error_Check(listElement->list, newElement);
|
||||||
|
if (listStatus == kLIST_Ok)
|
||||||
|
{
|
||||||
|
#if (defined(GENERIC_LIST_LIGHT) && (GENERIC_LIST_LIGHT > 0U))
|
||||||
|
list_element_handle_t element_list = listElement->list->head;
|
||||||
|
while (NULL != element_list)
|
||||||
|
{
|
||||||
|
if ((element_list->next == listElement) || (element_list == listElement))
|
||||||
|
{
|
||||||
|
if (element_list == listElement)
|
||||||
|
{
|
||||||
|
listElement->list->head = newElement;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
element_list->next = newElement;
|
||||||
|
}
|
||||||
|
newElement->list = listElement->list;
|
||||||
|
newElement->next = listElement;
|
||||||
|
listElement->list->size++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
element_list = element_list->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
if (listElement->prev == NULL) /*Element is list head*/
|
||||||
|
{
|
||||||
|
listElement->list->head = newElement;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
listElement->prev->next = newElement;
|
||||||
|
}
|
||||||
|
newElement->list = listElement->list;
|
||||||
|
listElement->list->size++;
|
||||||
|
newElement->next = listElement;
|
||||||
|
newElement->prev = listElement->prev;
|
||||||
|
listElement->prev = newElement;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LIST_EXIT_CRITICAL();
|
||||||
|
return listStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! *********************************************************************************
|
||||||
|
* \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 (list->max - list->size); /*Gets the number of free places in the list*/
|
||||||
|
}
|
||||||
1450
drivers/Src/fsl_debug_console.c
Normal file
1450
drivers/Src/fsl_debug_console.c
Normal file
File diff suppressed because it is too large
Load Diff
401
drivers/Src/fsl_flexcomm.c
Normal file
401
drivers/Src/fsl_flexcomm.c
Normal file
@ -0,0 +1,401 @@
|
|||||||
|
/*
|
||||||
|
* 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 Array to map FLEXCOMM instance number to base address. */
|
||||||
|
static const uint32_t s_flexcommBaseAddrs[] = FLEXCOMM_BASE_ADDRS;
|
||||||
|
|
||||||
|
/*! @brief Pointers to real IRQ handlers installed by drivers for each instance. */
|
||||||
|
static flexcomm_irq_handler_t s_flexcommIrqHandler[ARRAY_SIZE(s_flexcommBaseAddrs)];
|
||||||
|
|
||||||
|
/*! @brief Pointers to handles for each instance to provide context to interrupt routines */
|
||||||
|
static void *s_flexcommHandle[ARRAY_SIZE(s_flexcommBaseAddrs)];
|
||||||
|
|
||||||
|
/*! @brief Array to map FLEXCOMM instance number to IRQ number. */
|
||||||
|
IRQn_Type const kFlexcommIrqs[] = FLEXCOMM_IRQS;
|
||||||
|
|
||||||
|
#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 & (1UL << ((uint32_t)periph + 3U))) > 0UL ? true : false;
|
||||||
|
}
|
||||||
|
else if (periph == FLEXCOMM_PERIPH_I2S_RX)
|
||||||
|
{
|
||||||
|
return (base->PSELID & (1U << 7U)) > (uint32_t)0U ? 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)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
for (i = 0U; i < (uint32_t)FSL_FEATURE_SOC_FLEXCOMM_COUNT; i++)
|
||||||
|
{
|
||||||
|
if ((uintptr_t)(uint8_t*)base == s_flexcommBaseAddrs[i])
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(i < (uint32_t)FSL_FEATURE_SOC_FLEXCOMM_COUNT);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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) != 0U) &&
|
||||||
|
((base->PSELID & FLEXCOMM_PSELID_PERSEL_MASK) != (uint32_t)periph))
|
||||||
|
{
|
||||||
|
return kStatus_Fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if we are asked to lock */
|
||||||
|
if (lock != 0)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
uint32_t idx = FLEXCOMM_GetInstance(base);
|
||||||
|
|
||||||
|
#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 *flexcommHandle)
|
||||||
|
{
|
||||||
|
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] = flexcommHandle;
|
||||||
|
s_flexcommIrqHandler[instance] = handler;
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IRQ handler functions overloading weak symbols in the startup */
|
||||||
|
#if defined(FLEXCOMM0)
|
||||||
|
void FLEXCOMM0_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM0_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM0);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM1)
|
||||||
|
void FLEXCOMM1_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM1_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM1);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM2)
|
||||||
|
void FLEXCOMM2_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM2_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM2);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM3)
|
||||||
|
void FLEXCOMM3_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM3_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM3);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM4)
|
||||||
|
void FLEXCOMM4_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM4_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM4);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM5)
|
||||||
|
void FLEXCOMM5_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM5_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM5);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM6)
|
||||||
|
void FLEXCOMM6_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM6_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM6);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM7)
|
||||||
|
void FLEXCOMM7_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM7_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM7);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM8)
|
||||||
|
void FLEXCOMM8_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM8_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM8);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM9)
|
||||||
|
void FLEXCOMM9_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM9_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM9);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM10)
|
||||||
|
void FLEXCOMM10_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM10_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM10);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM11)
|
||||||
|
void FLEXCOMM11_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM11_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM11);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM12)
|
||||||
|
void FLEXCOMM12_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM12_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM12);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM13)
|
||||||
|
void FLEXCOMM13_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM13_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM13);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM14)
|
||||||
|
void FLEXCOMM14_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM14_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM14);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM15)
|
||||||
|
void FLEXCOMM15_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM15_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM15);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(FLEXCOMM16)
|
||||||
|
void FLEXCOMM16_DriverIRQHandler(void);
|
||||||
|
void FLEXCOMM16_DriverIRQHandler(void)
|
||||||
|
{
|
||||||
|
uint32_t instance;
|
||||||
|
|
||||||
|
/* Look up instance number */
|
||||||
|
instance = FLEXCOMM_GetInstance(FLEXCOMM16);
|
||||||
|
assert(s_flexcommIrqHandler[instance] != NULL);
|
||||||
|
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
|
||||||
|
SDK_ISR_EXIT_BARRIER;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
1831
drivers/Src/fsl_power.c
Normal file
1831
drivers/Src/fsl_power.c
Normal file
File diff suppressed because it is too large
Load Diff
99
drivers/Src/fsl_reset.c
Normal file
99
drivers/Src/fsl_reset.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||||
|
* Copyright 2016, NXP
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "fsl_common.h"
|
||||||
|
#include "fsl_reset.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Definitions
|
||||||
|
******************************************************************************/
|
||||||
|
/* Component ID definition, used by tools. */
|
||||||
|
#ifndef FSL_COMPONENT_ID
|
||||||
|
#define FSL_COMPONENT_ID "platform.drivers.reset"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Variables
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Prototypes
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
* Code
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#if (defined(FSL_FEATURE_SOC_SYSCON_COUNT) && (FSL_FEATURE_SOC_SYSCON_COUNT > 0))
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Assert reset to peripheral.
|
||||||
|
*
|
||||||
|
* Asserts reset signal to specified peripheral module.
|
||||||
|
*
|
||||||
|
* param peripheral Assert reset to this peripheral. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
void RESET_SetPeripheralReset(reset_ip_name_t peripheral)
|
||||||
|
{
|
||||||
|
const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
|
||||||
|
const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
|
||||||
|
const uint32_t bitMask = 1UL << bitPos;
|
||||||
|
|
||||||
|
assert(bitPos < 32u);
|
||||||
|
|
||||||
|
/* reset register is in SYSCON */
|
||||||
|
/* set bit */
|
||||||
|
SYSCON->PRESETCTRLSET[regIndex] = bitMask;
|
||||||
|
/* wait until it reads 0b1 */
|
||||||
|
while (0u == (SYSCON->PRESETCTRLX[regIndex] & bitMask))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Clear reset to peripheral.
|
||||||
|
*
|
||||||
|
* Clears reset signal to specified peripheral module, allows it to operate.
|
||||||
|
*
|
||||||
|
* param peripheral Clear reset to this peripheral. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
void RESET_ClearPeripheralReset(reset_ip_name_t peripheral)
|
||||||
|
{
|
||||||
|
const uint32_t regIndex = ((uint32_t)peripheral & 0xFFFF0000u) >> 16;
|
||||||
|
const uint32_t bitPos = ((uint32_t)peripheral & 0x0000FFFFu);
|
||||||
|
const uint32_t bitMask = 1UL << bitPos;
|
||||||
|
|
||||||
|
assert(bitPos < 32u);
|
||||||
|
|
||||||
|
/* reset register is in SYSCON */
|
||||||
|
|
||||||
|
/* clear bit */
|
||||||
|
SYSCON->PRESETCTRLCLR[regIndex] = bitMask;
|
||||||
|
/* wait until it reads 0b0 */
|
||||||
|
while (bitMask == (SYSCON->PRESETCTRLX[regIndex] & bitMask))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* brief Reset peripheral module.
|
||||||
|
*
|
||||||
|
* Reset peripheral module.
|
||||||
|
*
|
||||||
|
* param peripheral Peripheral to reset. The enum argument contains encoding of reset register
|
||||||
|
* and reset bit position in the reset register.
|
||||||
|
*/
|
||||||
|
void RESET_PeripheralReset(reset_ip_name_t peripheral)
|
||||||
|
{
|
||||||
|
RESET_SetPeripheralReset(peripheral);
|
||||||
|
RESET_ClearPeripheralReset(peripheral);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* FSL_FEATURE_SOC_SYSCON_COUNT || FSL_FEATURE_SOC_ASYNC_SYSCON_COUNT */
|
||||||
1707
drivers/Src/fsl_str.c
Normal file
1707
drivers/Src/fsl_str.c
Normal file
File diff suppressed because it is too large
Load Diff
1314
drivers/Src/fsl_usart.c
Normal file
1314
drivers/Src/fsl_usart.c
Normal file
File diff suppressed because it is too large
Load Diff
23
drivers/Src/led.c
Normal file
23
drivers/Src/led.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define PORT1 (1U<<15)
|
||||||
|
#define GPIO1_4 (1U<<4)
|
||||||
|
|
||||||
|
void led_init(void){
|
||||||
|
/* ENable Clock access to led port (PORT1) */
|
||||||
|
SYSCON->AHBCLKCTRLX[0] |= PORT1;
|
||||||
|
/* Set led pin as output pin */
|
||||||
|
GPIO->W[1][4] = 1;
|
||||||
|
GPIO->DIRSET[1] = GPIO1_4;
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_on(void){
|
||||||
|
/* Set Led pin HIGH (P1-4) */
|
||||||
|
GPIO->W[1][4] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_off(void){
|
||||||
|
/* Set Led pin LOW (P1-4) */
|
||||||
|
GPIO->W[1][4] = 1;
|
||||||
|
}
|
||||||
60
drivers/Src/uart.c
Normal file
60
drivers/Src/uart.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include "uart.h"
|
||||||
|
#include "fsl_common.h"
|
||||||
|
#include "fsl_debug_console.h"
|
||||||
|
|
||||||
|
void uart_tx_pin(void)
|
||||||
|
{
|
||||||
|
/* Enable IOCON Clock */
|
||||||
|
CLOCK_EnableClock(kCLOCK_Iocon);
|
||||||
|
|
||||||
|
/* Enable Uart Clock IP */
|
||||||
|
const uint32_t port0_pin30_config = (/* Pin is configured as FC0_TXD_SCL_MISO_WS */
|
||||||
|
0x01u |
|
||||||
|
/* No addition pin function */
|
||||||
|
0x00u |
|
||||||
|
/* Standard mode, output slew rate control is enabled */
|
||||||
|
0x00u |
|
||||||
|
/* Input function is not inverted */
|
||||||
|
0x00u |
|
||||||
|
/* Enables digital function */
|
||||||
|
0x0100u |
|
||||||
|
/* Open drain is disabled */
|
||||||
|
0x00u);
|
||||||
|
/* PORT0 PIN30 (coords: 94) is configured as FC0_TXD_SCL_MISO_WS */
|
||||||
|
IOCON->PIO[0U][30U] = port0_pin30_config;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_rx_pin(void)
|
||||||
|
{
|
||||||
|
/* Enable IOCON Clock */
|
||||||
|
CLOCK_EnableClock(kCLOCK_Iocon);
|
||||||
|
|
||||||
|
/* Enable Uart Clock IP */
|
||||||
|
const uint32_t port0_pin29_config = (/* Pin is configured as FC0_TXD_SCL_MISO_WS */
|
||||||
|
0x01u |
|
||||||
|
/* No addition pin function */
|
||||||
|
0x00u |
|
||||||
|
/* Standard mode, output slew rate control is enabled */
|
||||||
|
0x00u |
|
||||||
|
/* Input function is not inverted */
|
||||||
|
0x00u |
|
||||||
|
/* Enables digital function */
|
||||||
|
0x0100u |
|
||||||
|
/* Open drain is disabled */
|
||||||
|
0x00u);
|
||||||
|
/* PORT0 PIN30 (coords: 94) is configured as FC0_TXD_SCL_MISO_WS */
|
||||||
|
IOCON->PIO[0U][29U] = port0_pin29_config;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void uart_init(void){
|
||||||
|
uart_tx_pin();
|
||||||
|
uart_rx_pin();
|
||||||
|
CLOCK_AttachClk(kFRO12M_to_FLEXCOMM0);
|
||||||
|
RESET_ClearPeripheralReset(kFC0_RST_SHIFT_RSTn);
|
||||||
|
uint32_t uartClkSrcFreq = 12000000U;
|
||||||
|
DbgConsole_Init(0, 115200U, kSerialPort_Uart, uartClkSrcFreq);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
24
main.c
Normal file
24
main.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include "led.h"
|
||||||
|
#include "uart.h"
|
||||||
|
#include "fsl_debug_console.h"
|
||||||
|
#include "timebase.h"
|
||||||
|
#include "fsl_power.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
SystemCoreClockUpdate();
|
||||||
|
uart_init();
|
||||||
|
led_init();
|
||||||
|
timebase_init();
|
||||||
|
|
||||||
|
PRINTF("LPC55S69 ..............\n\r");
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
delay_s(1);
|
||||||
|
PRINTF("A second just occured!!\n\r");
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user