1.增加hc32l136 bsp工程文件

This commit is contained in:
jacycle 2021-08-21 14:10:33 +08:00
parent d71e2ac582
commit 3a602808c9
136 changed files with 89074 additions and 0 deletions

574
bsp/hc32l136/.config Normal file
View File

@ -0,0 +1,574 @@
#
# Automatically generated file; DO NOT EDIT.
# RT-Thread Project Configuration
#
#
# RT-Thread Kernel
#
CONFIG_RT_NAME_MAX=8
# CONFIG_RT_USING_ARCH_DATA_TYPE is not set
# CONFIG_RT_USING_SMP is not set
CONFIG_RT_ALIGN_SIZE=4
# CONFIG_RT_THREAD_PRIORITY_8 is not set
CONFIG_RT_THREAD_PRIORITY_32=y
# CONFIG_RT_THREAD_PRIORITY_256 is not set
CONFIG_RT_THREAD_PRIORITY_MAX=32
CONFIG_RT_TICK_PER_SECOND=1000
CONFIG_RT_USING_OVERFLOW_CHECK=y
CONFIG_RT_USING_HOOK=y
CONFIG_RT_USING_IDLE_HOOK=y
CONFIG_RT_IDLE_HOOK_LIST_SIZE=4
CONFIG_IDLE_THREAD_STACK_SIZE=256
CONFIG_RT_USING_TIMER_SOFT=y
CONFIG_RT_TIMER_THREAD_PRIO=4
CONFIG_RT_TIMER_THREAD_STACK_SIZE=512
#
# kservice optimization
#
# CONFIG_RT_KSERVICE_USING_STDLIB is not set
# CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set
CONFIG_RT_DEBUG=y
# CONFIG_RT_DEBUG_COLOR is not set
# CONFIG_RT_DEBUG_INIT_CONFIG is not set
# CONFIG_RT_DEBUG_THREAD_CONFIG is not set
# CONFIG_RT_DEBUG_SCHEDULER_CONFIG is not set
# CONFIG_RT_DEBUG_IPC_CONFIG is not set
# CONFIG_RT_DEBUG_TIMER_CONFIG is not set
# CONFIG_RT_DEBUG_IRQ_CONFIG is not set
# CONFIG_RT_DEBUG_MEM_CONFIG is not set
# CONFIG_RT_DEBUG_SLAB_CONFIG is not set
# CONFIG_RT_DEBUG_MEMHEAP_CONFIG is not set
# CONFIG_RT_DEBUG_MODULE_CONFIG is not set
#
# Inter-Thread communication
#
CONFIG_RT_USING_SEMAPHORE=y
CONFIG_RT_USING_MUTEX=y
CONFIG_RT_USING_EVENT=y
CONFIG_RT_USING_MAILBOX=y
CONFIG_RT_USING_MESSAGEQUEUE=y
# CONFIG_RT_USING_SIGNALS is not set
#
# Memory Management
#
CONFIG_RT_USING_MEMPOOL=y
# CONFIG_RT_USING_MEMHEAP is not set
# CONFIG_RT_USING_NOHEAP is not set
CONFIG_RT_USING_SMALL_MEM=y
# CONFIG_RT_USING_SLAB is not set
# CONFIG_RT_USING_USERHEAP is not set
# CONFIG_RT_USING_MEMTRACE is not set
CONFIG_RT_USING_HEAP=y
#
# Kernel Device Object
#
CONFIG_RT_USING_DEVICE=y
# CONFIG_RT_USING_DEVICE_OPS is not set
# CONFIG_RT_USING_INTERRUPT_INFO is not set
CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=128
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
# CONFIG_RT_PRINTF_LONGLONG is not set
CONFIG_RT_VER_NUM=0x40003
CONFIG_ARCH_ARM=y
# CONFIG_RT_USING_CPU_FFS is not set
CONFIG_ARCH_ARM_CORTEX_M=y
CONFIG_ARCH_ARM_CORTEX_M0=y
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
#
# RT-Thread Components
#
CONFIG_RT_USING_COMPONENTS_INIT=y
CONFIG_RT_USING_USER_MAIN=y
CONFIG_RT_MAIN_THREAD_STACK_SIZE=512
CONFIG_RT_MAIN_THREAD_PRIORITY=10
#
# C++ features
#
# CONFIG_RT_USING_CPLUSPLUS is not set
#
# Command shell
#
CONFIG_RT_USING_FINSH=y
CONFIG_FINSH_THREAD_NAME="tshell"
CONFIG_FINSH_USING_HISTORY=y
CONFIG_FINSH_HISTORY_LINES=5
CONFIG_FINSH_USING_SYMTAB=y
CONFIG_FINSH_USING_DESCRIPTION=y
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
CONFIG_FINSH_THREAD_PRIORITY=20
CONFIG_FINSH_THREAD_STACK_SIZE=512
CONFIG_FINSH_CMD_SIZE=80
# CONFIG_FINSH_USING_AUTH is not set
CONFIG_FINSH_USING_MSH=y
CONFIG_FINSH_USING_MSH_DEFAULT=y
# CONFIG_FINSH_USING_MSH_ONLY is not set
CONFIG_FINSH_ARG_MAX=10
#
# Device virtual file system
#
# CONFIG_RT_USING_DFS is not set
#
# Device Drivers
#
CONFIG_RT_USING_DEVICE_IPC=y
CONFIG_RT_PIPE_BUFSZ=512
# CONFIG_RT_USING_SYSTEM_WORKQUEUE is not set
CONFIG_RT_USING_SERIAL=y
# CONFIG_RT_SERIAL_USING_DMA is not set
CONFIG_RT_SERIAL_RB_BUFSZ=64
# CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_HWTIMER is not set
# CONFIG_RT_USING_CPUTIME is not set
# CONFIG_RT_USING_I2C is not set
# CONFIG_RT_USING_PHY is not set
CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_ADC is not set
# CONFIG_RT_USING_DAC is not set
# CONFIG_RT_USING_PWM is not set
# CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_PM is not set
# CONFIG_RT_USING_RTC is not set
# CONFIG_RT_USING_SDIO is not set
# CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set
# CONFIG_RT_USING_TOUCH is not set
# CONFIG_RT_USING_HWCRYPTO is not set
# CONFIG_RT_USING_PULSE_ENCODER is not set
# CONFIG_RT_USING_INPUT_CAPTURE is not set
# CONFIG_RT_USING_WIFI is not set
#
# Using USB
#
# CONFIG_RT_USING_USB_HOST is not set
# CONFIG_RT_USING_USB_DEVICE is not set
#
# POSIX layer and C standard library
#
# CONFIG_RT_USING_LIBC is not set
# CONFIG_RT_USING_PTHREADS is not set
# CONFIG_RT_LIBC_USING_TIME is not set
#
# Network
#
#
# Socket abstraction layer
#
# CONFIG_RT_USING_SAL is not set
#
# Network interface device
#
# CONFIG_RT_USING_NETDEV is not set
#
# light weight TCP/IP stack
#
# CONFIG_RT_USING_LWIP is not set
#
# AT commands
#
# CONFIG_RT_USING_AT is not set
#
# VBUS(Virtual Software BUS)
#
# CONFIG_RT_USING_VBUS is not set
#
# Utilities
#
# CONFIG_RT_USING_RYM is not set
# CONFIG_RT_USING_ULOG is not set
# CONFIG_RT_USING_UTEST is not set
# CONFIG_RT_USING_LWP is not set
#
# RT-Thread online packages
#
#
# IoT - internet of things
#
# CONFIG_PKG_USING_LORAWAN_DRIVER is not set
# CONFIG_PKG_USING_PAHOMQTT is not set
# CONFIG_PKG_USING_UMQTT is not set
# CONFIG_PKG_USING_WEBCLIENT is not set
# CONFIG_PKG_USING_WEBNET is not set
# CONFIG_PKG_USING_MONGOOSE is not set
# CONFIG_PKG_USING_MYMQTT is not set
# CONFIG_PKG_USING_KAWAII_MQTT is not set
# CONFIG_PKG_USING_BC28_MQTT is not set
# CONFIG_PKG_USING_WEBTERMINAL is not set
# CONFIG_PKG_USING_CJSON is not set
# CONFIG_PKG_USING_JSMN is not set
# CONFIG_PKG_USING_LIBMODBUS is not set
# CONFIG_PKG_USING_FREEMODBUS is not set
# CONFIG_PKG_USING_LJSON is not set
# CONFIG_PKG_USING_EZXML is not set
# CONFIG_PKG_USING_NANOPB is not set
#
# Wi-Fi
#
#
# Marvell WiFi
#
# CONFIG_PKG_USING_WLANMARVELL is not set
#
# Wiced WiFi
#
# CONFIG_PKG_USING_WLAN_WICED is not set
# CONFIG_PKG_USING_RW007 is not set
# CONFIG_PKG_USING_COAP is not set
# CONFIG_PKG_USING_NOPOLL is not set
# CONFIG_PKG_USING_NETUTILS is not set
# CONFIG_PKG_USING_CMUX is not set
# CONFIG_PKG_USING_PPP_DEVICE is not set
# CONFIG_PKG_USING_AT_DEVICE is not set
# CONFIG_PKG_USING_ATSRV_SOCKET is not set
# CONFIG_PKG_USING_WIZNET is not set
# CONFIG_PKG_USING_ZB_COORDINATOR is not set
#
# IoT Cloud
#
# CONFIG_PKG_USING_ONENET is not set
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
# CONFIG_PKG_USING_ALI_IOTKIT is not set
# CONFIG_PKG_USING_AZURE is not set
# CONFIG_PKG_USING_TENCENT_IOT_EXPLORER is not set
# CONFIG_PKG_USING_JIOT-C-SDK is not set
# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
# CONFIG_PKG_USING_JOYLINK is not set
# CONFIG_PKG_USING_NIMBLE is not set
# CONFIG_PKG_USING_OTA_DOWNLOADER is not set
# CONFIG_PKG_USING_IPMSG is not set
# CONFIG_PKG_USING_LSSDP is not set
# CONFIG_PKG_USING_AIRKISS_OPEN is not set
# CONFIG_PKG_USING_LIBRWS is not set
# CONFIG_PKG_USING_TCPSERVER is not set
# CONFIG_PKG_USING_PROTOBUF_C is not set
# CONFIG_PKG_USING_DLT645 is not set
# CONFIG_PKG_USING_QXWZ is not set
# CONFIG_PKG_USING_SMTP_CLIENT is not set
# CONFIG_PKG_USING_ABUP_FOTA is not set
# CONFIG_PKG_USING_LIBCURL2RTT is not set
# CONFIG_PKG_USING_CAPNP is not set
# CONFIG_PKG_USING_RT_CJSON_TOOLS is not set
# CONFIG_PKG_USING_AGILE_TELNET is not set
# CONFIG_PKG_USING_NMEALIB is not set
# CONFIG_PKG_USING_AGILE_JSMN is not set
# CONFIG_PKG_USING_PDULIB is not set
# CONFIG_PKG_USING_BTSTACK is not set
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
# CONFIG_PKG_USING_WAYZ_IOTKIT is not set
# CONFIG_PKG_USING_MAVLINK is not set
# CONFIG_PKG_USING_RAPIDJSON is not set
# CONFIG_PKG_USING_BSAL is not set
# CONFIG_PKG_USING_AGILE_MODBUS is not set
# CONFIG_PKG_USING_AGILE_FTP is not set
# CONFIG_PKG_USING_EMBEDDEDPROTO is not set
# CONFIG_PKG_USING_RT_LINK_HW is not set
#
# security packages
#
# CONFIG_PKG_USING_MBEDTLS is not set
# CONFIG_PKG_USING_libsodium is not set
# CONFIG_PKG_USING_TINYCRYPT is not set
# CONFIG_PKG_USING_TFM is not set
# CONFIG_PKG_USING_YD_CRYPTO is not set
#
# language packages
#
# CONFIG_PKG_USING_LUA is not set
# CONFIG_PKG_USING_JERRYSCRIPT is not set
# CONFIG_PKG_USING_MICROPYTHON is not set
#
# multimedia packages
#
# CONFIG_PKG_USING_OPENMV is not set
# CONFIG_PKG_USING_MUPDF is not set
# CONFIG_PKG_USING_STEMWIN is not set
# CONFIG_PKG_USING_WAVPLAYER is not set
# CONFIG_PKG_USING_TJPGD is not set
# CONFIG_PKG_USING_PDFGEN is not set
# CONFIG_PKG_USING_HELIX is not set
# CONFIG_PKG_USING_AZUREGUIX is not set
# CONFIG_PKG_USING_TOUCHGFX2RTT is not set
# CONFIG_PKG_USING_NUEMWIN is not set
# CONFIG_PKG_USING_MP3PLAYER is not set
# CONFIG_PKG_USING_TINYJPEG is not set
#
# tools packages
#
# CONFIG_PKG_USING_CMBACKTRACE is not set
# CONFIG_PKG_USING_EASYFLASH is not set
# CONFIG_PKG_USING_EASYLOGGER is not set
# CONFIG_PKG_USING_SYSTEMVIEW is not set
# CONFIG_PKG_USING_SEGGER_RTT is not set
# CONFIG_PKG_USING_RDB is not set
# CONFIG_PKG_USING_QRCODE is not set
# CONFIG_PKG_USING_ULOG_EASYFLASH is not set
# CONFIG_PKG_USING_ULOG_FILE is not set
# CONFIG_PKG_USING_LOGMGR is not set
# CONFIG_PKG_USING_ADBD is not set
# CONFIG_PKG_USING_COREMARK is not set
# CONFIG_PKG_USING_DHRYSTONE is not set
# CONFIG_PKG_USING_MEMORYPERF is not set
# CONFIG_PKG_USING_NR_MICRO_SHELL is not set
# CONFIG_PKG_USING_CHINESE_FONT_LIBRARY is not set
# CONFIG_PKG_USING_LUNAR_CALENDAR is not set
# CONFIG_PKG_USING_BS8116A is not set
# CONFIG_PKG_USING_GPS_RMC is not set
# CONFIG_PKG_USING_URLENCODE is not set
# CONFIG_PKG_USING_UMCN is not set
# CONFIG_PKG_USING_LWRB2RTT is not set
# CONFIG_PKG_USING_CPU_USAGE is not set
# CONFIG_PKG_USING_GBK2UTF8 is not set
# CONFIG_PKG_USING_VCONSOLE is not set
# CONFIG_PKG_USING_KDB is not set
# CONFIG_PKG_USING_WAMR is not set
# CONFIG_PKG_USING_MICRO_XRCE_DDS_CLIENT is not set
# CONFIG_PKG_USING_LWLOG is not set
# CONFIG_PKG_USING_ANV_TRACE is not set
# CONFIG_PKG_USING_ANV_MEMLEAK is not set
# CONFIG_PKG_USING_ANV_TESTSUIT is not set
# CONFIG_PKG_USING_ANV_BENCH is not set
# CONFIG_PKG_USING_DEVMEM is not set
# CONFIG_PKG_USING_REGEX is not set
# CONFIG_PKG_USING_MEM_SANDBOX is not set
# CONFIG_PKG_USING_SOLAR_TERMS is not set
# CONFIG_PKG_USING_GAN_ZHI is not set
#
# system packages
#
#
# acceleration: Assembly language or algorithmic acceleration packages
#
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
# CONFIG_PKG_USING_QFPLIB_M0_FULL is not set
# CONFIG_PKG_USING_QFPLIB_M0_TINY is not set
# CONFIG_PKG_USING_QFPLIB_M3 is not set
#
# Micrium: Micrium software products porting for RT-Thread
#
# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
# CONFIG_PKG_USING_UCOSII_WRAPPER is not set
# CONFIG_PKG_USING_UC_CRC is not set
# CONFIG_PKG_USING_UC_CLK is not set
# CONFIG_PKG_USING_UC_COMMON is not set
# CONFIG_PKG_USING_UC_MODBUS is not set
# CONFIG_PKG_USING_GUIENGINE is not set
# CONFIG_PKG_USING_CAIRO is not set
# CONFIG_PKG_USING_PIXMAN is not set
# CONFIG_PKG_USING_PARTITION is not set
# CONFIG_PKG_USING_FAL is not set
# CONFIG_PKG_USING_FLASHDB is not set
# CONFIG_PKG_USING_SQLITE is not set
# CONFIG_PKG_USING_RTI is not set
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set
# CONFIG_PKG_USING_CMSIS is not set
# CONFIG_PKG_USING_DFS_YAFFS is not set
# CONFIG_PKG_USING_LITTLEFS is not set
# CONFIG_PKG_USING_DFS_JFFS2 is not set
# CONFIG_PKG_USING_DFS_UFFS is not set
# CONFIG_PKG_USING_LWEXT4 is not set
# CONFIG_PKG_USING_THREAD_POOL is not set
# CONFIG_PKG_USING_ROBOTS is not set
# CONFIG_PKG_USING_EV is not set
# CONFIG_PKG_USING_SYSWATCH is not set
# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
# CONFIG_PKG_USING_PLCCORE is not set
# CONFIG_PKG_USING_RAMDISK is not set
# CONFIG_PKG_USING_MININI is not set
# CONFIG_PKG_USING_QBOOT is not set
# CONFIG_PKG_USING_PPOOL is not set
# CONFIG_PKG_USING_OPENAMP is not set
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
# CONFIG_PKG_USING_LPM is not set
# CONFIG_PKG_USING_TLSF is not set
# CONFIG_PKG_USING_EVENT_RECORDER is not set
#
# peripheral libraries and drivers
#
# CONFIG_PKG_USING_SENSORS_DRIVERS is not set
# CONFIG_PKG_USING_REALTEK_AMEBA is not set
# CONFIG_PKG_USING_SHT2X is not set
# CONFIG_PKG_USING_SHT3X is not set
# CONFIG_PKG_USING_AS7341 is not set
# CONFIG_PKG_USING_STM32_SDIO is not set
# CONFIG_PKG_USING_ICM20608 is not set
# CONFIG_PKG_USING_U8G2 is not set
# CONFIG_PKG_USING_BUTTON is not set
# CONFIG_PKG_USING_PCF8574 is not set
# CONFIG_PKG_USING_SX12XX is not set
# CONFIG_PKG_USING_SIGNAL_LED is not set
# CONFIG_PKG_USING_LEDBLINK is not set
# CONFIG_PKG_USING_LITTLED is not set
# CONFIG_PKG_USING_LKDGUI is not set
# CONFIG_PKG_USING_NRF5X_SDK is not set
# CONFIG_PKG_USING_NRFX is not set
# CONFIG_PKG_USING_WM_LIBRARIES is not set
# CONFIG_PKG_USING_KENDRYTE_SDK is not set
# CONFIG_PKG_USING_INFRARED is not set
# CONFIG_PKG_USING_AGILE_BUTTON is not set
# CONFIG_PKG_USING_AGILE_LED is not set
# CONFIG_PKG_USING_AT24CXX is not set
# CONFIG_PKG_USING_MOTIONDRIVER2RTT is not set
# CONFIG_PKG_USING_AD7746 is not set
# CONFIG_PKG_USING_PCA9685 is not set
# CONFIG_PKG_USING_I2C_TOOLS is not set
# CONFIG_PKG_USING_NRF24L01 is not set
# CONFIG_PKG_USING_TOUCH_DRIVERS is not set
# CONFIG_PKG_USING_MAX17048 is not set
# CONFIG_PKG_USING_RPLIDAR is not set
# CONFIG_PKG_USING_AS608 is not set
# CONFIG_PKG_USING_RC522 is not set
# CONFIG_PKG_USING_WS2812B is not set
# CONFIG_PKG_USING_EMBARC_BSP is not set
# CONFIG_PKG_USING_EXTERN_RTC_DRIVERS is not set
# CONFIG_PKG_USING_MULTI_RTIMER is not set
# CONFIG_PKG_USING_MAX7219 is not set
# CONFIG_PKG_USING_BEEP is not set
# CONFIG_PKG_USING_EASYBLINK is not set
# CONFIG_PKG_USING_PMS_SERIES is not set
# CONFIG_PKG_USING_CAN_YMODEM is not set
# CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
# CONFIG_PKG_USING_QLED is not set
# CONFIG_PKG_USING_PAJ7620 is not set
# CONFIG_PKG_USING_AGILE_CONSOLE is not set
# CONFIG_PKG_USING_LD3320 is not set
# CONFIG_PKG_USING_WK2124 is not set
# CONFIG_PKG_USING_LY68L6400 is not set
# CONFIG_PKG_USING_DM9051 is not set
# CONFIG_PKG_USING_SSD1306 is not set
# CONFIG_PKG_USING_QKEY is not set
# CONFIG_PKG_USING_RS485 is not set
# CONFIG_PKG_USING_NES is not set
# CONFIG_PKG_USING_VIRTUAL_SENSOR is not set
# CONFIG_PKG_USING_VDEVICE is not set
# CONFIG_PKG_USING_SGM706 is not set
# CONFIG_PKG_USING_STM32WB55_SDK is not set
# CONFIG_PKG_USING_RDA58XX is not set
# CONFIG_PKG_USING_LIBNFC is not set
# CONFIG_PKG_USING_MFOC is not set
# CONFIG_PKG_USING_TMC51XX is not set
# CONFIG_PKG_USING_TCA9534 is not set
# CONFIG_PKG_USING_KOBUKI is not set
# CONFIG_PKG_USING_ROSSERIAL is not set
# CONFIG_PKG_USING_MICRO_ROS is not set
# CONFIG_PKG_USING_MCP23008 is not set
#
# AI packages
#
# CONFIG_PKG_USING_LIBANN is not set
# CONFIG_PKG_USING_NNOM is not set
# CONFIG_PKG_USING_ONNX_BACKEND is not set
# CONFIG_PKG_USING_ONNX_PARSER is not set
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
# CONFIG_PKG_USING_ELAPACK is not set
# CONFIG_PKG_USING_ULAPACK is not set
# CONFIG_PKG_USING_QUEST is not set
# CONFIG_PKG_USING_NAXOS is not set
#
# miscellaneous packages
#
# CONFIG_PKG_USING_LIBCSV is not set
# CONFIG_PKG_USING_OPTPARSE is not set
# CONFIG_PKG_USING_FASTLZ is not set
# CONFIG_PKG_USING_MINILZO is not set
# CONFIG_PKG_USING_QUICKLZ is not set
# CONFIG_PKG_USING_LZMA is not set
# CONFIG_PKG_USING_MULTIBUTTON is not set
# CONFIG_PKG_USING_FLEXIBLE_BUTTON is not set
# CONFIG_PKG_USING_CANFESTIVAL is not set
# CONFIG_PKG_USING_ZLIB is not set
# CONFIG_PKG_USING_MINIZIP is not set
# CONFIG_PKG_USING_DSTR is not set
# CONFIG_PKG_USING_TINYFRAME is not set
# CONFIG_PKG_USING_KENDRYTE_DEMO is not set
# CONFIG_PKG_USING_DIGITALCTRL is not set
# CONFIG_PKG_USING_UPACKER is not set
# CONFIG_PKG_USING_UPARAM is not set
#
# samples: kernel and components samples
#
# CONFIG_PKG_USING_KERNEL_SAMPLES is not set
# CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set
# CONFIG_PKG_USING_NETWORK_SAMPLES is not set
# CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set
# CONFIG_PKG_USING_HELLO is not set
# CONFIG_PKG_USING_VI is not set
# CONFIG_PKG_USING_KI is not set
# CONFIG_PKG_USING_ARMv7M_DWT is not set
# CONFIG_PKG_USING_VT100 is not set
# CONFIG_PKG_USING_UKAL is not set
# CONFIG_PKG_USING_CRCLIB is not set
#
# entertainment: terminal games and other interesting software packages
#
# CONFIG_PKG_USING_THREES is not set
# CONFIG_PKG_USING_2048 is not set
# CONFIG_PKG_USING_SNAKE is not set
# CONFIG_PKG_USING_TETRIS is not set
# CONFIG_PKG_USING_DONUT is not set
# CONFIG_PKG_USING_ACLOCK is not set
# CONFIG_PKG_USING_LWGPS is not set
# CONFIG_PKG_USING_STATE_MACHINE is not set
# CONFIG_PKG_USING_MCURSES is not set
# CONFIG_PKG_USING_COWSAY is not set
#
# Hardware Drivers Config
#
CONFIG_MCU_HC32L136=y
#
# Onboard Peripheral Drivers
#
#
# On-chip Peripheral Drivers
#
CONFIG_BSP_USING_GPIO=y
CONFIG_BSP_USING_UART=y
# CONFIG_BSP_USING_UART0 is not set
CONFIG_BSP_USING_UART1=y
# CONFIG_BSP_USING_I2C1 is not set
#
# Board extended module Drivers
#

23
bsp/hc32l136/Kconfig Normal file
View File

@ -0,0 +1,23 @@
mainmenu "RT-Thread Project Configuration"
config BSP_DIR
string
option env="BSP_ROOT"
default "."
config RTT_DIR
string
option env="RTT_ROOT"
default "../.."
config PKGS_DIR
string
option env="PKGS_ROOT"
default "packages"
source "$RTT_DIR/Kconfig"
source "$PKGS_DIR/Kconfig"
source "board/Kconfig"

View File

@ -0,0 +1,155 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file base_types.h
**
** base type common define.
** @link SampleGroup Some description @endlink
**
** - 2018-03-09 1.0 Lux First version.
**
******************************************************************************/
#ifndef __BASE_TYPES_H__
#define __BASE_TYPES_H__
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdint.h>
#include <assert.h>
/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
#ifndef TRUE
/** Value is true (boolean_t type) */
#define TRUE ((boolean_t) 1u)
#endif
#ifndef FALSE
/** Value is false (boolean_t type) */
#define FALSE ((boolean_t) 0u)
#endif
#if defined (__ICCARM__)
#define __WEAKDEF __WEAK __ATTRIBUTES
#elif defined (__CC_ARM)
#define __WEAKDEF __weak
#else
#error "unsupported compiler!!"
#endif
/** Returns the minimum value out of two values */
#define MINIMUM( X, Y ) ((X) < (Y) ? (X) : (Y))
/** Returns the maximum value out of two values */
#define MAXIMUM( X, Y ) ((X) > (Y) ? (X) : (Y))
/** Returns the dimension of an array */
#define ARRAY_SZ( X ) (sizeof(X) / sizeof((X)[0]))
#ifdef __DEBUG_ASSERT
#define ASSERT(x) do{ assert((x)> 0u) ; }while(0);
#else
#define ASSERT(x) {}
#endif
/******************************************************************************
* Global type definitions
******************************************************************************/
/** logical datatype (only values are TRUE and FALSE) */
typedef uint8_t boolean_t;
/** single precision floating point number (4 byte) */
typedef float float32_t;
/** double precision floating point number (8 byte) */
typedef double float64_t;
/** ASCII character for string generation (8 bit) */
typedef char char_t;
/** function pointer type to void/void function */
typedef void (*func_ptr_t)(void);
/** function pointer type to void/uint8_t function */
typedef void (*func_ptr_arg1_t)(uint8_t u8Param);
/** generic error codes */
typedef enum en_result
{
Ok = 0u, ///< No error
Error = 1u, ///< Non-specific error code
ErrorAddressAlignment = 2u, ///< Address alignment does not match
ErrorAccessRights = 3u, ///< Wrong mode (e.g. user/system) mode is set
ErrorInvalidParameter = 4u, ///< Provided parameter is not valid
ErrorOperationInProgress = 5u, ///< A conflicting or requested operation is still in progress
ErrorInvalidMode = 6u, ///< Operation not allowed in current mode
ErrorUninitialized = 7u, ///< Module (or part of it) was not initialized properly
ErrorBufferFull = 8u, ///< Circular buffer can not be written because the buffer is full
ErrorTimeout = 9u, ///< Time Out error occurred (e.g. I2C arbitration lost, Flash time-out, etc.)
ErrorNotReady = 10u, ///< A requested final state is not reached
OperationInProgress = 11u ///< Indicator for operation in progress
} en_result_t;
/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/
/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
#endif /* __BASE_TYPES_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/

View File

@ -0,0 +1,120 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file stkhc32l13x.h
**
** stk board common define.
** @link SampleGroup Some description @endlink
**
** - 2018-03-09 1.0 Lux First version.
**
******************************************************************************/
#ifndef __BOARD_STKHC32L13X_H__
#define __BOARD_STKHC32L13X_H__
///< STK GPIO DEFINE
///< USER KEY
#define STK_USER_PORT GpioPortD
#define STK_USER_PIN GpioPin4
///< LED
#define STK_LED_PORT GpioPortD
#define STK_LED_PIN GpioPin5
///< XTH
#define SYSTEM_XTH (32*1000*1000u) ///< 32MHz
#define STK_XTHI_PORT GpioPortD
#define STK_XTHI_PIN GpioPin0
#define STK_XTHO_PORT GpioPortD
#define STK_XTHO_PIN GpioPin1
///< XTL
#define SYSTEM_XTL (32768u) ///< 32768Hz
#define STK_XTLI_PORT GpioPortC
#define STK_XTLI_PIN GpioPin14
#define STK_XTLO_PORT GpioPortC
#define STK_XTLO_PIN GpioPin15
///< LCD
#define STK_LCD_COM0_PORT GpioPortA
#define STK_LCD_COM0_PIN GpioPin9
#define STK_LCD_COM1_PORT GpioPortA
#define STK_LCD_COM1_PIN GpioPin10
#define STK_LCD_COM2_PORT GpioPortA
#define STK_LCD_COM2_PIN GpioPin11
#define STK_LCD_COM3_PORT GpioPortA
#define STK_LCD_COM3_PIN GpioPin12
#define STK_LCD_SEG0_PORT GpioPortA
#define STK_LCD_SEG0_PIN GpioPin8
#define STK_LCD_SEG1_PORT GpioPortC
#define STK_LCD_SEG1_PIN GpioPin9
#define STK_LCD_SEG2_PORT GpioPortC
#define STK_LCD_SEG2_PIN GpioPin8
#define STK_LCD_SEG3_PORT GpioPortC
#define STK_LCD_SEG3_PIN GpioPin7
#define STK_LCD_SEG4_PORT GpioPortC
#define STK_LCD_SEG4_PIN GpioPin6
#define STK_LCD_SEG5_PORT GpioPortB
#define STK_LCD_SEG5_PIN GpioPin15
#define STK_LCD_SEG6_PORT GpioPortB
#define STK_LCD_SEG6_PIN GpioPin14
#define STK_LCD_SEG7_PORT GpioPortB
#define STK_LCD_SEG7_PIN GpioPin13
///< I2C EEPROM
#define EVB_I2C0_EEPROM_SCL_PORT GpioPortB
#define EVB_I2C0_EEPROM_SCL_PIN GpioPin6
#define EVB_I2C0_EEPROM_SDA_PORT GpioPortB
#define EVB_I2C0_EEPROM_SDA_PIN GpioPin7
///< SPI0
#define EVB_SPI0_FLASH_CS_PORT GpioPortE
#define EVB_SPI0_FLASH_CS_PIN GpioPin12
#define EVB_SPI0_FLASH_SCK_PORT GpioPortE
#define EVB_SPI0_FLASH_SCK_PIN GpioPin13
#define EVB_SPI0_FLASH_MISO_PORT GpioPortE
#define EVB_SPI0_FLASH_MISO_PIN GpioPin14
#define EVB_SPI0_FLASH_MOSI_PORT GpioPortE
#define EVB_SPI0_FLASH_MOSI_PIN GpioPin15
#endif

View File

@ -0,0 +1,76 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ddl_device.h
**
** Device define
** @link SampleGroup Some description @endlink
**
** - 2018-04-15
**
*****************************************************************************/
#ifndef __DDL_DEVICE_H__
#define __DDL_DEVICE_H__
/**
*******************************************************************************
** \brief Global device series definition
**
** \note
******************************************************************************/
#define DDL_MCU_SERIES DDL_DEVICE_SERIES_HC32L13X
/**
*******************************************************************************
** \brief Global package definition
**
** \note This definition is used for device package settings
******************************************************************************/
#define DDL_MCU_PACKAGE DDL_DEVICE_PACKAGE_HC_K
#endif /* __DDL_DEVICE_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,107 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file system_hc32l136.h
**
** A detailed description is available at
** @link SampleGroup Some description @endlink
**
** - 2018-03-09 1.0 Lux First version.
**
******************************************************************************/
#ifndef __SYSTEM_HC32L136_H__
#define __SYSTEM_HC32L136_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('define') */
/******************************************************************************/
#define HWWD_DISABLE (1)
/**
******************************************************************************
** \brief Clock Setup macro definition
**
** - 0: CLOCK_SETTING_NONE - User provides own clock setting in application
** - 1: CLOCK_SETTING_CMSIS -
******************************************************************************/
#define CLOCK_SETTING_NONE 0u
#define CLOCK_SETTING_CMSIS 1u
/******************************************************************************/
/* */
/* START OF USER SETTINGS HERE */
/* =========================== */
/* */
/* All lines with '<<<' can be set by user. */
/* */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
extern void SystemInit (void); // Initialize the system
extern void SystemCoreClockUpdate (void); // Update SystemCoreClock variable
#ifdef __cplusplus
}
#endif
#endif /* __SYSTEM_HC32L136_H__ */

View File

@ -0,0 +1,111 @@
/*******************************************************************************
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file system_hc32l13x.h
**
** A detailed description is available at
** @link SampleGroup Some description @endlink
**
** - 2019-03-01 1.0 Lux First version.
**
******************************************************************************/
#ifndef __SYSTEM_HC32L13X_H__
#define __SYSTEM_HC32L13X_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('define') */
/******************************************************************************/
#define HWWD_DISABLE (1)
/**
******************************************************************************
** \brief Clock Setup macro definition
**
** - 0: CLOCK_SETTING_NONE - User provides own clock setting in application
** - 1: CLOCK_SETTING_CMSIS -
******************************************************************************/
#define CLOCK_SETTING_NONE 0u
#define CLOCK_SETTING_CMSIS 1u
/******************************************************************************/
/* */
/* START OF USER SETTINGS HERE */
/* =========================== */
/* */
/* All lines with '<<<' can be set by user. */
/* */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
extern void SystemInit (void); // Initialize the system
extern void SystemCoreClockUpdate (void); // Update SystemCoreClock variable
#ifdef __cplusplus
}
#endif
#endif /* __SYSTEM_HC32L13X_H__ */

View File

@ -0,0 +1,294 @@
;/******************************************************************************
;* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
;*
;* This software is owned and published by:
;* Huada Semiconductor Co.,Ltd ("HDSC").
;*
;* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
;* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
;*
;* This software contains source code for use with HDSC
;* components. This software is licensed by HDSC to be adapted only
;* for use in systems utilizing HDSC components. HDSC shall not be
;* responsible for misuse or illegal use of this software for devices not
;* supported herein. HDSC is providing this software "AS IS" and will
;* not be responsible for issues arising from incorrect user implementation
;* of the software.
;*
;* Disclaimer:
;* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
;* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
;* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
;* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
;* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
;* WARRANTY OF NONINFRINGEMENT.
;* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
;* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
;* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
;* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
;* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
;* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
;* SAVINGS OR PROFITS,
;* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
;* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
;* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
;* FROM, THE SOFTWARE.
;*
;* This software may be replicated in part or whole for the licensed use,
;* with the restriction that this Disclaimer and Copyright notice must be
;* included with each copy of this software, whether used in part or whole,
;* at all times.
;*/
;/*****************************************************************************/
;/*****************************************************************************/
;/* Startup for ARM */
;/* Version V1.0 */
;/* Date 2018-04-15 */
;/* Target-mcu {HC32L136} */
;/*****************************************************************************/
; Stack Configuration
; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
Stack_Size EQU 0x00000200
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
; Heap Configuration
; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB
; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size
__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset
DCD NMI_Handler ; NMI
DCD HardFault_Handler ; Hard Fault
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV
DCD SysTick_Handler ; SysTick
DCD IRQ000_Handler ;
DCD IRQ001_Handler ;
DCD IRQ002_Handler ;
DCD IRQ003_Handler ;
DCD IRQ004_Handler ;
DCD IRQ005_Handler ;
DCD IRQ006_Handler ;
DCD IRQ007_Handler ;
DCD IRQ008_Handler ;
DCD IRQ009_Handler ;
DCD IRQ010_Handler ;
DCD IRQ011_Handler ;
DCD IRQ012_Handler ;
DCD IRQ013_Handler ;
DCD IRQ014_Handler ;
DCD IRQ015_Handler ;
DCD IRQ016_Handler ;
DCD IRQ017_Handler ;
DCD IRQ018_Handler ;
DCD IRQ019_Handler ;
DCD IRQ020_Handler ;
DCD IRQ021_Handler ;
DCD IRQ022_Handler ;
DCD IRQ023_Handler ;
DCD IRQ024_Handler ;
DCD IRQ025_Handler ;
DCD IRQ026_Handler ;
DCD IRQ027_Handler ;
DCD IRQ028_Handler ;
DCD IRQ029_Handler ;
DCD IRQ030_Handler ;
DCD IRQ031_Handler ;
__Vectors_End
__Vectors_Size EQU __Vectors_End - __Vectors
AREA |.text|, CODE, READONLY
; Reset Handler
Reset_Handler PROC
EXPORT Reset_Handler [WEAK]
IMPORT SystemInit
IMPORT __main
;reset NVIC if in rom debug
LDR R0, =0x20000000
LDR R2, =0x0
MOVS R1, #0 ; for warning,
ADD R1, PC,#0 ; for A1609W,
CMP R1, R0
BLS RAMCODE
; ram code base address.
ADD R2, R0,R2
RAMCODE
; reset Vector table address.
LDR R0, =0xE000ED08
STR R2, [R0]
LDR R0, =SystemInit
BLX R0
LDR R0, =__main
BX R0
ENDP
; Dummy Exception Handlers (infinite loops which can be modified)
NMI_Handler PROC
EXPORT NMI_Handler [WEAK]
B .
ENDP
HardFault_Handler\
PROC
EXPORT HardFault_Handler [WEAK]
B .
ENDP
SVC_Handler PROC
EXPORT SVC_Handler [WEAK]
B .
ENDP
PendSV_Handler PROC
EXPORT PendSV_Handler [WEAK]
B .
ENDP
SysTick_Handler PROC
EXPORT SysTick_Handler [WEAK]
B .
ENDP
Default_Handler PROC
EXPORT IRQ000_Handler [WEAK]
EXPORT IRQ001_Handler [WEAK]
EXPORT IRQ002_Handler [WEAK]
EXPORT IRQ003_Handler [WEAK]
EXPORT IRQ004_Handler [WEAK]
EXPORT IRQ005_Handler [WEAK]
EXPORT IRQ006_Handler [WEAK]
EXPORT IRQ007_Handler [WEAK]
EXPORT IRQ008_Handler [WEAK]
EXPORT IRQ009_Handler [WEAK]
EXPORT IRQ010_Handler [WEAK]
EXPORT IRQ011_Handler [WEAK]
EXPORT IRQ012_Handler [WEAK]
EXPORT IRQ013_Handler [WEAK]
EXPORT IRQ014_Handler [WEAK]
EXPORT IRQ015_Handler [WEAK]
EXPORT IRQ016_Handler [WEAK]
EXPORT IRQ017_Handler [WEAK]
EXPORT IRQ018_Handler [WEAK]
EXPORT IRQ019_Handler [WEAK]
EXPORT IRQ020_Handler [WEAK]
EXPORT IRQ021_Handler [WEAK]
EXPORT IRQ022_Handler [WEAK]
EXPORT IRQ023_Handler [WEAK]
EXPORT IRQ024_Handler [WEAK]
EXPORT IRQ025_Handler [WEAK]
EXPORT IRQ026_Handler [WEAK]
EXPORT IRQ027_Handler [WEAK]
EXPORT IRQ028_Handler [WEAK]
EXPORT IRQ029_Handler [WEAK]
EXPORT IRQ030_Handler [WEAK]
EXPORT IRQ031_Handler [WEAK]
IRQ000_Handler
IRQ001_Handler
IRQ002_Handler
IRQ003_Handler
IRQ004_Handler
IRQ005_Handler
IRQ006_Handler
IRQ007_Handler
IRQ008_Handler
IRQ009_Handler
IRQ010_Handler
IRQ011_Handler
IRQ012_Handler
IRQ013_Handler
IRQ014_Handler
IRQ015_Handler
IRQ016_Handler
IRQ017_Handler
IRQ018_Handler
IRQ019_Handler
IRQ020_Handler
IRQ021_Handler
IRQ022_Handler
IRQ023_Handler
IRQ024_Handler
IRQ025_Handler
IRQ026_Handler
IRQ027_Handler
IRQ028_Handler
IRQ029_Handler
IRQ030_Handler
IRQ031_Handler
B .
ENDP
ALIGN
; User Initial Stack & Heap
IF :DEF:__MICROLIB
EXPORT __initial_sp
EXPORT __heap_base
EXPORT __heap_limit
ELSE
IMPORT __use_two_region_memory
EXPORT __user_initial_stackheap
__user_initial_stackheap
LDR R0, = Heap_Mem
LDR R1, =(Stack_Mem + Stack_Size)
LDR R2, = (Heap_Mem + Heap_Size)
LDR R3, = Stack_Mem
BX LR
ALIGN
ENDIF
END

View File

@ -0,0 +1,353 @@
;*******************************************************************************
; Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
;
; This software is owned and published by:
; Huada Semiconductor Co.,Ltd ("HDSC").
;
; BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
; BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
;
; This software contains source code for use with HDSC
; components. This software is licensed by HDSC to be adapted only
; for use in systems utilizing HDSC components. HDSC shall not be
; responsible for misuse or illegal use of this software for devices not
; supported herein. HDSC is providing this software "AS IS" and will
; not be responsible for issues arising from incorrect user implementation
; of the software.
;
; Disclaimer:
; HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
; REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
; ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
; WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
; WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
; WARRANTY OF NONINFRINGEMENT.
; HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
; NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
; LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
; LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
; INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
; INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
; SAVINGS OR PROFITS,
; EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
; YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
; INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
; FROM, THE SOFTWARE.
;
; This software may be replicated in part or whole for the licensed use,
; with the restriction that this Disclaimer and Copyright notice must be
; included with each copy of this software, whether used in part or whole,
; at all times.
;/
;/*****************************************************************************/
;/* Startup for IAR */
;/* Version V1.0 */
;/* Date 2018-04-15 */
;/* Target-mcu M0+ Device */
;/*****************************************************************************/
MODULE ?cstartup
;; Forward declaration of sections.
SECTION CSTACK:DATA:NOROOT(3)
EXTERN __iar_program_start
EXTERN SystemInit
PUBLIC __vector_table
SECTION .intvec:CODE:ROOT(8)
DATA
__vector_table DCD sfe(CSTACK)
DCD Reset_Handler
DCD NMI_Handler ; NMI
DCD HardFault_Handler ; Hard Fault
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall
DCD 0 ; Debug Monitor
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV
DCD SysTick_Handler ; SysTick
; Numbered IRQ handler vectors
; Note: renaming to device dependent ISR function names are done in
DCD IRQ000_Handler
DCD IRQ001_Handler
DCD IRQ002_Handler
DCD IRQ003_Handler
DCD IRQ004_Handler
DCD IRQ005_Handler
DCD IRQ006_Handler
DCD IRQ007_Handler
DCD IRQ008_Handler
DCD IRQ009_Handler
DCD IRQ010_Handler
DCD IRQ011_Handler
DCD IRQ012_Handler
DCD IRQ013_Handler
DCD IRQ014_Handler
DCD IRQ015_Handler
DCD IRQ016_Handler
DCD IRQ017_Handler
DCD IRQ018_Handler
DCD IRQ019_Handler
DCD IRQ020_Handler
DCD IRQ021_Handler
DCD IRQ022_Handler
DCD IRQ023_Handler
DCD IRQ024_Handler
DCD IRQ025_Handler
DCD IRQ026_Handler
DCD IRQ027_Handler
DCD IRQ028_Handler
DCD IRQ029_Handler
DCD IRQ030_Handler
DCD IRQ031_Handler
THUMB
PUBWEAK Reset_Handler
SECTION .text:CODE:NOROOT:REORDER(2)
Reset_Handler
;reset NVIC if in rom debug
LDR R0, =0x20000000
LDR R2, =0x0 ; vector offset
cmp PC, R0
bls ROMCODE
; ram code base address.
ADD R2, R0,R2
ROMCODE
; reset Vector table address.
LDR R0, =0xE000ED08
STR R2, [R0]
LDR R0, =SystemInit
BLX R0
LDR R0, =__iar_program_start
BX R0
PUBWEAK NMI_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
NMI_Handler
B NMI_Handler
PUBWEAK HardFault_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
HardFault_Handler
B HardFault_Handler
PUBWEAK SVC_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
SVC_Handler
B SVC_Handler
PUBWEAK PendSV_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
PendSV_Handler
B PendSV_Handler
PUBWEAK SysTick_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
SysTick_Handler
B SysTick_Handler
PUBWEAK IRQ000_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ000_Handler
B IRQ000_Handler
PUBWEAK IRQ001_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ001_Handler
B IRQ001_Handler
PUBWEAK IRQ002_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ002_Handler
B IRQ002_Handler
PUBWEAK IRQ003_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ003_Handler
B IRQ003_Handler
PUBWEAK IRQ004_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ004_Handler
B IRQ004_Handler
PUBWEAK IRQ005_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ005_Handler
B IRQ005_Handler
PUBWEAK IRQ006_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ006_Handler
B IRQ006_Handler
PUBWEAK IRQ007_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ007_Handler
B IRQ007_Handler
PUBWEAK IRQ008_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ008_Handler
B IRQ008_Handler
PUBWEAK IRQ009_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ009_Handler
B IRQ009_Handler
PUBWEAK IRQ010_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ010_Handler
B IRQ010_Handler
PUBWEAK IRQ011_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ011_Handler
B IRQ011_Handler
PUBWEAK IRQ012_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ012_Handler
B IRQ012_Handler
PUBWEAK IRQ013_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ013_Handler
B IRQ013_Handler
PUBWEAK IRQ014_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ014_Handler
B IRQ014_Handler
PUBWEAK IRQ015_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ015_Handler
B IRQ015_Handler
PUBWEAK IRQ016_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ016_Handler
B IRQ016_Handler
PUBWEAK IRQ017_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ017_Handler
B IRQ017_Handler
PUBWEAK IRQ018_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ018_Handler
B IRQ018_Handler
PUBWEAK IRQ019_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ019_Handler
B IRQ019_Handler
PUBWEAK IRQ020_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ020_Handler
B IRQ020_Handler
PUBWEAK IRQ021_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ021_Handler
B IRQ021_Handler
PUBWEAK IRQ022_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ022_Handler
B IRQ022_Handler
PUBWEAK IRQ023_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ023_Handler
B IRQ023_Handler
PUBWEAK IRQ024_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ024_Handler
B IRQ024_Handler
PUBWEAK IRQ025_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ025_Handler
B IRQ025_Handler
PUBWEAK IRQ026_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ026_Handler
B IRQ026_Handler
PUBWEAK IRQ027_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ027_Handler
B IRQ027_Handler
PUBWEAK IRQ028_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ028_Handler
B IRQ028_Handler
PUBWEAK IRQ029_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ029_Handler
B IRQ029_Handler
PUBWEAK IRQ030_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ030_Handler
B IRQ030_Handler
PUBWEAK IRQ031_Handler
SECTION .text:CODE:NOROOT:REORDER(1)
IRQ031_Handler
B IRQ031_Handler
END

View File

@ -0,0 +1,477 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file interrupts_hc32l136.c
**
** Interrupt management
** @link Driver Group Some description @endlink
**
** - 2018-04-15 1.0 Lux First version.
**
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
void Gpio_IRQHandler(uint8_t u8Param);
__WEAKDEF void Dma_IRQHandler(uint8_t u8Param);
void Uart_IRQHandler(uint8_t u8Param);
__WEAKDEF void LpUart_IRQHandler(uint8_t u8Param);
__WEAKDEF void Spi_IRQHandler(uint8_t u8Param);
__WEAKDEF void I2c_IRQHandler(uint8_t u8Param);
__WEAKDEF void Tim_IRQHandler(uint8_t u8Param);
__WEAKDEF void Tim3_IRQHandler(uint8_t u8Param);
__WEAKDEF void Adt_IRQHandler(uint8_t u8Param);
__WEAKDEF void LpTim_IRQHandler(uint8_t u8Param);
__WEAKDEF void Pca_IRQHandler(uint8_t u8Param);
__WEAKDEF void Wdt_IRQHandler(uint8_t u8Param);
__WEAKDEF void Vc_IRQHandler(uint8_t u8Param);
__WEAKDEF void Rtc_IRQHandler(uint8_t u8Param);
__WEAKDEF void Adc_IRQHandler(uint8_t u8Param);
__WEAKDEF void Pcnt_IRQHandler(uint8_t u8Param);
__WEAKDEF void Lvd_IRQHandler(uint8_t u8Param);
__WEAKDEF void Lcd_IRQHandler(uint8_t u8Param);
__WEAKDEF void EfRam_IRQHandler(uint8_t u8Param);
__WEAKDEF void ClkTrim_IRQHandler(uint8_t u8Param);
/**
*******************************************************************************
** \brief NVIC 使
**
** \param [in] enIrq
** \param [in] enLevel
** \param [in] bEn
** \retval Ok
**
******************************************************************************/
void EnableNvic(IRQn_Type enIrq, en_irq_level_t enLevel, boolean_t bEn)
{
NVIC_ClearPendingIRQ(enIrq);
NVIC_SetPriority(enIrq, enLevel);
if (TRUE == bEn)
{
NVIC_EnableIRQ(enIrq);
}
else
{
NVIC_DisableIRQ(enIrq);
}
}
/**
*******************************************************************************
** \brief NVIC hardware fault
**
**
** \retval
******************************************************************************/
//void HardFault_Handler(void)
//{
// volatile int a = 0;
// while( 0 == a)
// {
// ;
// }
//}
/**
*******************************************************************************
** \brief GPIO PortA
**
** \retval
******************************************************************************/
void PORTA_IRQHandler(void)
{
Gpio_IRQHandler(0);
}
/**
*******************************************************************************
** \brief GPIO PortB
**
** \retval
******************************************************************************/
void PORTB_IRQHandler(void)
{
Gpio_IRQHandler(1);
}
/**
*******************************************************************************
** \brief GPIO PortC
**
** \retval
******************************************************************************/
void PORTC_IRQHandler(void)
{
Gpio_IRQHandler(2);
}
/**
*******************************************************************************
** \brief GPIO PortD
**
** \retval
******************************************************************************/
void PORTD_IRQHandler(void)
{
Gpio_IRQHandler(3);
}
/**
*******************************************************************************
** \brief DMAC
**
** \retval
******************************************************************************/
void DMAC_IRQHandler(void)
{
Dma_IRQHandler(0);
}
/**
*******************************************************************************
** \brief UART0 0
**
** \retval
******************************************************************************/
void UART0_IRQHandler(void)
{
Uart_IRQHandler(0);
}
/**
*******************************************************************************
** \brief UART1 1
**
** \retval
******************************************************************************/
void UART1_IRQHandler(void)
{
Uart_IRQHandler(1);
}
/**
*******************************************************************************
** \brief LPUART0 0
**
** \retval
******************************************************************************/
void LPUART0_IRQHandler(void)
{
LpUart_IRQHandler(0);
}
/**
*******************************************************************************
** \brief LPUART1 1
**
** \retval
******************************************************************************/
void LPUART1_IRQHandler(void)
{
LpUart_IRQHandler(1);
}
/**
*******************************************************************************
** \brief SPI0
**
** \retval
******************************************************************************/
void SPI0_IRQHandler(void)
{
Spi_IRQHandler(0);
}
/**
*******************************************************************************
** \brief SPI1
**
** \retval
******************************************************************************/
void SPI1_IRQHandler(void)
{
Spi_IRQHandler(1);
}
/**
*******************************************************************************
** \brief I2C0
**
** \retval
******************************************************************************/
void I2C0_IRQHandler(void)
{
I2c_IRQHandler(0);
}
/**
*******************************************************************************
** \brief I2C1
**
** \retval
******************************************************************************/
void I2C1_IRQHandler(void)
{
I2c_IRQHandler(1);
}
/**
*******************************************************************************
** \brief TIM0 0
**
** \retval
******************************************************************************/
void TIM0_IRQHandler(void)
{
Tim_IRQHandler(0);
}
/**
*******************************************************************************
** \brief TIM1 1
**
** \retval
******************************************************************************/
void TIM1_IRQHandler(void)
{
Tim_IRQHandler(1);
}
/**
*******************************************************************************
** \brief TIM2 2
**
** \retval
******************************************************************************/
void TIM2_IRQHandler(void)
{
Tim_IRQHandler(2);
}
/**
*******************************************************************************
** \brief TIM3 3
**
** \retval
******************************************************************************/
void TIM3_IRQHandler(void)
{
Tim3_IRQHandler(0);
}
/**
*******************************************************************************
** \brief LPTIM
**
** \retval
******************************************************************************/
void LPTIM_IRQHandler(void)
{
LpTim_IRQHandler(0);
}
/**
*******************************************************************************
** \brief TIM4 4
**
** \retval
******************************************************************************/
void TIM4_IRQHandler(void)
{
Adt_IRQHandler(4);
}
/**
*******************************************************************************
** \brief TIM5 5
**
** \retval
******************************************************************************/
void TIM5_IRQHandler(void)
{
Adt_IRQHandler(5);
}
/**
*******************************************************************************
** \brief TIM6 6
**
** \retval
******************************************************************************/
void TIM6_IRQHandler(void)
{
Adt_IRQHandler(6);
}
/**
*******************************************************************************
** \brief PCA
**
** \retval
******************************************************************************/
void PCA_IRQHandler(void)
{
Pca_IRQHandler(0);
}
/**
*******************************************************************************
** \brief WDT
**
** \retval
******************************************************************************/
void WDT_IRQHandler(void)
{
Wdt_IRQHandler(0);
}
/**
*******************************************************************************
** \brief RTC
**
** \retval
******************************************************************************/
void RTC_IRQHandler(void)
{
Rtc_IRQHandler(0);
}
/**
*******************************************************************************
** \brief ADC
**
** \retval
******************************************************************************/
void ADC_IRQHandler(void)
{
Adc_IRQHandler(0);
}
/**
*******************************************************************************
** \brief PCNT
**
** \retval
******************************************************************************/
void PCNT_IRQHandler(void)
{
Pcnt_IRQHandler(0);
}
/**
*******************************************************************************
** \brief 0
**
** \retval
******************************************************************************/
void VC0_IRQHandler(void)
{
Vc_IRQHandler(0);
}
/**
*******************************************************************************
** \brief 1
**
** \retval
******************************************************************************/
void VC1_IRQHandler(void)
{
Vc_IRQHandler(1);
}
/**
*******************************************************************************
** \brief
**
** \retval
******************************************************************************/
void LVD_IRQHandler(void)
{
Lvd_IRQHandler(0);
}
/**
*******************************************************************************
** \brief LCD
**
** \retval
******************************************************************************/
void LCD_IRQHandler(void)
{
Lcd_IRQHandler(0);
}
/**
*******************************************************************************
** \brief RAM
**
** \retval
******************************************************************************/
void EF_RAM_IRQHandler(void)
{
EfRam_IRQHandler(0);
}
/**
*******************************************************************************
** \brief
**
** \retval
******************************************************************************/
void CLKTRIM_IRQHandler(void)
{
ClkTrim_IRQHandler(0);
}
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/

View File

@ -0,0 +1,107 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file system_hc32l136.h
**
** A detailed description is available at
** @link SampleGroup Some description @endlink
**
** - 2018-03-09 1.0 Lux First version.
**
******************************************************************************/
#ifndef __SYSTEM_HC32L136_H__
#define __SYSTEM_HC32L136_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('define') */
/******************************************************************************/
#define HWWD_DISABLE (1)
/**
******************************************************************************
** \brief Clock Setup macro definition
**
** - 0: CLOCK_SETTING_NONE - User provides own clock setting in application
** - 1: CLOCK_SETTING_CMSIS -
******************************************************************************/
#define CLOCK_SETTING_NONE 0u
#define CLOCK_SETTING_CMSIS 1u
/******************************************************************************/
/* */
/* START OF USER SETTINGS HERE */
/* =========================== */
/* */
/* All lines with '<<<' can be set by user. */
/* */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
extern uint32_t SystemCoreClock; // System Clock Frequency (Core Clock)
extern void SystemInit (void); // Initialize the system
extern void SystemCoreClockUpdate (void); // Update SystemCoreClock variable
#ifdef __cplusplus
}
#endif
#endif /* __SYSTEM_HC32L136_H__ */

View File

@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (C) 2019, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file system_hc32l13x.c
**
** System clock initialization.
** @link SampleGroup Some description @endlink
**
** - 2019-03-01 1.0 Lux First version.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "base_types.h"
#include "hc32l136.h"
#include "system_hc32l13x.h"
#include "sysctrl.h"
/**
******************************************************************************
** System Clock Frequency (Core Clock) Variable according CMSIS
******************************************************************************/
uint32_t SystemCoreClock = 4000000;
//add clock source.
void SystemCoreClockUpdate (void) // Update SystemCoreClock variable
{
SystemCoreClock = Sysctrl_GetHClkFreq();
}
/**
******************************************************************************
** \brief Setup the microcontroller system. Initialize the System and update
** the SystemCoreClock variable.
**
** \param none
** \return none
******************************************************************************/
void SystemInit(void)
{
SystemCoreClockUpdate();
}

View File

@ -0,0 +1,894 @@
/**************************************************************************//**
* @file cmsis_armcc.h
* @brief CMSIS compiler ARMCC (Arm Compiler 5) header file
* @version V5.1.0
* @date 08. May 2019
******************************************************************************/
/*
* Copyright (c) 2009-2019 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_ARMCC_H
#define __CMSIS_ARMCC_H
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 400677)
#error "Please use Arm Compiler Toolchain V4.0.677 or later!"
#endif
/* CMSIS compiler control architecture macros */
#if ((defined (__TARGET_ARCH_6_M ) && (__TARGET_ARCH_6_M == 1)) || \
(defined (__TARGET_ARCH_6S_M ) && (__TARGET_ARCH_6S_M == 1)) )
#define __ARM_ARCH_6M__ 1
#endif
#if (defined (__TARGET_ARCH_7_M ) && (__TARGET_ARCH_7_M == 1))
#define __ARM_ARCH_7M__ 1
#endif
#if (defined (__TARGET_ARCH_7E_M) && (__TARGET_ARCH_7E_M == 1))
#define __ARM_ARCH_7EM__ 1
#endif
/* __ARM_ARCH_8M_BASE__ not applicable */
/* __ARM_ARCH_8M_MAIN__ not applicable */
/* CMSIS compiler control DSP macros */
#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
#define __ARM_FEATURE_DSP 1
#endif
/* CMSIS compiler specific defines */
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE __inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static __inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE static __forceinline
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __declspec(noreturn)
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed))
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT __packed struct
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION __packed union
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
#define __UNALIGNED_UINT32(x) (*((__packed uint32_t *)(x)))
#endif
#ifndef __UNALIGNED_UINT16_WRITE
#define __UNALIGNED_UINT16_WRITE(addr, val) ((*((__packed uint16_t *)(addr))) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
#define __UNALIGNED_UINT16_READ(addr) (*((const __packed uint16_t *)(addr)))
#endif
#ifndef __UNALIGNED_UINT32_WRITE
#define __UNALIGNED_UINT32_WRITE(addr, val) ((*((__packed uint32_t *)(addr))) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
#define __UNALIGNED_UINT32_READ(addr) (*((const __packed uint32_t *)(addr)))
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#ifndef __RESTRICT
#define __RESTRICT __restrict
#endif
#ifndef __COMPILER_BARRIER
#define __COMPILER_BARRIER() __memory_changed()
#endif
/* ######################### Startup and Lowlevel Init ######################## */
#ifndef __PROGRAM_START
#define __PROGRAM_START __main
#endif
#ifndef __INITIAL_SP
#define __INITIAL_SP Image$$ARM_LIB_STACK$$ZI$$Limit
#endif
#ifndef __STACK_LIMIT
#define __STACK_LIMIT Image$$ARM_LIB_STACK$$ZI$$Base
#endif
#ifndef __VECTOR_TABLE
#define __VECTOR_TABLE __Vectors
#endif
#ifndef __VECTOR_TABLE_ATTRIBUTE
#define __VECTOR_TABLE_ATTRIBUTE __attribute((used, section("RESET")))
#endif
/* ########################### Core Function Access ########################### */
/** \ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions
@{
*/
/**
\brief Enable IRQ Interrupts
\details Enables IRQ interrupts by clearing the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
/* intrinsic void __enable_irq(); */
/**
\brief Disable IRQ Interrupts
\details Disables IRQ interrupts by setting the I-bit in the CPSR.
Can only be executed in Privileged modes.
*/
/* intrinsic void __disable_irq(); */
/**
\brief Get Control Register
\details Returns the content of the Control Register.
\return Control Register value
*/
__STATIC_INLINE uint32_t __get_CONTROL(void)
{
register uint32_t __regControl __ASM("control");
return(__regControl);
}
/**
\brief Set Control Register
\details Writes the given value to the Control Register.
\param [in] control Control Register value to set
*/
__STATIC_INLINE void __set_CONTROL(uint32_t control)
{
register uint32_t __regControl __ASM("control");
__regControl = control;
}
/**
\brief Get IPSR Register
\details Returns the content of the IPSR Register.
\return IPSR Register value
*/
__STATIC_INLINE uint32_t __get_IPSR(void)
{
register uint32_t __regIPSR __ASM("ipsr");
return(__regIPSR);
}
/**
\brief Get APSR Register
\details Returns the content of the APSR Register.
\return APSR Register value
*/
__STATIC_INLINE uint32_t __get_APSR(void)
{
register uint32_t __regAPSR __ASM("apsr");
return(__regAPSR);
}
/**
\brief Get xPSR Register
\details Returns the content of the xPSR Register.
\return xPSR Register value
*/
__STATIC_INLINE uint32_t __get_xPSR(void)
{
register uint32_t __regXPSR __ASM("xpsr");
return(__regXPSR);
}
/**
\brief Get Process Stack Pointer
\details Returns the current value of the Process Stack Pointer (PSP).
\return PSP Register value
*/
__STATIC_INLINE uint32_t __get_PSP(void)
{
register uint32_t __regProcessStackPointer __ASM("psp");
return(__regProcessStackPointer);
}
/**
\brief Set Process Stack Pointer
\details Assigns the given value to the Process Stack Pointer (PSP).
\param [in] topOfProcStack Process Stack Pointer value to set
*/
__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack)
{
register uint32_t __regProcessStackPointer __ASM("psp");
__regProcessStackPointer = topOfProcStack;
}
/**
\brief Get Main Stack Pointer
\details Returns the current value of the Main Stack Pointer (MSP).
\return MSP Register value
*/
__STATIC_INLINE uint32_t __get_MSP(void)
{
register uint32_t __regMainStackPointer __ASM("msp");
return(__regMainStackPointer);
}
/**
\brief Set Main Stack Pointer
\details Assigns the given value to the Main Stack Pointer (MSP).
\param [in] topOfMainStack Main Stack Pointer value to set
*/
__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack)
{
register uint32_t __regMainStackPointer __ASM("msp");
__regMainStackPointer = topOfMainStack;
}
/**
\brief Get Priority Mask
\details Returns the current state of the priority mask bit from the Priority Mask Register.
\return Priority Mask value
*/
__STATIC_INLINE uint32_t __get_PRIMASK(void)
{
register uint32_t __regPriMask __ASM("primask");
return(__regPriMask);
}
/**
\brief Set Priority Mask
\details Assigns the given value to the Priority Mask Register.
\param [in] priMask Priority Mask
*/
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
register uint32_t __regPriMask __ASM("primask");
__regPriMask = (priMask);
}
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
/**
\brief Enable FIQ
\details Enables FIQ interrupts by clearing the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __enable_fault_irq __enable_fiq
/**
\brief Disable FIQ
\details Disables FIQ interrupts by setting the F-bit in the CPSR.
Can only be executed in Privileged modes.
*/
#define __disable_fault_irq __disable_fiq
/**
\brief Get Base Priority
\details Returns the current value of the Base Priority register.
\return Base Priority register value
*/
__STATIC_INLINE uint32_t __get_BASEPRI(void)
{
register uint32_t __regBasePri __ASM("basepri");
return(__regBasePri);
}
/**
\brief Set Base Priority
\details Assigns the given value to the Base Priority register.
\param [in] basePri Base Priority value to set
*/
__STATIC_INLINE void __set_BASEPRI(uint32_t basePri)
{
register uint32_t __regBasePri __ASM("basepri");
__regBasePri = (basePri & 0xFFU);
}
/**
\brief Set Base Priority with condition
\details Assigns the given value to the Base Priority register only if BASEPRI masking is disabled,
or the new value increases the BASEPRI priority level.
\param [in] basePri Base Priority value to set
*/
__STATIC_INLINE void __set_BASEPRI_MAX(uint32_t basePri)
{
register uint32_t __regBasePriMax __ASM("basepri_max");
__regBasePriMax = (basePri & 0xFFU);
}
/**
\brief Get Fault Mask
\details Returns the current value of the Fault Mask register.
\return Fault Mask register value
*/
__STATIC_INLINE uint32_t __get_FAULTMASK(void)
{
register uint32_t __regFaultMask __ASM("faultmask");
return(__regFaultMask);
}
/**
\brief Set Fault Mask
\details Assigns the given value to the Fault Mask register.
\param [in] faultMask Fault Mask value to set
*/
__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask)
{
register uint32_t __regFaultMask __ASM("faultmask");
__regFaultMask = (faultMask & (uint32_t)1U);
}
#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
/**
\brief Get FPSCR
\details Returns the current value of the Floating Point Status/Control register.
\return Floating Point Status/Control register value
*/
__STATIC_INLINE uint32_t __get_FPSCR(void)
{
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
register uint32_t __regfpscr __ASM("fpscr");
return(__regfpscr);
#else
return(0U);
#endif
}
/**
\brief Set FPSCR
\details Assigns the given value to the Floating Point Status/Control register.
\param [in] fpscr Floating Point Status/Control value to set
*/
__STATIC_INLINE void __set_FPSCR(uint32_t fpscr)
{
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
register uint32_t __regfpscr __ASM("fpscr");
__regfpscr = (fpscr);
#else
(void)fpscr;
#endif
}
/*@} end of CMSIS_Core_RegAccFunctions */
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
/**
\brief No Operation
\details No Operation does nothing. This instruction can be used for code alignment purposes.
*/
#define __NOP __nop
/**
\brief Wait For Interrupt
\details Wait For Interrupt is a hint instruction that suspends execution until one of a number of events occurs.
*/
#define __WFI __wfi
/**
\brief Wait For Event
\details Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
#define __WFE __wfe
/**
\brief Send Event
\details Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
#define __SEV __sev
/**
\brief Instruction Synchronization Barrier
\details Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or memory,
after the instruction has been completed.
*/
#define __ISB() do {\
__schedule_barrier();\
__isb(0xF);\
__schedule_barrier();\
} while (0U)
/**
\brief Data Synchronization Barrier
\details Acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
#define __DSB() do {\
__schedule_barrier();\
__dsb(0xF);\
__schedule_barrier();\
} while (0U)
/**
\brief Data Memory Barrier
\details Ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
#define __DMB() do {\
__schedule_barrier();\
__dmb(0xF);\
__schedule_barrier();\
} while (0U)
/**
\brief Reverse byte order (32 bit)
\details Reverses the byte order in unsigned integer value. For example, 0x12345678 becomes 0x78563412.
\param [in] value Value to reverse
\return Reversed value
*/
#define __REV __rev
/**
\brief Reverse byte order (16 bit)
\details Reverses the byte order within each halfword of a word. For example, 0x12345678 becomes 0x34127856.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)
{
rev16 r0, r0
bx lr
}
#endif
/**
\brief Reverse byte order (16 bit)
\details Reverses the byte order in a 16-bit value and returns the signed 16-bit result. For example, 0x0080 becomes 0x8000.
\param [in] value Value to reverse
\return Reversed value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int16_t __REVSH(int16_t value)
{
revsh r0, r0
bx lr
}
#endif
/**
\brief Rotate Right in unsigned value (32 bit)
\details Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.
\param [in] op1 Value to rotate
\param [in] op2 Number of Bits to rotate
\return Rotated value
*/
#define __ROR __ror
/**
\brief Breakpoint
\details Causes the processor to enter Debug state.
Debug tools can use this to investigate system state when the instruction at a particular address is reached.
\param [in] value is ignored by the processor.
If required, a debugger can use it to store additional information about the breakpoint.
*/
#define __BKPT(value) __breakpoint(value)
/**
\brief Reverse bit order of value
\details Reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
#define __RBIT __rbit
#else
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */
result = value; /* r will be reversed bits of v; first get LSB of v */
for (value >>= 1U; value != 0U; value >>= 1U)
{
result <<= 1U;
result |= value & 1U;
s--;
}
result <<= s; /* shift when v's highest bits are zero */
return result;
}
#endif
/**
\brief Count leading zeros
\details Counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
#define __CLZ __clz
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
/**
\brief LDR Exclusive (8 bit)
\details Executes a exclusive LDR instruction for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
#else
#define __LDREXB(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint8_t ) __ldrex(ptr)) _Pragma("pop")
#endif
/**
\brief LDR Exclusive (16 bit)
\details Executes a exclusive LDR instruction for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
#else
#define __LDREXH(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint16_t) __ldrex(ptr)) _Pragma("pop")
#endif
/**
\brief LDR Exclusive (32 bit)
\details Executes a exclusive LDR instruction for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
#else
#define __LDREXW(ptr) _Pragma("push") _Pragma("diag_suppress 3731") ((uint32_t ) __ldrex(ptr)) _Pragma("pop")
#endif
/**
\brief STR Exclusive (8 bit)
\details Executes a exclusive STR instruction for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
#define __STREXB(value, ptr) __strex(value, ptr)
#else
#define __STREXB(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
#endif
/**
\brief STR Exclusive (16 bit)
\details Executes a exclusive STR instruction for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
#define __STREXH(value, ptr) __strex(value, ptr)
#else
#define __STREXH(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
#endif
/**
\brief STR Exclusive (32 bit)
\details Executes a exclusive STR instruction for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 5060020)
#define __STREXW(value, ptr) __strex(value, ptr)
#else
#define __STREXW(value, ptr) _Pragma("push") _Pragma("diag_suppress 3731") __strex(value, ptr) _Pragma("pop")
#endif
/**
\brief Remove the exclusive lock
\details Removes the exclusive lock which is created by LDREX.
*/
#define __CLREX __clrex
/**
\brief Signed Saturate
\details Saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT __ssat
/**
\brief Unsigned Saturate
\details Saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT __usat
/**
\brief Rotate Right with Extend (32 bit)
\details Moves each bit of a bitstring right by one bit.
The carry input is shifted in at the left end of the bitstring.
\param [in] value Value to rotate
\return Rotated value
*/
#ifndef __NO_EMBEDDED_ASM
__attribute__((section(".rrx_text"))) __STATIC_INLINE __ASM uint32_t __RRX(uint32_t value)
{
rrx r0, r0
bx lr
}
#endif
/**
\brief LDRT Unprivileged (8 bit)
\details Executes a Unprivileged LDRT instruction for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#define __LDRBT(ptr) ((uint8_t ) __ldrt(ptr))
/**
\brief LDRT Unprivileged (16 bit)
\details Executes a Unprivileged LDRT instruction for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#define __LDRHT(ptr) ((uint16_t) __ldrt(ptr))
/**
\brief LDRT Unprivileged (32 bit)
\details Executes a Unprivileged LDRT instruction for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#define __LDRT(ptr) ((uint32_t ) __ldrt(ptr))
/**
\brief STRT Unprivileged (8 bit)
\details Executes a Unprivileged STRT instruction for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
#define __STRBT(value, ptr) __strt(value, ptr)
/**
\brief STRT Unprivileged (16 bit)
\details Executes a Unprivileged STRT instruction for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
#define __STRHT(value, ptr) __strt(value, ptr)
/**
\brief STRT Unprivileged (32 bit)
\details Executes a Unprivileged STRT instruction for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
*/
#define __STRT(value, ptr) __strt(value, ptr)
#else /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
/**
\brief Signed Saturate
\details Saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
__attribute__((always_inline)) __STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
{
if ((sat >= 1U) && (sat <= 32U))
{
const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
const int32_t min = -1 - max ;
if (val > max)
{
return max;
}
else if (val < min)
{
return min;
}
}
return val;
}
/**
\brief Unsigned Saturate
\details Saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
__attribute__((always_inline)) __STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
{
if (sat <= 31U)
{
const uint32_t max = ((1U << sat) - 1U);
if (val > (int32_t)max)
{
return max;
}
else if (val < 0)
{
return 0U;
}
}
return (uint32_t)val;
}
#endif /* ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__ == 1)) || \
(defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
/* ################### Compiler specific Intrinsics ########################### */
/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics
Access to dedicated SIMD instructions
@{
*/
#if ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) )
#define __SADD8 __sadd8
#define __QADD8 __qadd8
#define __SHADD8 __shadd8
#define __UADD8 __uadd8
#define __UQADD8 __uqadd8
#define __UHADD8 __uhadd8
#define __SSUB8 __ssub8
#define __QSUB8 __qsub8
#define __SHSUB8 __shsub8
#define __USUB8 __usub8
#define __UQSUB8 __uqsub8
#define __UHSUB8 __uhsub8
#define __SADD16 __sadd16
#define __QADD16 __qadd16
#define __SHADD16 __shadd16
#define __UADD16 __uadd16
#define __UQADD16 __uqadd16
#define __UHADD16 __uhadd16
#define __SSUB16 __ssub16
#define __QSUB16 __qsub16
#define __SHSUB16 __shsub16
#define __USUB16 __usub16
#define __UQSUB16 __uqsub16
#define __UHSUB16 __uhsub16
#define __SASX __sasx
#define __QASX __qasx
#define __SHASX __shasx
#define __UASX __uasx
#define __UQASX __uqasx
#define __UHASX __uhasx
#define __SSAX __ssax
#define __QSAX __qsax
#define __SHSAX __shsax
#define __USAX __usax
#define __UQSAX __uqsax
#define __UHSAX __uhsax
#define __USAD8 __usad8
#define __USADA8 __usada8
#define __SSAT16 __ssat16
#define __USAT16 __usat16
#define __UXTB16 __uxtb16
#define __UXTAB16 __uxtab16
#define __SXTB16 __sxtb16
#define __SXTAB16 __sxtab16
#define __SMUAD __smuad
#define __SMUADX __smuadx
#define __SMLAD __smlad
#define __SMLADX __smladx
#define __SMLALD __smlald
#define __SMLALDX __smlaldx
#define __SMUSD __smusd
#define __SMUSDX __smusdx
#define __SMLSD __smlsd
#define __SMLSDX __smlsdx
#define __SMLSLD __smlsld
#define __SMLSLDX __smlsldx
#define __SEL __sel
#define __QADD __qadd
#define __QSUB __qsub
#define __PKHBT(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0x0000FFFFUL) | \
((((uint32_t)(ARG2)) << (ARG3)) & 0xFFFF0000UL) )
#define __PKHTB(ARG1,ARG2,ARG3) ( ((((uint32_t)(ARG1)) ) & 0xFFFF0000UL) | \
((((uint32_t)(ARG2)) >> (ARG3)) & 0x0000FFFFUL) )
#define __SMMLA(ARG1,ARG2,ARG3) ( (int32_t)((((int64_t)(ARG1) * (ARG2)) + \
((int64_t)(ARG3) << 32U) ) >> 32U))
#endif /* ((defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) ) */
/*@} end of group CMSIS_SIMD_intrinsics */
#endif /* __CMSIS_ARMCC_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,283 @@
/**************************************************************************//**
* @file cmsis_compiler.h
* @brief CMSIS compiler generic header file
* @version V5.1.0
* @date 09. October 2018
******************************************************************************/
/*
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CMSIS_COMPILER_H
#define __CMSIS_COMPILER_H
#include <stdint.h>
/*
* Arm Compiler 4/5
*/
#if defined ( __CC_ARM )
#include "cmsis_armcc.h"
/*
* Arm Compiler 6.6 LTM (armclang)
*/
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) && (__ARMCC_VERSION < 6100100)
#include "cmsis_armclang_ltm.h"
/*
* Arm Compiler above 6.10.1 (armclang)
*/
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6100100)
#include "cmsis_armclang.h"
/*
* GNU Compiler
*/
#elif defined ( __GNUC__ )
#include "cmsis_gcc.h"
/*
* IAR Compiler
*/
#elif defined ( __ICCARM__ )
#include <cmsis_iccarm.h>
/*
* TI Arm Compiler
*/
#elif defined ( __TI_ARM__ )
#include <cmsis_ccs.h>
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __attribute__((packed))
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __attribute__((packed))
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __attribute__((packed))
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
struct __attribute__((packed)) T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void*)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __attribute__((aligned(x)))
#endif
#ifndef __RESTRICT
#define __RESTRICT __restrict
#endif
#ifndef __COMPILER_BARRIER
#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
#define __COMPILER_BARRIER() (void)0
#endif
/*
* TASKING Compiler
*/
#elif defined ( __TASKING__ )
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all intrinsics,
* Including the CMSIS ones.
*/
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
#define __NO_RETURN __attribute__((noreturn))
#endif
#ifndef __USED
#define __USED __attribute__((used))
#endif
#ifndef __WEAK
#define __WEAK __attribute__((weak))
#endif
#ifndef __PACKED
#define __PACKED __packed__
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT struct __packed__
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION union __packed__
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
struct __packed__ T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#define __ALIGNED(x) __align(x)
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
#ifndef __COMPILER_BARRIER
#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
#define __COMPILER_BARRIER() (void)0
#endif
/*
* COSMIC Compiler
*/
#elif defined ( __CSMC__ )
#include <cmsis_csm.h>
#ifndef __ASM
#define __ASM _asm
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __STATIC_INLINE
#endif
#ifndef __NO_RETURN
// NO RETURN is automatically detected hence no warning here
#define __NO_RETURN
#endif
#ifndef __USED
#warning No compiler specific solution for __USED. __USED is ignored.
#define __USED
#endif
#ifndef __WEAK
#define __WEAK __weak
#endif
#ifndef __PACKED
#define __PACKED @packed
#endif
#ifndef __PACKED_STRUCT
#define __PACKED_STRUCT @packed struct
#endif
#ifndef __PACKED_UNION
#define __PACKED_UNION @packed union
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
@packed struct T_UINT32 { uint32_t v; };
#define __UNALIGNED_UINT32(x) (((struct T_UINT32 *)(x))->v)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
__PACKED_STRUCT T_UINT16_WRITE { uint16_t v; };
#define __UNALIGNED_UINT16_WRITE(addr, val) (void)((((struct T_UINT16_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT16_READ
__PACKED_STRUCT T_UINT16_READ { uint16_t v; };
#define __UNALIGNED_UINT16_READ(addr) (((const struct T_UINT16_READ *)(const void *)(addr))->v)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
__PACKED_STRUCT T_UINT32_WRITE { uint32_t v; };
#define __UNALIGNED_UINT32_WRITE(addr, val) (void)((((struct T_UINT32_WRITE *)(void *)(addr))->v) = (val))
#endif
#ifndef __UNALIGNED_UINT32_READ
__PACKED_STRUCT T_UINT32_READ { uint32_t v; };
#define __UNALIGNED_UINT32_READ(addr) (((const struct T_UINT32_READ *)(const void *)(addr))->v)
#endif
#ifndef __ALIGNED
#warning No compiler specific solution for __ALIGNED. __ALIGNED is ignored.
#define __ALIGNED(x)
#endif
#ifndef __RESTRICT
#warning No compiler specific solution for __RESTRICT. __RESTRICT is ignored.
#define __RESTRICT
#endif
#ifndef __COMPILER_BARRIER
#warning No compiler specific solution for __COMPILER_BARRIER. __COMPILER_BARRIER is ignored.
#define __COMPILER_BARRIER() (void)0
#endif
#else
#error Unknown compiler.
#endif
#endif /* __CMSIS_COMPILER_H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,964 @@
/**************************************************************************//**
* @file cmsis_iccarm.h
* @brief CMSIS compiler ICCARM (IAR Compiler for Arm) header file
* @version V5.1.0
* @date 08. May 2019
******************************************************************************/
//------------------------------------------------------------------------------
//
// Copyright (c) 2017-2019 IAR Systems
// Copyright (c) 2017-2019 Arm Limited. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//------------------------------------------------------------------------------
#ifndef __CMSIS_ICCARM_H__
#define __CMSIS_ICCARM_H__
#ifndef __ICCARM__
#error This file should only be compiled by ICCARM
#endif
#pragma system_include
#define __IAR_FT _Pragma("inline=forced") __intrinsic
#if (__VER__ >= 8000000)
#define __ICCARM_V8 1
#else
#define __ICCARM_V8 0
#endif
#ifndef __ALIGNED
#if __ICCARM_V8
#define __ALIGNED(x) __attribute__((aligned(x)))
#elif (__VER__ >= 7080000)
/* Needs IAR language extensions */
#define __ALIGNED(x) __attribute__((aligned(x)))
#else
#warning No compiler specific solution for __ALIGNED.__ALIGNED is ignored.
#define __ALIGNED(x)
#endif
#endif
/* Define compiler macros for CPU architecture, used in CMSIS 5.
*/
#if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ || __ARM_ARCH_8M_BASE__ || __ARM_ARCH_8M_MAIN__
/* Macros already defined */
#else
#if defined(__ARM8M_MAINLINE__) || defined(__ARM8EM_MAINLINE__)
#define __ARM_ARCH_8M_MAIN__ 1
#elif defined(__ARM8M_BASELINE__)
#define __ARM_ARCH_8M_BASE__ 1
#elif defined(__ARM_ARCH_PROFILE) && __ARM_ARCH_PROFILE == 'M'
#if __ARM_ARCH == 6
#define __ARM_ARCH_6M__ 1
#elif __ARM_ARCH == 7
#if __ARM_FEATURE_DSP
#define __ARM_ARCH_7EM__ 1
#else
#define __ARM_ARCH_7M__ 1
#endif
#endif /* __ARM_ARCH */
#endif /* __ARM_ARCH_PROFILE == 'M' */
#endif
/* Alternativ core deduction for older ICCARM's */
#if !defined(__ARM_ARCH_6M__) && !defined(__ARM_ARCH_7M__) && !defined(__ARM_ARCH_7EM__) && \
!defined(__ARM_ARCH_8M_BASE__) && !defined(__ARM_ARCH_8M_MAIN__)
#if defined(__ARM6M__) && (__CORE__ == __ARM6M__)
#define __ARM_ARCH_6M__ 1
#elif defined(__ARM7M__) && (__CORE__ == __ARM7M__)
#define __ARM_ARCH_7M__ 1
#elif defined(__ARM7EM__) && (__CORE__ == __ARM7EM__)
#define __ARM_ARCH_7EM__ 1
#elif defined(__ARM8M_BASELINE__) && (__CORE == __ARM8M_BASELINE__)
#define __ARM_ARCH_8M_BASE__ 1
#elif defined(__ARM8M_MAINLINE__) && (__CORE == __ARM8M_MAINLINE__)
#define __ARM_ARCH_8M_MAIN__ 1
#elif defined(__ARM8EM_MAINLINE__) && (__CORE == __ARM8EM_MAINLINE__)
#define __ARM_ARCH_8M_MAIN__ 1
#else
#error "Unknown target."
#endif
#endif
#if defined(__ARM_ARCH_6M__) && __ARM_ARCH_6M__==1
#define __IAR_M0_FAMILY 1
#elif defined(__ARM_ARCH_8M_BASE__) && __ARM_ARCH_8M_BASE__==1
#define __IAR_M0_FAMILY 1
#else
#define __IAR_M0_FAMILY 0
#endif
#ifndef __ASM
#define __ASM __asm
#endif
#ifndef __COMPILER_BARRIER
#define __COMPILER_BARRIER() __ASM volatile("":::"memory")
#endif
#ifndef __INLINE
#define __INLINE inline
#endif
#ifndef __NO_RETURN
#if __ICCARM_V8
#define __NO_RETURN __attribute__((__noreturn__))
#else
#define __NO_RETURN _Pragma("object_attribute=__noreturn")
#endif
#endif
#ifndef __PACKED
#if __ICCARM_V8
#define __PACKED __attribute__((packed, aligned(1)))
#else
/* Needs IAR language extensions */
#define __PACKED __packed
#endif
#endif
#ifndef __PACKED_STRUCT
#if __ICCARM_V8
#define __PACKED_STRUCT struct __attribute__((packed, aligned(1)))
#else
/* Needs IAR language extensions */
#define __PACKED_STRUCT __packed struct
#endif
#endif
#ifndef __PACKED_UNION
#if __ICCARM_V8
#define __PACKED_UNION union __attribute__((packed, aligned(1)))
#else
/* Needs IAR language extensions */
#define __PACKED_UNION __packed union
#endif
#endif
#ifndef __RESTRICT
#if __ICCARM_V8
#define __RESTRICT __restrict
#else
/* Needs IAR language extensions */
#define __RESTRICT restrict
#endif
#endif
#ifndef __STATIC_INLINE
#define __STATIC_INLINE static inline
#endif
#ifndef __FORCEINLINE
#define __FORCEINLINE _Pragma("inline=forced")
#endif
#ifndef __STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE __FORCEINLINE __STATIC_INLINE
#endif
#ifndef __UNALIGNED_UINT16_READ
#pragma language=save
#pragma language=extended
__IAR_FT uint16_t __iar_uint16_read(void const *ptr)
{
return *(__packed uint16_t*)(ptr);
}
#pragma language=restore
#define __UNALIGNED_UINT16_READ(PTR) __iar_uint16_read(PTR)
#endif
#ifndef __UNALIGNED_UINT16_WRITE
#pragma language=save
#pragma language=extended
__IAR_FT void __iar_uint16_write(void const *ptr, uint16_t val)
{
*(__packed uint16_t*)(ptr) = val;;
}
#pragma language=restore
#define __UNALIGNED_UINT16_WRITE(PTR,VAL) __iar_uint16_write(PTR,VAL)
#endif
#ifndef __UNALIGNED_UINT32_READ
#pragma language=save
#pragma language=extended
__IAR_FT uint32_t __iar_uint32_read(void const *ptr)
{
return *(__packed uint32_t*)(ptr);
}
#pragma language=restore
#define __UNALIGNED_UINT32_READ(PTR) __iar_uint32_read(PTR)
#endif
#ifndef __UNALIGNED_UINT32_WRITE
#pragma language=save
#pragma language=extended
__IAR_FT void __iar_uint32_write(void const *ptr, uint32_t val)
{
*(__packed uint32_t*)(ptr) = val;;
}
#pragma language=restore
#define __UNALIGNED_UINT32_WRITE(PTR,VAL) __iar_uint32_write(PTR,VAL)
#endif
#ifndef __UNALIGNED_UINT32 /* deprecated */
#pragma language=save
#pragma language=extended
__packed struct __iar_u32 { uint32_t v; };
#pragma language=restore
#define __UNALIGNED_UINT32(PTR) (((struct __iar_u32 *)(PTR))->v)
#endif
#ifndef __USED
#if __ICCARM_V8
#define __USED __attribute__((used))
#else
#define __USED _Pragma("__root")
#endif
#endif
#ifndef __WEAK
#if __ICCARM_V8
#define __WEAK __attribute__((weak))
#else
#define __WEAK _Pragma("__weak")
#endif
#endif
#ifndef __PROGRAM_START
#define __PROGRAM_START __iar_program_start
#endif
#ifndef __INITIAL_SP
#define __INITIAL_SP CSTACK$$Limit
#endif
#ifndef __STACK_LIMIT
#define __STACK_LIMIT CSTACK$$Base
#endif
#ifndef __VECTOR_TABLE
#define __VECTOR_TABLE __vector_table
#endif
#ifndef __VECTOR_TABLE_ATTRIBUTE
#define __VECTOR_TABLE_ATTRIBUTE @".intvec"
#endif
#ifndef __ICCARM_INTRINSICS_VERSION__
#define __ICCARM_INTRINSICS_VERSION__ 0
#endif
#if __ICCARM_INTRINSICS_VERSION__ == 2
#if defined(__CLZ)
#undef __CLZ
#endif
#if defined(__REVSH)
#undef __REVSH
#endif
#if defined(__RBIT)
#undef __RBIT
#endif
#if defined(__SSAT)
#undef __SSAT
#endif
#if defined(__USAT)
#undef __USAT
#endif
#include "iccarm_builtin.h"
#define __disable_fault_irq __iar_builtin_disable_fiq
#define __disable_irq __iar_builtin_disable_interrupt
#define __enable_fault_irq __iar_builtin_enable_fiq
#define __enable_irq __iar_builtin_enable_interrupt
#define __arm_rsr __iar_builtin_rsr
#define __arm_wsr __iar_builtin_wsr
#define __get_APSR() (__arm_rsr("APSR"))
#define __get_BASEPRI() (__arm_rsr("BASEPRI"))
#define __get_CONTROL() (__arm_rsr("CONTROL"))
#define __get_FAULTMASK() (__arm_rsr("FAULTMASK"))
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
#define __get_FPSCR() (__arm_rsr("FPSCR"))
#define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
#else
#define __get_FPSCR() ( 0 )
#define __set_FPSCR(VALUE) ((void)VALUE)
#endif
#define __get_IPSR() (__arm_rsr("IPSR"))
#define __get_MSP() (__arm_rsr("MSP"))
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure MSPLIM is RAZ/WI
#define __get_MSPLIM() (0U)
#else
#define __get_MSPLIM() (__arm_rsr("MSPLIM"))
#endif
#define __get_PRIMASK() (__arm_rsr("PRIMASK"))
#define __get_PSP() (__arm_rsr("PSP"))
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
#define __get_PSPLIM() (0U)
#else
#define __get_PSPLIM() (__arm_rsr("PSPLIM"))
#endif
#define __get_xPSR() (__arm_rsr("xPSR"))
#define __set_BASEPRI(VALUE) (__arm_wsr("BASEPRI", (VALUE)))
#define __set_BASEPRI_MAX(VALUE) (__arm_wsr("BASEPRI_MAX", (VALUE)))
#define __set_CONTROL(VALUE) (__arm_wsr("CONTROL", (VALUE)))
#define __set_FAULTMASK(VALUE) (__arm_wsr("FAULTMASK", (VALUE)))
#define __set_MSP(VALUE) (__arm_wsr("MSP", (VALUE)))
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure MSPLIM is RAZ/WI
#define __set_MSPLIM(VALUE) ((void)(VALUE))
#else
#define __set_MSPLIM(VALUE) (__arm_wsr("MSPLIM", (VALUE)))
#endif
#define __set_PRIMASK(VALUE) (__arm_wsr("PRIMASK", (VALUE)))
#define __set_PSP(VALUE) (__arm_wsr("PSP", (VALUE)))
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
#define __set_PSPLIM(VALUE) ((void)(VALUE))
#else
#define __set_PSPLIM(VALUE) (__arm_wsr("PSPLIM", (VALUE)))
#endif
#define __TZ_get_CONTROL_NS() (__arm_rsr("CONTROL_NS"))
#define __TZ_set_CONTROL_NS(VALUE) (__arm_wsr("CONTROL_NS", (VALUE)))
#define __TZ_get_PSP_NS() (__arm_rsr("PSP_NS"))
#define __TZ_set_PSP_NS(VALUE) (__arm_wsr("PSP_NS", (VALUE)))
#define __TZ_get_MSP_NS() (__arm_rsr("MSP_NS"))
#define __TZ_set_MSP_NS(VALUE) (__arm_wsr("MSP_NS", (VALUE)))
#define __TZ_get_SP_NS() (__arm_rsr("SP_NS"))
#define __TZ_set_SP_NS(VALUE) (__arm_wsr("SP_NS", (VALUE)))
#define __TZ_get_PRIMASK_NS() (__arm_rsr("PRIMASK_NS"))
#define __TZ_set_PRIMASK_NS(VALUE) (__arm_wsr("PRIMASK_NS", (VALUE)))
#define __TZ_get_BASEPRI_NS() (__arm_rsr("BASEPRI_NS"))
#define __TZ_set_BASEPRI_NS(VALUE) (__arm_wsr("BASEPRI_NS", (VALUE)))
#define __TZ_get_FAULTMASK_NS() (__arm_rsr("FAULTMASK_NS"))
#define __TZ_set_FAULTMASK_NS(VALUE)(__arm_wsr("FAULTMASK_NS", (VALUE)))
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
#define __TZ_get_PSPLIM_NS() (0U)
#define __TZ_set_PSPLIM_NS(VALUE) ((void)(VALUE))
#else
#define __TZ_get_PSPLIM_NS() (__arm_rsr("PSPLIM_NS"))
#define __TZ_set_PSPLIM_NS(VALUE) (__arm_wsr("PSPLIM_NS", (VALUE)))
#endif
#define __TZ_get_MSPLIM_NS() (__arm_rsr("MSPLIM_NS"))
#define __TZ_set_MSPLIM_NS(VALUE) (__arm_wsr("MSPLIM_NS", (VALUE)))
#define __NOP __iar_builtin_no_operation
#define __CLZ __iar_builtin_CLZ
#define __CLREX __iar_builtin_CLREX
#define __DMB __iar_builtin_DMB
#define __DSB __iar_builtin_DSB
#define __ISB __iar_builtin_ISB
#define __LDREXB __iar_builtin_LDREXB
#define __LDREXH __iar_builtin_LDREXH
#define __LDREXW __iar_builtin_LDREX
#define __RBIT __iar_builtin_RBIT
#define __REV __iar_builtin_REV
#define __REV16 __iar_builtin_REV16
__IAR_FT int16_t __REVSH(int16_t val)
{
return (int16_t) __iar_builtin_REVSH(val);
}
#define __ROR __iar_builtin_ROR
#define __RRX __iar_builtin_RRX
#define __SEV __iar_builtin_SEV
#if !__IAR_M0_FAMILY
#define __SSAT __iar_builtin_SSAT
#endif
#define __STREXB __iar_builtin_STREXB
#define __STREXH __iar_builtin_STREXH
#define __STREXW __iar_builtin_STREX
#if !__IAR_M0_FAMILY
#define __USAT __iar_builtin_USAT
#endif
#define __WFE __iar_builtin_WFE
#define __WFI __iar_builtin_WFI
#if __ARM_MEDIA__
#define __SADD8 __iar_builtin_SADD8
#define __QADD8 __iar_builtin_QADD8
#define __SHADD8 __iar_builtin_SHADD8
#define __UADD8 __iar_builtin_UADD8
#define __UQADD8 __iar_builtin_UQADD8
#define __UHADD8 __iar_builtin_UHADD8
#define __SSUB8 __iar_builtin_SSUB8
#define __QSUB8 __iar_builtin_QSUB8
#define __SHSUB8 __iar_builtin_SHSUB8
#define __USUB8 __iar_builtin_USUB8
#define __UQSUB8 __iar_builtin_UQSUB8
#define __UHSUB8 __iar_builtin_UHSUB8
#define __SADD16 __iar_builtin_SADD16
#define __QADD16 __iar_builtin_QADD16
#define __SHADD16 __iar_builtin_SHADD16
#define __UADD16 __iar_builtin_UADD16
#define __UQADD16 __iar_builtin_UQADD16
#define __UHADD16 __iar_builtin_UHADD16
#define __SSUB16 __iar_builtin_SSUB16
#define __QSUB16 __iar_builtin_QSUB16
#define __SHSUB16 __iar_builtin_SHSUB16
#define __USUB16 __iar_builtin_USUB16
#define __UQSUB16 __iar_builtin_UQSUB16
#define __UHSUB16 __iar_builtin_UHSUB16
#define __SASX __iar_builtin_SASX
#define __QASX __iar_builtin_QASX
#define __SHASX __iar_builtin_SHASX
#define __UASX __iar_builtin_UASX
#define __UQASX __iar_builtin_UQASX
#define __UHASX __iar_builtin_UHASX
#define __SSAX __iar_builtin_SSAX
#define __QSAX __iar_builtin_QSAX
#define __SHSAX __iar_builtin_SHSAX
#define __USAX __iar_builtin_USAX
#define __UQSAX __iar_builtin_UQSAX
#define __UHSAX __iar_builtin_UHSAX
#define __USAD8 __iar_builtin_USAD8
#define __USADA8 __iar_builtin_USADA8
#define __SSAT16 __iar_builtin_SSAT16
#define __USAT16 __iar_builtin_USAT16
#define __UXTB16 __iar_builtin_UXTB16
#define __UXTAB16 __iar_builtin_UXTAB16
#define __SXTB16 __iar_builtin_SXTB16
#define __SXTAB16 __iar_builtin_SXTAB16
#define __SMUAD __iar_builtin_SMUAD
#define __SMUADX __iar_builtin_SMUADX
#define __SMMLA __iar_builtin_SMMLA
#define __SMLAD __iar_builtin_SMLAD
#define __SMLADX __iar_builtin_SMLADX
#define __SMLALD __iar_builtin_SMLALD
#define __SMLALDX __iar_builtin_SMLALDX
#define __SMUSD __iar_builtin_SMUSD
#define __SMUSDX __iar_builtin_SMUSDX
#define __SMLSD __iar_builtin_SMLSD
#define __SMLSDX __iar_builtin_SMLSDX
#define __SMLSLD __iar_builtin_SMLSLD
#define __SMLSLDX __iar_builtin_SMLSLDX
#define __SEL __iar_builtin_SEL
#define __QADD __iar_builtin_QADD
#define __QSUB __iar_builtin_QSUB
#define __PKHBT __iar_builtin_PKHBT
#define __PKHTB __iar_builtin_PKHTB
#endif
#else /* __ICCARM_INTRINSICS_VERSION__ == 2 */
#if __IAR_M0_FAMILY
/* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
#define __CLZ __cmsis_iar_clz_not_active
#define __SSAT __cmsis_iar_ssat_not_active
#define __USAT __cmsis_iar_usat_not_active
#define __RBIT __cmsis_iar_rbit_not_active
#define __get_APSR __cmsis_iar_get_APSR_not_active
#endif
#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
#define __get_FPSCR __cmsis_iar_get_FPSR_not_active
#define __set_FPSCR __cmsis_iar_set_FPSR_not_active
#endif
#ifdef __INTRINSICS_INCLUDED
#error intrinsics.h is already included previously!
#endif
#include <intrinsics.h>
#if __IAR_M0_FAMILY
/* Avoid clash between intrinsics.h and arm_math.h when compiling for Cortex-M0. */
#undef __CLZ
#undef __SSAT
#undef __USAT
#undef __RBIT
#undef __get_APSR
__STATIC_INLINE uint8_t __CLZ(uint32_t data)
{
if (data == 0U) { return 32U; }
uint32_t count = 0U;
uint32_t mask = 0x80000000U;
while ((data & mask) == 0U)
{
count += 1U;
mask = mask >> 1U;
}
return count;
}
__STATIC_INLINE uint32_t __RBIT(uint32_t v)
{
uint8_t sc = 31U;
uint32_t r = v;
for (v >>= 1U; v; v >>= 1U)
{
r <<= 1U;
r |= v & 1U;
sc--;
}
return (r << sc);
}
__STATIC_INLINE uint32_t __get_APSR(void)
{
uint32_t res;
__asm("MRS %0,APSR" : "=r" (res));
return res;
}
#endif
#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
#undef __get_FPSCR
#undef __set_FPSCR
#define __get_FPSCR() (0)
#define __set_FPSCR(VALUE) ((void)VALUE)
#endif
#pragma diag_suppress=Pe940
#pragma diag_suppress=Pe177
#define __enable_irq __enable_interrupt
#define __disable_irq __disable_interrupt
#define __NOP __no_operation
#define __get_xPSR __get_PSR
#if (!defined(__ARM_ARCH_6M__) || __ARM_ARCH_6M__==0)
__IAR_FT uint32_t __LDREXW(uint32_t volatile *ptr)
{
return __LDREX((unsigned long *)ptr);
}
__IAR_FT uint32_t __STREXW(uint32_t value, uint32_t volatile *ptr)
{
return __STREX(value, (unsigned long *)ptr);
}
#endif
/* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
#if (__CORTEX_M >= 0x03)
__IAR_FT uint32_t __RRX(uint32_t value)
{
uint32_t result;
__ASM("RRX %0, %1" : "=r"(result) : "r" (value) : "cc");
return(result);
}
__IAR_FT void __set_BASEPRI_MAX(uint32_t value)
{
__asm volatile("MSR BASEPRI_MAX,%0"::"r" (value));
}
#define __enable_fault_irq __enable_fiq
#define __disable_fault_irq __disable_fiq
#endif /* (__CORTEX_M >= 0x03) */
__IAR_FT uint32_t __ROR(uint32_t op1, uint32_t op2)
{
return (op1 >> op2) | (op1 << ((sizeof(op1)*8)-op2));
}
#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
(defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
__IAR_FT uint32_t __get_MSPLIM(void)
{
uint32_t res;
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure MSPLIM is RAZ/WI
res = 0U;
#else
__asm volatile("MRS %0,MSPLIM" : "=r" (res));
#endif
return res;
}
__IAR_FT void __set_MSPLIM(uint32_t value)
{
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure MSPLIM is RAZ/WI
(void)value;
#else
__asm volatile("MSR MSPLIM,%0" :: "r" (value));
#endif
}
__IAR_FT uint32_t __get_PSPLIM(void)
{
uint32_t res;
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
res = 0U;
#else
__asm volatile("MRS %0,PSPLIM" : "=r" (res));
#endif
return res;
}
__IAR_FT void __set_PSPLIM(uint32_t value)
{
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
(void)value;
#else
__asm volatile("MSR PSPLIM,%0" :: "r" (value));
#endif
}
__IAR_FT uint32_t __TZ_get_CONTROL_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,CONTROL_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_CONTROL_NS(uint32_t value)
{
__asm volatile("MSR CONTROL_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_PSP_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,PSP_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_PSP_NS(uint32_t value)
{
__asm volatile("MSR PSP_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_MSP_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,MSP_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_MSP_NS(uint32_t value)
{
__asm volatile("MSR MSP_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_SP_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,SP_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_SP_NS(uint32_t value)
{
__asm volatile("MSR SP_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_PRIMASK_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,PRIMASK_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_PRIMASK_NS(uint32_t value)
{
__asm volatile("MSR PRIMASK_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_BASEPRI_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,BASEPRI_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_BASEPRI_NS(uint32_t value)
{
__asm volatile("MSR BASEPRI_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_FAULTMASK_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,FAULTMASK_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_FAULTMASK_NS(uint32_t value)
{
__asm volatile("MSR FAULTMASK_NS,%0" :: "r" (value));
}
__IAR_FT uint32_t __TZ_get_PSPLIM_NS(void)
{
uint32_t res;
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
res = 0U;
#else
__asm volatile("MRS %0,PSPLIM_NS" : "=r" (res));
#endif
return res;
}
__IAR_FT void __TZ_set_PSPLIM_NS(uint32_t value)
{
#if (!(defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) && \
(!defined (__ARM_FEATURE_CMSE ) || (__ARM_FEATURE_CMSE < 3)))
// without main extensions, the non-secure PSPLIM is RAZ/WI
(void)value;
#else
__asm volatile("MSR PSPLIM_NS,%0" :: "r" (value));
#endif
}
__IAR_FT uint32_t __TZ_get_MSPLIM_NS(void)
{
uint32_t res;
__asm volatile("MRS %0,MSPLIM_NS" : "=r" (res));
return res;
}
__IAR_FT void __TZ_set_MSPLIM_NS(uint32_t value)
{
__asm volatile("MSR MSPLIM_NS,%0" :: "r" (value));
}
#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
#endif /* __ICCARM_INTRINSICS_VERSION__ == 2 */
#define __BKPT(value) __asm volatile ("BKPT %0" : : "i"(value))
#if __IAR_M0_FAMILY
__STATIC_INLINE int32_t __SSAT(int32_t val, uint32_t sat)
{
if ((sat >= 1U) && (sat <= 32U))
{
const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U);
const int32_t min = -1 - max ;
if (val > max)
{
return max;
}
else if (val < min)
{
return min;
}
}
return val;
}
__STATIC_INLINE uint32_t __USAT(int32_t val, uint32_t sat)
{
if (sat <= 31U)
{
const uint32_t max = ((1U << sat) - 1U);
if (val > (int32_t)max)
{
return max;
}
else if (val < 0)
{
return 0U;
}
}
return (uint32_t)val;
}
#endif
#if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
__IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
{
uint32_t res;
__ASM("LDRBT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
return ((uint8_t)res);
}
__IAR_FT uint16_t __LDRHT(volatile uint16_t *addr)
{
uint32_t res;
__ASM("LDRHT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
return ((uint16_t)res);
}
__IAR_FT uint32_t __LDRT(volatile uint32_t *addr)
{
uint32_t res;
__ASM("LDRT %0, [%1]" : "=r" (res) : "r" (addr) : "memory");
return res;
}
__IAR_FT void __STRBT(uint8_t value, volatile uint8_t *addr)
{
__ASM("STRBT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
}
__IAR_FT void __STRHT(uint16_t value, volatile uint16_t *addr)
{
__ASM("STRHT %1, [%0]" : : "r" (addr), "r" ((uint32_t)value) : "memory");
}
__IAR_FT void __STRT(uint32_t value, volatile uint32_t *addr)
{
__ASM("STRT %1, [%0]" : : "r" (addr), "r" (value) : "memory");
}
#endif /* (__CORTEX_M >= 0x03) */
#if ((defined (__ARM_ARCH_8M_MAIN__ ) && (__ARM_ARCH_8M_MAIN__ == 1)) || \
(defined (__ARM_ARCH_8M_BASE__ ) && (__ARM_ARCH_8M_BASE__ == 1)) )
__IAR_FT uint8_t __LDAB(volatile uint8_t *ptr)
{
uint32_t res;
__ASM volatile ("LDAB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
return ((uint8_t)res);
}
__IAR_FT uint16_t __LDAH(volatile uint16_t *ptr)
{
uint32_t res;
__ASM volatile ("LDAH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
return ((uint16_t)res);
}
__IAR_FT uint32_t __LDA(volatile uint32_t *ptr)
{
uint32_t res;
__ASM volatile ("LDA %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
return res;
}
__IAR_FT void __STLB(uint8_t value, volatile uint8_t *ptr)
{
__ASM volatile ("STLB %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
}
__IAR_FT void __STLH(uint16_t value, volatile uint16_t *ptr)
{
__ASM volatile ("STLH %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
}
__IAR_FT void __STL(uint32_t value, volatile uint32_t *ptr)
{
__ASM volatile ("STL %1, [%0]" :: "r" (ptr), "r" (value) : "memory");
}
__IAR_FT uint8_t __LDAEXB(volatile uint8_t *ptr)
{
uint32_t res;
__ASM volatile ("LDAEXB %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
return ((uint8_t)res);
}
__IAR_FT uint16_t __LDAEXH(volatile uint16_t *ptr)
{
uint32_t res;
__ASM volatile ("LDAEXH %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
return ((uint16_t)res);
}
__IAR_FT uint32_t __LDAEX(volatile uint32_t *ptr)
{
uint32_t res;
__ASM volatile ("LDAEX %0, [%1]" : "=r" (res) : "r" (ptr) : "memory");
return res;
}
__IAR_FT uint32_t __STLEXB(uint8_t value, volatile uint8_t *ptr)
{
uint32_t res;
__ASM volatile ("STLEXB %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
return res;
}
__IAR_FT uint32_t __STLEXH(uint16_t value, volatile uint16_t *ptr)
{
uint32_t res;
__ASM volatile ("STLEXH %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
return res;
}
__IAR_FT uint32_t __STLEX(uint32_t value, volatile uint32_t *ptr)
{
uint32_t res;
__ASM volatile ("STLEX %0, %2, [%1]" : "=r" (res) : "r" (ptr), "r" (value) : "memory");
return res;
}
#endif /* __ARM_ARCH_8M_MAIN__ or __ARM_ARCH_8M_BASE__ */
#undef __IAR_FT
#undef __IAR_M0_FAMILY
#undef __ICCARM_V8
#pragma diag_default=Pe940
#pragma diag_default=Pe177
#endif /* __CMSIS_ICCARM_H__ */

View File

@ -0,0 +1,39 @@
/**************************************************************************//**
* @file cmsis_version.h
* @brief CMSIS Core(M) Version definitions
* @version V5.0.3
* @date 24. June 2019
******************************************************************************/
/*
* Copyright (c) 2009-2019 ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CMSIS_VERSION_H
#define __CMSIS_VERSION_H
/* CMSIS Version definitions */
#define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
#define __CM_CMSIS_VERSION_SUB ( 3U) /*!< [15:0] CMSIS Core(M) sub version */
#define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
__CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,952 @@
/**************************************************************************//**
* @file core_cm0.h
* @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File
* @version V5.0.6
* @date 13. March 2019
******************************************************************************/
/*
* Copyright (c) 2009-2019 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CM0_H_GENERIC
#define __CORE_CM0_H_GENERIC
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
\page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/**
\ingroup Cortex_M0
@{
*/
#include "cmsis_version.h"
/* CMSIS CM0 definitions */
#define __CM0_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
#define __CM0_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16U) | \
__CM0_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
#define __CORTEX_M (0U) /*!< Cortex-M Core */
/** __FPU_USED indicates whether an FPU is used or not.
This core does not support an FPU at all
*/
#define __FPU_USED 0U
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#if defined __ARM_FP
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TI_ARM__ )
#if defined __TI_VFP_SUPPORT__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __CSMC__ )
#if ( __CSMC__ & 0x400U)
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM0_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_CM0_H_DEPENDANT
#define __CORE_CM0_H_DEPENDANT
#ifdef __cplusplus
extern "C" {
#endif
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __CM0_REV
#define __CM0_REV 0x0000U
#warning "__CM0_REV not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2U
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0U
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/* following defines should be used for structure members */
#define __IM volatile const /*! Defines 'read only' structure member permissions */
#define __OM volatile /*! Defines 'write only' structure member permissions */
#define __IOM volatile /*! Defines 'read / write' structure member permissions */
/*@} end of group Cortex_M0 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
******************************************************************************/
/**
\defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/**
\brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/* APSR Register Definitions */
#define APSR_N_Pos 31U /*!< APSR: N Position */
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
#define APSR_Z_Pos 30U /*!< APSR: Z Position */
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
#define APSR_C_Pos 29U /*!< APSR: C Position */
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
#define APSR_V_Pos 28U /*!< APSR: V Position */
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
/**
\brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/* IPSR Register Definitions */
#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
/**
\brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/* xPSR Register Definitions */
#define xPSR_N_Pos 31U /*!< xPSR: N Position */
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
#define xPSR_C_Pos 29U /*!< xPSR: C Position */
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
#define xPSR_V_Pos 28U /*!< xPSR: V Position */
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
/**
\brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t _reserved0:1; /*!< bit: 0 Reserved */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/* CONTROL Register Definitions */
#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
/*@} end of group CMSIS_CORE */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/**
\brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31U];
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RESERVED1[31U];
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31U];
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31U];
uint32_t RESERVED4[64U];
__IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/**
\brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
uint32_t RESERVED0;
__IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED1;
__IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/*@} end of group CMSIS_SCB */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/**
\brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
Therefore they are not covered by the Cortex-M0 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_core_bitfield Core register bit field macros
\brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
@{
*/
/**
\brief Mask and shift a bit field value for use in a register bit range.
\param[in] field Name of the register bit field.
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
\return Masked and shifted value.
*/
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
/**
\brief Mask and shift a register value to extract a bit filed value.
\param[in] field Name of the register bit field.
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
\return Masked and shifted bit field value.
*/
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
/*@} end of group CMSIS_core_bitfield */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of Core Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/**
\defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/**
\ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
#ifdef CMSIS_NVIC_VIRTUAL
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
#endif
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
#else
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
#define NVIC_EnableIRQ __NVIC_EnableIRQ
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
#define NVIC_DisableIRQ __NVIC_DisableIRQ
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
/*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M0 */
#define NVIC_SetPriority __NVIC_SetPriority
#define NVIC_GetPriority __NVIC_GetPriority
#define NVIC_SystemReset __NVIC_SystemReset
#endif /* CMSIS_NVIC_VIRTUAL */
#ifdef CMSIS_VECTAB_VIRTUAL
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
#endif
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
#else
#define NVIC_SetVector __NVIC_SetVector
#define NVIC_GetVector __NVIC_GetVector
#endif /* (CMSIS_VECTAB_VIRTUAL) */
#define NVIC_USER_IRQ_OFFSET 16
/* The following EXC_RETURN values are saved the LR on exception entry */
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
/* Interrupt Priorities are WORD accessible only under Armv6-M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
#define __NVIC_SetPriorityGrouping(X) (void)(X)
#define __NVIC_GetPriorityGrouping() (0U)
/**
\brief Enable Interrupt
\details Enables a device specific interrupt in the NVIC interrupt controller.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
__COMPILER_BARRIER();
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
__COMPILER_BARRIER();
}
}
/**
\brief Get Interrupt Enable status
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
\param [in] IRQn Device specific interrupt number.
\return 0 Interrupt is not enabled.
\return 1 Interrupt is enabled.
\note IRQn must not be negative.
*/
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
}
else
{
return(0U);
}
}
/**
\brief Disable Interrupt
\details Disables a device specific interrupt in the NVIC interrupt controller.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
__DSB();
__ISB();
}
}
/**
\brief Get Pending Interrupt
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
\param [in] IRQn Device specific interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
\note IRQn must not be negative.
*/
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
}
else
{
return(0U);
}
}
/**
\brief Set Pending Interrupt
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
}
}
/**
\brief Clear Pending Interrupt
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
}
}
/**
\brief Set Interrupt Priority
\details Sets the priority of a device specific interrupt or a processor exception.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
\note The priority cannot be set for every processor exception.
*/
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
}
else
{
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
}
}
/**
\brief Get Interrupt Priority
\details Reads the priority of a device specific interrupt or a processor exception.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\return Interrupt Priority.
Value is aligned automatically to the implemented priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
}
else
{
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
}
}
/**
\brief Encode Priority
\details Encodes the priority for an interrupt with the given priority group,
preemptive priority value, and subpriority value.
In case of a conflict between priority grouping and available
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
\param [in] PriorityGroup Used priority group.
\param [in] PreemptPriority Preemptive priority value (starting from 0).
\param [in] SubPriority Subpriority value (starting from 0).
\return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
*/
__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
{
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
uint32_t PreemptPriorityBits;
uint32_t SubPriorityBits;
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
return (
((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
);
}
/**
\brief Decode Priority
\details Decodes an interrupt priority value with a given priority group to
preemptive priority value and subpriority value.
In case of a conflict between priority grouping and available
priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
\param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
\param [in] PriorityGroup Used priority group.
\param [out] pPreemptPriority Preemptive priority value (starting from 0).
\param [out] pSubPriority Subpriority value (starting from 0).
*/
__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
{
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
uint32_t PreemptPriorityBits;
uint32_t SubPriorityBits;
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
*pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
*pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
}
/**
\brief Set Interrupt Vector
\details Sets an interrupt vector in SRAM based interrupt vector table.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
Address 0 must be mapped to SRAM.
\param [in] IRQn Interrupt number
\param [in] vector Address of interrupt handler function
*/
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
{
uint32_t vectors = 0x0U;
(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4)) = vector;
/* ARM Application Note 321 states that the M0 does not require the architectural barrier */
}
/**
\brief Get Interrupt Vector
\details Reads an interrupt vector from interrupt vector table.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\return Address of interrupt handler function
*/
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
{
uint32_t vectors = 0x0U;
return (uint32_t)(* (int *) (vectors + ((int32_t)IRQn + NVIC_USER_IRQ_OFFSET) * 4));
}
/**
\brief System Reset
\details Initiates a system reset request to reset the MCU.
*/
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
for(;;) /* wait until reset */
{
__NOP();
}
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ########################## FPU functions #################################### */
/**
\ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_FpuFunctions FPU Functions
\brief Function that provides FPU type.
@{
*/
/**
\brief get FPU type
\details returns the FPU type
\returns
- \b 0: No FPU
- \b 1: Single precision FPU
- \b 2: Double + Single precision FPU
*/
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
{
return 0U; /* No FPU */
}
/*@} end of CMSIS_Core_FpuFunctions */
/* ################################## SysTick function ############################################ */
/**
\ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
/**
\brief System Tick Configuration
\details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM0_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,979 @@
/**************************************************************************//**
* @file core_cm1.h
* @brief CMSIS Cortex-M1 Core Peripheral Access Layer Header File
* @version V1.0.1
* @date 12. November 2018
******************************************************************************/
/*
* Copyright (c) 2009-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef __CORE_CM1_H_GENERIC
#define __CORE_CM1_H_GENERIC
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
\page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions
CMSIS violates the following MISRA-C:2004 rules:
\li Required Rule 8.5, object/function definition in header file.<br>
Function definitions in header files are used to allow 'inlining'.
\li Required Rule 18.4, declaration of union type or object of union type: '{...}'.<br>
Unions are used for effective representation of core registers.
\li Advisory Rule 19.7, Function-like macro defined.<br>
Function-like macros are used to allow more efficient code.
*/
/*******************************************************************************
* CMSIS definitions
******************************************************************************/
/**
\ingroup Cortex_M1
@{
*/
#include "cmsis_version.h"
/* CMSIS CM1 definitions */
#define __CM1_CMSIS_VERSION_MAIN (__CM_CMSIS_VERSION_MAIN) /*!< \deprecated [31:16] CMSIS HAL main version */
#define __CM1_CMSIS_VERSION_SUB (__CM_CMSIS_VERSION_SUB) /*!< \deprecated [15:0] CMSIS HAL sub version */
#define __CM1_CMSIS_VERSION ((__CM1_CMSIS_VERSION_MAIN << 16U) | \
__CM1_CMSIS_VERSION_SUB ) /*!< \deprecated CMSIS HAL version number */
#define __CORTEX_M (1U) /*!< Cortex-M Core */
/** __FPU_USED indicates whether an FPU is used or not.
This core does not support an FPU at all
*/
#define __FPU_USED 0U
#if defined ( __CC_ARM )
#if defined __TARGET_FPU_VFP
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
#if defined __ARM_FP
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __GNUC__ )
#if defined (__VFP_FP__) && !defined(__SOFTFP__)
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __ICCARM__ )
#if defined __ARMVFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TI_ARM__ )
#if defined __TI_VFP_SUPPORT__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __TASKING__ )
#if defined __FPU_VFP__
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#elif defined ( __CSMC__ )
#if ( __CSMC__ & 0x400U)
#error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
#endif
#endif
#include "cmsis_compiler.h" /* CMSIS compiler specific defines */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM1_H_GENERIC */
#ifndef __CMSIS_GENERIC
#ifndef __CORE_CM1_H_DEPENDANT
#define __CORE_CM1_H_DEPENDANT
#ifdef __cplusplus
extern "C" {
#endif
/* check device defines and use defaults */
#if defined __CHECK_DEVICE_DEFINES
#ifndef __CM1_REV
#define __CM1_REV 0x0100U
#warning "__CM1_REV not defined in device header file; using default!"
#endif
#ifndef __NVIC_PRIO_BITS
#define __NVIC_PRIO_BITS 2U
#warning "__NVIC_PRIO_BITS not defined in device header file; using default!"
#endif
#ifndef __Vendor_SysTickConfig
#define __Vendor_SysTickConfig 0U
#warning "__Vendor_SysTickConfig not defined in device header file; using default!"
#endif
#endif
/* IO definitions (access restrictions to peripheral registers) */
/**
\defgroup CMSIS_glob_defs CMSIS Global Defines
<strong>IO Type Qualifiers</strong> are used
\li to specify the access to peripheral variables.
\li for automatic generation of peripheral register debug information.
*/
#ifdef __cplusplus
#define __I volatile /*!< Defines 'read only' permissions */
#else
#define __I volatile const /*!< Defines 'read only' permissions */
#endif
#define __O volatile /*!< Defines 'write only' permissions */
#define __IO volatile /*!< Defines 'read / write' permissions */
/* following defines should be used for structure members */
#define __IM volatile const /*! Defines 'read only' structure member permissions */
#define __OM volatile /*! Defines 'write only' structure member permissions */
#define __IOM volatile /*! Defines 'read / write' structure member permissions */
/*@} end of group Cortex_M1 */
/*******************************************************************************
* Register Abstraction
Core Register contain:
- Core Register
- Core NVIC Register
- Core SCB Register
- Core SysTick Register
******************************************************************************/
/**
\defgroup CMSIS_core_register Defines and Type Definitions
\brief Type definitions and defines for Cortex-M processor based devices.
*/
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_CORE Status and Control Registers
\brief Core Register type definitions.
@{
*/
/**
\brief Union type to access the Application Program Status Register (APSR).
*/
typedef union
{
struct
{
uint32_t _reserved0:28; /*!< bit: 0..27 Reserved */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} APSR_Type;
/* APSR Register Definitions */
#define APSR_N_Pos 31U /*!< APSR: N Position */
#define APSR_N_Msk (1UL << APSR_N_Pos) /*!< APSR: N Mask */
#define APSR_Z_Pos 30U /*!< APSR: Z Position */
#define APSR_Z_Msk (1UL << APSR_Z_Pos) /*!< APSR: Z Mask */
#define APSR_C_Pos 29U /*!< APSR: C Position */
#define APSR_C_Msk (1UL << APSR_C_Pos) /*!< APSR: C Mask */
#define APSR_V_Pos 28U /*!< APSR: V Position */
#define APSR_V_Msk (1UL << APSR_V_Pos) /*!< APSR: V Mask */
/**
\brief Union type to access the Interrupt Program Status Register (IPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} IPSR_Type;
/* IPSR Register Definitions */
#define IPSR_ISR_Pos 0U /*!< IPSR: ISR Position */
#define IPSR_ISR_Msk (0x1FFUL /*<< IPSR_ISR_Pos*/) /*!< IPSR: ISR Mask */
/**
\brief Union type to access the Special-Purpose Program Status Registers (xPSR).
*/
typedef union
{
struct
{
uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */
uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */
uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */
uint32_t _reserved1:3; /*!< bit: 25..27 Reserved */
uint32_t V:1; /*!< bit: 28 Overflow condition code flag */
uint32_t C:1; /*!< bit: 29 Carry condition code flag */
uint32_t Z:1; /*!< bit: 30 Zero condition code flag */
uint32_t N:1; /*!< bit: 31 Negative condition code flag */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} xPSR_Type;
/* xPSR Register Definitions */
#define xPSR_N_Pos 31U /*!< xPSR: N Position */
#define xPSR_N_Msk (1UL << xPSR_N_Pos) /*!< xPSR: N Mask */
#define xPSR_Z_Pos 30U /*!< xPSR: Z Position */
#define xPSR_Z_Msk (1UL << xPSR_Z_Pos) /*!< xPSR: Z Mask */
#define xPSR_C_Pos 29U /*!< xPSR: C Position */
#define xPSR_C_Msk (1UL << xPSR_C_Pos) /*!< xPSR: C Mask */
#define xPSR_V_Pos 28U /*!< xPSR: V Position */
#define xPSR_V_Msk (1UL << xPSR_V_Pos) /*!< xPSR: V Mask */
#define xPSR_T_Pos 24U /*!< xPSR: T Position */
#define xPSR_T_Msk (1UL << xPSR_T_Pos) /*!< xPSR: T Mask */
#define xPSR_ISR_Pos 0U /*!< xPSR: ISR Position */
#define xPSR_ISR_Msk (0x1FFUL /*<< xPSR_ISR_Pos*/) /*!< xPSR: ISR Mask */
/**
\brief Union type to access the Control Registers (CONTROL).
*/
typedef union
{
struct
{
uint32_t _reserved0:1; /*!< bit: 0 Reserved */
uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */
uint32_t _reserved1:30; /*!< bit: 2..31 Reserved */
} b; /*!< Structure used for bit access */
uint32_t w; /*!< Type used for word access */
} CONTROL_Type;
/* CONTROL Register Definitions */
#define CONTROL_SPSEL_Pos 1U /*!< CONTROL: SPSEL Position */
#define CONTROL_SPSEL_Msk (1UL << CONTROL_SPSEL_Pos) /*!< CONTROL: SPSEL Mask */
/*@} end of group CMSIS_CORE */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC)
\brief Type definitions for the NVIC Registers
@{
*/
/**
\brief Structure type to access the Nested Vectored Interrupt Controller (NVIC).
*/
typedef struct
{
__IOM uint32_t ISER[1U]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */
uint32_t RESERVED0[31U];
__IOM uint32_t ICER[1U]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */
uint32_t RSERVED1[31U];
__IOM uint32_t ISPR[1U]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */
uint32_t RESERVED2[31U];
__IOM uint32_t ICPR[1U]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */
uint32_t RESERVED3[31U];
uint32_t RESERVED4[64U];
__IOM uint32_t IP[8U]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */
} NVIC_Type;
/*@} end of group CMSIS_NVIC */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_SCB System Control Block (SCB)
\brief Type definitions for the System Control Block Registers
@{
*/
/**
\brief Structure type to access the System Control Block (SCB).
*/
typedef struct
{
__IM uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */
__IOM uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */
uint32_t RESERVED0;
__IOM uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */
__IOM uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */
__IOM uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */
uint32_t RESERVED1;
__IOM uint32_t SHP[2U]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */
__IOM uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */
} SCB_Type;
/* SCB CPUID Register Definitions */
#define SCB_CPUID_IMPLEMENTER_Pos 24U /*!< SCB CPUID: IMPLEMENTER Position */
#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */
#define SCB_CPUID_VARIANT_Pos 20U /*!< SCB CPUID: VARIANT Position */
#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */
#define SCB_CPUID_ARCHITECTURE_Pos 16U /*!< SCB CPUID: ARCHITECTURE Position */
#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */
#define SCB_CPUID_PARTNO_Pos 4U /*!< SCB CPUID: PARTNO Position */
#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */
#define SCB_CPUID_REVISION_Pos 0U /*!< SCB CPUID: REVISION Position */
#define SCB_CPUID_REVISION_Msk (0xFUL /*<< SCB_CPUID_REVISION_Pos*/) /*!< SCB CPUID: REVISION Mask */
/* SCB Interrupt Control State Register Definitions */
#define SCB_ICSR_NMIPENDSET_Pos 31U /*!< SCB ICSR: NMIPENDSET Position */
#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */
#define SCB_ICSR_PENDSVSET_Pos 28U /*!< SCB ICSR: PENDSVSET Position */
#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */
#define SCB_ICSR_PENDSVCLR_Pos 27U /*!< SCB ICSR: PENDSVCLR Position */
#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */
#define SCB_ICSR_PENDSTSET_Pos 26U /*!< SCB ICSR: PENDSTSET Position */
#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */
#define SCB_ICSR_PENDSTCLR_Pos 25U /*!< SCB ICSR: PENDSTCLR Position */
#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */
#define SCB_ICSR_ISRPREEMPT_Pos 23U /*!< SCB ICSR: ISRPREEMPT Position */
#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */
#define SCB_ICSR_ISRPENDING_Pos 22U /*!< SCB ICSR: ISRPENDING Position */
#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */
#define SCB_ICSR_VECTPENDING_Pos 12U /*!< SCB ICSR: VECTPENDING Position */
#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */
#define SCB_ICSR_VECTACTIVE_Pos 0U /*!< SCB ICSR: VECTACTIVE Position */
#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL /*<< SCB_ICSR_VECTACTIVE_Pos*/) /*!< SCB ICSR: VECTACTIVE Mask */
/* SCB Application Interrupt and Reset Control Register Definitions */
#define SCB_AIRCR_VECTKEY_Pos 16U /*!< SCB AIRCR: VECTKEY Position */
#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */
#define SCB_AIRCR_VECTKEYSTAT_Pos 16U /*!< SCB AIRCR: VECTKEYSTAT Position */
#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */
#define SCB_AIRCR_ENDIANESS_Pos 15U /*!< SCB AIRCR: ENDIANESS Position */
#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */
#define SCB_AIRCR_SYSRESETREQ_Pos 2U /*!< SCB AIRCR: SYSRESETREQ Position */
#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */
#define SCB_AIRCR_VECTCLRACTIVE_Pos 1U /*!< SCB AIRCR: VECTCLRACTIVE Position */
#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */
/* SCB System Control Register Definitions */
#define SCB_SCR_SEVONPEND_Pos 4U /*!< SCB SCR: SEVONPEND Position */
#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */
#define SCB_SCR_SLEEPDEEP_Pos 2U /*!< SCB SCR: SLEEPDEEP Position */
#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */
#define SCB_SCR_SLEEPONEXIT_Pos 1U /*!< SCB SCR: SLEEPONEXIT Position */
#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */
/* SCB Configuration Control Register Definitions */
#define SCB_CCR_STKALIGN_Pos 9U /*!< SCB CCR: STKALIGN Position */
#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */
#define SCB_CCR_UNALIGN_TRP_Pos 3U /*!< SCB CCR: UNALIGN_TRP Position */
#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */
/* SCB System Handler Control and State Register Definitions */
#define SCB_SHCSR_SVCALLPENDED_Pos 15U /*!< SCB SHCSR: SVCALLPENDED Position */
#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */
/*@} end of group CMSIS_SCB */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_SCnSCB System Controls not in SCB (SCnSCB)
\brief Type definitions for the System Control and ID Register not in the SCB
@{
*/
/**
\brief Structure type to access the System Control and ID Register not in the SCB.
*/
typedef struct
{
uint32_t RESERVED0[2U];
__IOM uint32_t ACTLR; /*!< Offset: 0x008 (R/W) Auxiliary Control Register */
} SCnSCB_Type;
/* Auxiliary Control Register Definitions */
#define SCnSCB_ACTLR_ITCMUAEN_Pos 4U /*!< ACTLR: Instruction TCM Upper Alias Enable Position */
#define SCnSCB_ACTLR_ITCMUAEN_Msk (1UL << SCnSCB_ACTLR_ITCMUAEN_Pos) /*!< ACTLR: Instruction TCM Upper Alias Enable Mask */
#define SCnSCB_ACTLR_ITCMLAEN_Pos 3U /*!< ACTLR: Instruction TCM Lower Alias Enable Position */
#define SCnSCB_ACTLR_ITCMLAEN_Msk (1UL << SCnSCB_ACTLR_ITCMLAEN_Pos) /*!< ACTLR: Instruction TCM Lower Alias Enable Mask */
/*@} end of group CMSIS_SCnotSCB */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_SysTick System Tick Timer (SysTick)
\brief Type definitions for the System Timer Registers.
@{
*/
/**
\brief Structure type to access the System Timer (SysTick).
*/
typedef struct
{
__IOM uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */
__IOM uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */
__IOM uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */
__IM uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */
} SysTick_Type;
/* SysTick Control / Status Register Definitions */
#define SysTick_CTRL_COUNTFLAG_Pos 16U /*!< SysTick CTRL: COUNTFLAG Position */
#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */
#define SysTick_CTRL_CLKSOURCE_Pos 2U /*!< SysTick CTRL: CLKSOURCE Position */
#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */
#define SysTick_CTRL_TICKINT_Pos 1U /*!< SysTick CTRL: TICKINT Position */
#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */
#define SysTick_CTRL_ENABLE_Pos 0U /*!< SysTick CTRL: ENABLE Position */
#define SysTick_CTRL_ENABLE_Msk (1UL /*<< SysTick_CTRL_ENABLE_Pos*/) /*!< SysTick CTRL: ENABLE Mask */
/* SysTick Reload Register Definitions */
#define SysTick_LOAD_RELOAD_Pos 0U /*!< SysTick LOAD: RELOAD Position */
#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL /*<< SysTick_LOAD_RELOAD_Pos*/) /*!< SysTick LOAD: RELOAD Mask */
/* SysTick Current Register Definitions */
#define SysTick_VAL_CURRENT_Pos 0U /*!< SysTick VAL: CURRENT Position */
#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL /*<< SysTick_VAL_CURRENT_Pos*/) /*!< SysTick VAL: CURRENT Mask */
/* SysTick Calibration Register Definitions */
#define SysTick_CALIB_NOREF_Pos 31U /*!< SysTick CALIB: NOREF Position */
#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */
#define SysTick_CALIB_SKEW_Pos 30U /*!< SysTick CALIB: SKEW Position */
#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */
#define SysTick_CALIB_TENMS_Pos 0U /*!< SysTick CALIB: TENMS Position */
#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL /*<< SysTick_CALIB_TENMS_Pos*/) /*!< SysTick CALIB: TENMS Mask */
/*@} end of group CMSIS_SysTick */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug)
\brief Cortex-M1 Core Debug Registers (DCB registers, SHCSR, and DFSR) are only accessible over DAP and not via processor.
Therefore they are not covered by the Cortex-M1 header file.
@{
*/
/*@} end of group CMSIS_CoreDebug */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_core_bitfield Core register bit field macros
\brief Macros for use with bit field definitions (xxx_Pos, xxx_Msk).
@{
*/
/**
\brief Mask and shift a bit field value for use in a register bit range.
\param[in] field Name of the register bit field.
\param[in] value Value of the bit field. This parameter is interpreted as an uint32_t type.
\return Masked and shifted value.
*/
#define _VAL2FLD(field, value) (((uint32_t)(value) << field ## _Pos) & field ## _Msk)
/**
\brief Mask and shift a register value to extract a bit filed value.
\param[in] field Name of the register bit field.
\param[in] value Value of register. This parameter is interpreted as an uint32_t type.
\return Masked and shifted bit field value.
*/
#define _FLD2VAL(field, value) (((uint32_t)(value) & field ## _Msk) >> field ## _Pos)
/*@} end of group CMSIS_core_bitfield */
/**
\ingroup CMSIS_core_register
\defgroup CMSIS_core_base Core Definitions
\brief Definitions for base addresses, unions, and structures.
@{
*/
/* Memory mapping of Core Hardware */
#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */
#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */
#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */
#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */
#define SCnSCB ((SCnSCB_Type *) SCS_BASE ) /*!< System control Register not in SCB */
#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */
#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */
#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */
/*@} */
/*******************************************************************************
* Hardware Abstraction Layer
Core Function Interface contains:
- Core NVIC Functions
- Core SysTick Functions
- Core Register Access Functions
******************************************************************************/
/**
\defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference
*/
/* ########################## NVIC functions #################################### */
/**
\ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_NVICFunctions NVIC Functions
\brief Functions that manage interrupts and exceptions via the NVIC.
@{
*/
#ifdef CMSIS_NVIC_VIRTUAL
#ifndef CMSIS_NVIC_VIRTUAL_HEADER_FILE
#define CMSIS_NVIC_VIRTUAL_HEADER_FILE "cmsis_nvic_virtual.h"
#endif
#include CMSIS_NVIC_VIRTUAL_HEADER_FILE
#else
#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
#define NVIC_EnableIRQ __NVIC_EnableIRQ
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
#define NVIC_DisableIRQ __NVIC_DisableIRQ
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
#define NVIC_ClearPendingIRQ __NVIC_ClearPendingIRQ
/*#define NVIC_GetActive __NVIC_GetActive not available for Cortex-M1 */
#define NVIC_SetPriority __NVIC_SetPriority
#define NVIC_GetPriority __NVIC_GetPriority
#define NVIC_SystemReset __NVIC_SystemReset
#endif /* CMSIS_NVIC_VIRTUAL */
#ifdef CMSIS_VECTAB_VIRTUAL
#ifndef CMSIS_VECTAB_VIRTUAL_HEADER_FILE
#define CMSIS_VECTAB_VIRTUAL_HEADER_FILE "cmsis_vectab_virtual.h"
#endif
#include CMSIS_VECTAB_VIRTUAL_HEADER_FILE
#else
#define NVIC_SetVector __NVIC_SetVector
#define NVIC_GetVector __NVIC_GetVector
#endif /* (CMSIS_VECTAB_VIRTUAL) */
#define NVIC_USER_IRQ_OFFSET 16
/* The following EXC_RETURN values are saved the LR on exception entry */
#define EXC_RETURN_HANDLER (0xFFFFFFF1UL) /* return to Handler mode, uses MSP after return */
#define EXC_RETURN_THREAD_MSP (0xFFFFFFF9UL) /* return to Thread mode, uses MSP after return */
#define EXC_RETURN_THREAD_PSP (0xFFFFFFFDUL) /* return to Thread mode, uses PSP after return */
/* Interrupt Priorities are WORD accessible only under Armv6-M */
/* The following MACROS handle generation of the register offset and byte masks */
#define _BIT_SHIFT(IRQn) ( ((((uint32_t)(int32_t)(IRQn)) ) & 0x03UL) * 8UL)
#define _SHP_IDX(IRQn) ( (((((uint32_t)(int32_t)(IRQn)) & 0x0FUL)-8UL) >> 2UL) )
#define _IP_IDX(IRQn) ( (((uint32_t)(int32_t)(IRQn)) >> 2UL) )
#define __NVIC_SetPriorityGrouping(X) (void)(X)
#define __NVIC_GetPriorityGrouping() (0U)
/**
\brief Enable Interrupt
\details Enables a device specific interrupt in the NVIC interrupt controller.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
__COMPILER_BARRIER();
NVIC->ISER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
__COMPILER_BARRIER();
}
}
/**
\brief Get Interrupt Enable status
\details Returns a device specific interrupt enable status from the NVIC interrupt controller.
\param [in] IRQn Device specific interrupt number.
\return 0 Interrupt is not enabled.
\return 1 Interrupt is enabled.
\note IRQn must not be negative.
*/
__STATIC_INLINE uint32_t __NVIC_GetEnableIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return((uint32_t)(((NVIC->ISER[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
}
else
{
return(0U);
}
}
/**
\brief Disable Interrupt
\details Disables a device specific interrupt in the NVIC interrupt controller.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_DisableIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->ICER[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
__DSB();
__ISB();
}
}
/**
\brief Get Pending Interrupt
\details Reads the NVIC pending register and returns the pending bit for the specified device specific interrupt.
\param [in] IRQn Device specific interrupt number.
\return 0 Interrupt status is not pending.
\return 1 Interrupt status is pending.
\note IRQn must not be negative.
*/
__STATIC_INLINE uint32_t __NVIC_GetPendingIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return((uint32_t)(((NVIC->ISPR[0U] & (1UL << (((uint32_t)IRQn) & 0x1FUL))) != 0UL) ? 1UL : 0UL));
}
else
{
return(0U);
}
}
/**
\brief Set Pending Interrupt
\details Sets the pending bit of a device specific interrupt in the NVIC pending register.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_SetPendingIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->ISPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
}
}
/**
\brief Clear Pending Interrupt
\details Clears the pending bit of a device specific interrupt in the NVIC pending register.
\param [in] IRQn Device specific interrupt number.
\note IRQn must not be negative.
*/
__STATIC_INLINE void __NVIC_ClearPendingIRQ(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->ICPR[0U] = (uint32_t)(1UL << (((uint32_t)IRQn) & 0x1FUL));
}
}
/**
\brief Set Interrupt Priority
\details Sets the priority of a device specific interrupt or a processor exception.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\param [in] priority Priority to set.
\note The priority cannot be set for every processor exception.
*/
__STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
{
if ((int32_t)(IRQn) >= 0)
{
NVIC->IP[_IP_IDX(IRQn)] = ((uint32_t)(NVIC->IP[_IP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
}
else
{
SCB->SHP[_SHP_IDX(IRQn)] = ((uint32_t)(SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFFUL << _BIT_SHIFT(IRQn))) |
(((priority << (8U - __NVIC_PRIO_BITS)) & (uint32_t)0xFFUL) << _BIT_SHIFT(IRQn)));
}
}
/**
\brief Get Interrupt Priority
\details Reads the priority of a device specific interrupt or a processor exception.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\return Interrupt Priority.
Value is aligned automatically to the implemented priority bits of the microcontroller.
*/
__STATIC_INLINE uint32_t __NVIC_GetPriority(IRQn_Type IRQn)
{
if ((int32_t)(IRQn) >= 0)
{
return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
}
else
{
return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & (uint32_t)0xFFUL) >> (8U - __NVIC_PRIO_BITS)));
}
}
/**
\brief Encode Priority
\details Encodes the priority for an interrupt with the given priority group,
preemptive priority value, and subpriority value.
In case of a conflict between priority grouping and available
priority bits (__NVIC_PRIO_BITS), the smallest possible priority group is set.
\param [in] PriorityGroup Used priority group.
\param [in] PreemptPriority Preemptive priority value (starting from 0).
\param [in] SubPriority Subpriority value (starting from 0).
\return Encoded priority. Value can be used in the function \ref NVIC_SetPriority().
*/
__STATIC_INLINE uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
{
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
uint32_t PreemptPriorityBits;
uint32_t SubPriorityBits;
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
return (
((PreemptPriority & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL)) << SubPriorityBits) |
((SubPriority & (uint32_t)((1UL << (SubPriorityBits )) - 1UL)))
);
}
/**
\brief Decode Priority
\details Decodes an interrupt priority value with a given priority group to
preemptive priority value and subpriority value.
In case of a conflict between priority grouping and available
priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set.
\param [in] Priority Priority value, which can be retrieved with the function \ref NVIC_GetPriority().
\param [in] PriorityGroup Used priority group.
\param [out] pPreemptPriority Preemptive priority value (starting from 0).
\param [out] pSubPriority Subpriority value (starting from 0).
*/
__STATIC_INLINE void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* const pPreemptPriority, uint32_t* const pSubPriority)
{
uint32_t PriorityGroupTmp = (PriorityGroup & (uint32_t)0x07UL); /* only values 0..7 are used */
uint32_t PreemptPriorityBits;
uint32_t SubPriorityBits;
PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);
SubPriorityBits = ((PriorityGroupTmp + (uint32_t)(__NVIC_PRIO_BITS)) < (uint32_t)7UL) ? (uint32_t)0UL : (uint32_t)((PriorityGroupTmp - 7UL) + (uint32_t)(__NVIC_PRIO_BITS));
*pPreemptPriority = (Priority >> SubPriorityBits) & (uint32_t)((1UL << (PreemptPriorityBits)) - 1UL);
*pSubPriority = (Priority ) & (uint32_t)((1UL << (SubPriorityBits )) - 1UL);
}
/**
\brief Set Interrupt Vector
\details Sets an interrupt vector in SRAM based interrupt vector table.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
Address 0 must be mapped to SRAM.
\param [in] IRQn Interrupt number
\param [in] vector Address of interrupt handler function
*/
__STATIC_INLINE void __NVIC_SetVector(IRQn_Type IRQn, uint32_t vector)
{
uint32_t *vectors = (uint32_t *)0x0U;
vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET] = vector;
/* ARM Application Note 321 states that the M1 does not require the architectural barrier */
}
/**
\brief Get Interrupt Vector
\details Reads an interrupt vector from interrupt vector table.
The interrupt number can be positive to specify a device specific interrupt,
or negative to specify a processor exception.
\param [in] IRQn Interrupt number.
\return Address of interrupt handler function
*/
__STATIC_INLINE uint32_t __NVIC_GetVector(IRQn_Type IRQn)
{
uint32_t *vectors = (uint32_t *)0x0U;
return vectors[(int32_t)IRQn + NVIC_USER_IRQ_OFFSET];
}
/**
\brief System Reset
\details Initiates a system reset request to reset the MCU.
*/
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
{
__DSB(); /* Ensure all outstanding memory accesses included
buffered write are completed before reset */
SCB->AIRCR = ((0x5FAUL << SCB_AIRCR_VECTKEY_Pos) |
SCB_AIRCR_SYSRESETREQ_Msk);
__DSB(); /* Ensure completion of memory access */
for(;;) /* wait until reset */
{
__NOP();
}
}
/*@} end of CMSIS_Core_NVICFunctions */
/* ########################## FPU functions #################################### */
/**
\ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_FpuFunctions FPU Functions
\brief Function that provides FPU type.
@{
*/
/**
\brief get FPU type
\details returns the FPU type
\returns
- \b 0: No FPU
- \b 1: Single precision FPU
- \b 2: Double + Single precision FPU
*/
__STATIC_INLINE uint32_t SCB_GetFPUType(void)
{
return 0U; /* No FPU */
}
/*@} end of CMSIS_Core_FpuFunctions */
/* ################################## SysTick function ############################################ */
/**
\ingroup CMSIS_Core_FunctionInterface
\defgroup CMSIS_Core_SysTickFunctions SysTick Functions
\brief Functions that configure the System.
@{
*/
#if defined (__Vendor_SysTickConfig) && (__Vendor_SysTickConfig == 0U)
/**
\brief System Tick Configuration
\details Initializes the System Timer and its interrupt, and starts the System Tick Timer.
Counter is in free running mode to generate periodic interrupts.
\param [in] ticks Number of ticks between two interrupts.
\return 0 Function succeeded.
\return 1 Function failed.
\note When the variable <b>__Vendor_SysTickConfig</b> is set to 1, then the
function <b>SysTick_Config</b> is not included. In this case, the file <b><i>device</i>.h</b>
must contain a vendor-specific implementation of this function.
*/
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1UL) > SysTick_LOAD_RELOAD_Msk)
{
return (1UL); /* Reload value impossible */
}
SysTick->LOAD = (uint32_t)(ticks - 1UL); /* set reload register */
NVIC_SetPriority (SysTick_IRQn, (1UL << __NVIC_PRIO_BITS) - 1UL); /* set Priority for Systick Interrupt */
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
SysTick_CTRL_TICKINT_Msk |
SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */
return (0UL); /* Function successful */
}
#endif
/*@} end of CMSIS_Core_SysTickFunctions */
#ifdef __cplusplus
}
#endif
#endif /* __CORE_CM1_H_DEPENDANT */
#endif /* __CMSIS_GENERIC */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,272 @@
/******************************************************************************
* @file mpu_armv7.h
* @brief CMSIS MPU API for Armv7-M MPU
* @version V5.1.0
* @date 08. March 2019
******************************************************************************/
/*
* Copyright (c) 2017-2019 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef ARM_MPU_ARMV7_H
#define ARM_MPU_ARMV7_H
#define ARM_MPU_REGION_SIZE_32B ((uint8_t)0x04U) ///!< MPU Region Size 32 Bytes
#define ARM_MPU_REGION_SIZE_64B ((uint8_t)0x05U) ///!< MPU Region Size 64 Bytes
#define ARM_MPU_REGION_SIZE_128B ((uint8_t)0x06U) ///!< MPU Region Size 128 Bytes
#define ARM_MPU_REGION_SIZE_256B ((uint8_t)0x07U) ///!< MPU Region Size 256 Bytes
#define ARM_MPU_REGION_SIZE_512B ((uint8_t)0x08U) ///!< MPU Region Size 512 Bytes
#define ARM_MPU_REGION_SIZE_1KB ((uint8_t)0x09U) ///!< MPU Region Size 1 KByte
#define ARM_MPU_REGION_SIZE_2KB ((uint8_t)0x0AU) ///!< MPU Region Size 2 KBytes
#define ARM_MPU_REGION_SIZE_4KB ((uint8_t)0x0BU) ///!< MPU Region Size 4 KBytes
#define ARM_MPU_REGION_SIZE_8KB ((uint8_t)0x0CU) ///!< MPU Region Size 8 KBytes
#define ARM_MPU_REGION_SIZE_16KB ((uint8_t)0x0DU) ///!< MPU Region Size 16 KBytes
#define ARM_MPU_REGION_SIZE_32KB ((uint8_t)0x0EU) ///!< MPU Region Size 32 KBytes
#define ARM_MPU_REGION_SIZE_64KB ((uint8_t)0x0FU) ///!< MPU Region Size 64 KBytes
#define ARM_MPU_REGION_SIZE_128KB ((uint8_t)0x10U) ///!< MPU Region Size 128 KBytes
#define ARM_MPU_REGION_SIZE_256KB ((uint8_t)0x11U) ///!< MPU Region Size 256 KBytes
#define ARM_MPU_REGION_SIZE_512KB ((uint8_t)0x12U) ///!< MPU Region Size 512 KBytes
#define ARM_MPU_REGION_SIZE_1MB ((uint8_t)0x13U) ///!< MPU Region Size 1 MByte
#define ARM_MPU_REGION_SIZE_2MB ((uint8_t)0x14U) ///!< MPU Region Size 2 MBytes
#define ARM_MPU_REGION_SIZE_4MB ((uint8_t)0x15U) ///!< MPU Region Size 4 MBytes
#define ARM_MPU_REGION_SIZE_8MB ((uint8_t)0x16U) ///!< MPU Region Size 8 MBytes
#define ARM_MPU_REGION_SIZE_16MB ((uint8_t)0x17U) ///!< MPU Region Size 16 MBytes
#define ARM_MPU_REGION_SIZE_32MB ((uint8_t)0x18U) ///!< MPU Region Size 32 MBytes
#define ARM_MPU_REGION_SIZE_64MB ((uint8_t)0x19U) ///!< MPU Region Size 64 MBytes
#define ARM_MPU_REGION_SIZE_128MB ((uint8_t)0x1AU) ///!< MPU Region Size 128 MBytes
#define ARM_MPU_REGION_SIZE_256MB ((uint8_t)0x1BU) ///!< MPU Region Size 256 MBytes
#define ARM_MPU_REGION_SIZE_512MB ((uint8_t)0x1CU) ///!< MPU Region Size 512 MBytes
#define ARM_MPU_REGION_SIZE_1GB ((uint8_t)0x1DU) ///!< MPU Region Size 1 GByte
#define ARM_MPU_REGION_SIZE_2GB ((uint8_t)0x1EU) ///!< MPU Region Size 2 GBytes
#define ARM_MPU_REGION_SIZE_4GB ((uint8_t)0x1FU) ///!< MPU Region Size 4 GBytes
#define ARM_MPU_AP_NONE 0U ///!< MPU Access Permission no access
#define ARM_MPU_AP_PRIV 1U ///!< MPU Access Permission privileged access only
#define ARM_MPU_AP_URO 2U ///!< MPU Access Permission unprivileged access read-only
#define ARM_MPU_AP_FULL 3U ///!< MPU Access Permission full access
#define ARM_MPU_AP_PRO 5U ///!< MPU Access Permission privileged access read-only
#define ARM_MPU_AP_RO 6U ///!< MPU Access Permission read-only access
/** MPU Region Base Address Register Value
*
* \param Region The region to be configured, number 0 to 15.
* \param BaseAddress The base address for the region.
*/
#define ARM_MPU_RBAR(Region, BaseAddress) \
(((BaseAddress) & MPU_RBAR_ADDR_Msk) | \
((Region) & MPU_RBAR_REGION_Msk) | \
(MPU_RBAR_VALID_Msk))
/**
* MPU Memory Access Attributes
*
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
* \param IsShareable Region is shareable between multiple bus masters.
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
*/
#define ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable) \
((((TypeExtField) << MPU_RASR_TEX_Pos) & MPU_RASR_TEX_Msk) | \
(((IsShareable) << MPU_RASR_S_Pos) & MPU_RASR_S_Msk) | \
(((IsCacheable) << MPU_RASR_C_Pos) & MPU_RASR_C_Msk) | \
(((IsBufferable) << MPU_RASR_B_Pos) & MPU_RASR_B_Msk))
/**
* MPU Region Attribute and Size Register Value
*
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
* \param AccessAttributes Memory access attribution, see \ref ARM_MPU_ACCESS_.
* \param SubRegionDisable Sub-region disable field.
* \param Size Region size of the region to be configured, for example 4K, 8K.
*/
#define ARM_MPU_RASR_EX(DisableExec, AccessPermission, AccessAttributes, SubRegionDisable, Size) \
((((DisableExec) << MPU_RASR_XN_Pos) & MPU_RASR_XN_Msk) | \
(((AccessPermission) << MPU_RASR_AP_Pos) & MPU_RASR_AP_Msk) | \
(((AccessAttributes) & (MPU_RASR_TEX_Msk | MPU_RASR_S_Msk | MPU_RASR_C_Msk | MPU_RASR_B_Msk))) | \
(((SubRegionDisable) << MPU_RASR_SRD_Pos) & MPU_RASR_SRD_Msk) | \
(((Size) << MPU_RASR_SIZE_Pos) & MPU_RASR_SIZE_Msk) | \
(((MPU_RASR_ENABLE_Msk))))
/**
* MPU Region Attribute and Size Register Value
*
* \param DisableExec Instruction access disable bit, 1= disable instruction fetches.
* \param AccessPermission Data access permissions, allows you to configure read/write access for User and Privileged mode.
* \param TypeExtField Type extension field, allows you to configure memory access type, for example strongly ordered, peripheral.
* \param IsShareable Region is shareable between multiple bus masters.
* \param IsCacheable Region is cacheable, i.e. its value may be kept in cache.
* \param IsBufferable Region is bufferable, i.e. using write-back caching. Cacheable but non-bufferable regions use write-through policy.
* \param SubRegionDisable Sub-region disable field.
* \param Size Region size of the region to be configured, for example 4K, 8K.
*/
#define ARM_MPU_RASR(DisableExec, AccessPermission, TypeExtField, IsShareable, IsCacheable, IsBufferable, SubRegionDisable, Size) \
ARM_MPU_RASR_EX(DisableExec, AccessPermission, ARM_MPU_ACCESS_(TypeExtField, IsShareable, IsCacheable, IsBufferable), SubRegionDisable, Size)
/**
* MPU Memory Access Attribute for strongly ordered memory.
* - TEX: 000b
* - Shareable
* - Non-cacheable
* - Non-bufferable
*/
#define ARM_MPU_ACCESS_ORDERED ARM_MPU_ACCESS_(0U, 1U, 0U, 0U)
/**
* MPU Memory Access Attribute for device memory.
* - TEX: 000b (if shareable) or 010b (if non-shareable)
* - Shareable or non-shareable
* - Non-cacheable
* - Bufferable (if shareable) or non-bufferable (if non-shareable)
*
* \param IsShareable Configures the device memory as shareable or non-shareable.
*/
#define ARM_MPU_ACCESS_DEVICE(IsShareable) ((IsShareable) ? ARM_MPU_ACCESS_(0U, 1U, 0U, 1U) : ARM_MPU_ACCESS_(2U, 0U, 0U, 0U))
/**
* MPU Memory Access Attribute for normal memory.
* - TEX: 1BBb (reflecting outer cacheability rules)
* - Shareable or non-shareable
* - Cacheable or non-cacheable (reflecting inner cacheability rules)
* - Bufferable or non-bufferable (reflecting inner cacheability rules)
*
* \param OuterCp Configures the outer cache policy.
* \param InnerCp Configures the inner cache policy.
* \param IsShareable Configures the memory as shareable or non-shareable.
*/
#define ARM_MPU_ACCESS_NORMAL(OuterCp, InnerCp, IsShareable) ARM_MPU_ACCESS_((4U | (OuterCp)), IsShareable, ((InnerCp) & 2U), ((InnerCp) & 1U))
/**
* MPU Memory Access Attribute non-cacheable policy.
*/
#define ARM_MPU_CACHEP_NOCACHE 0U
/**
* MPU Memory Access Attribute write-back, write and read allocate policy.
*/
#define ARM_MPU_CACHEP_WB_WRA 1U
/**
* MPU Memory Access Attribute write-through, no write allocate policy.
*/
#define ARM_MPU_CACHEP_WT_NWA 2U
/**
* MPU Memory Access Attribute write-back, no write allocate policy.
*/
#define ARM_MPU_CACHEP_WB_NWA 3U
/**
* Struct for a single MPU Region
*/
typedef struct {
uint32_t RBAR; //!< The region base address register value (RBAR)
uint32_t RASR; //!< The region attribute and size register value (RASR) \ref MPU_RASR
} ARM_MPU_Region_t;
/** Enable the MPU.
* \param MPU_Control Default access permissions for unconfigured regions.
*/
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
{
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
#endif
__DSB();
__ISB();
}
/** Disable the MPU.
*/
__STATIC_INLINE void ARM_MPU_Disable(void)
{
__DMB();
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
#endif
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
}
/** Clear and disable the given MPU region.
* \param rnr Region number to be cleared.
*/
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
{
MPU->RNR = rnr;
MPU->RASR = 0U;
}
/** Configure an MPU region.
* \param rbar Value for RBAR register.
* \param rsar Value for RSAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rbar, uint32_t rasr)
{
MPU->RBAR = rbar;
MPU->RASR = rasr;
}
/** Configure the given MPU region.
* \param rnr Region number to be configured.
* \param rbar Value for RBAR register.
* \param rsar Value for RSAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegionEx(uint32_t rnr, uint32_t rbar, uint32_t rasr)
{
MPU->RNR = rnr;
MPU->RBAR = rbar;
MPU->RASR = rasr;
}
/** Memcopy with strictly ordered memory access, e.g. for register targets.
* \param dst Destination data is copied to.
* \param src Source data is copied from.
* \param len Amount of data words to be copied.
*/
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
{
uint32_t i;
for (i = 0U; i < len; ++i)
{
dst[i] = src[i];
}
}
/** Load the given number of MPU regions from a table.
* \param table Pointer to the MPU configuration table.
* \param cnt Amount of regions to be configured.
*/
__STATIC_INLINE void ARM_MPU_Load(ARM_MPU_Region_t const* table, uint32_t cnt)
{
const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
while (cnt > MPU_TYPE_RALIASES) {
ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), MPU_TYPE_RALIASES*rowWordSize);
table += MPU_TYPE_RALIASES;
cnt -= MPU_TYPE_RALIASES;
}
ARM_MPU_OrderedMemcpy(&(MPU->RBAR), &(table->RBAR), cnt*rowWordSize);
}
#endif

View File

@ -0,0 +1,346 @@
/******************************************************************************
* @file mpu_armv8.h
* @brief CMSIS MPU API for Armv8-M and Armv8.1-M MPU
* @version V5.1.0
* @date 08. March 2019
******************************************************************************/
/*
* Copyright (c) 2017-2019 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef ARM_MPU_ARMV8_H
#define ARM_MPU_ARMV8_H
/** \brief Attribute for device memory (outer only) */
#define ARM_MPU_ATTR_DEVICE ( 0U )
/** \brief Attribute for non-cacheable, normal memory */
#define ARM_MPU_ATTR_NON_CACHEABLE ( 4U )
/** \brief Attribute for normal memory (outer and inner)
* \param NT Non-Transient: Set to 1 for non-transient data.
* \param WB Write-Back: Set to 1 to use write-back update policy.
* \param RA Read Allocation: Set to 1 to use cache allocation on read miss.
* \param WA Write Allocation: Set to 1 to use cache allocation on write miss.
*/
#define ARM_MPU_ATTR_MEMORY_(NT, WB, RA, WA) \
(((NT & 1U) << 3U) | ((WB & 1U) << 2U) | ((RA & 1U) << 1U) | (WA & 1U))
/** \brief Device memory type non Gathering, non Re-ordering, non Early Write Acknowledgement */
#define ARM_MPU_ATTR_DEVICE_nGnRnE (0U)
/** \brief Device memory type non Gathering, non Re-ordering, Early Write Acknowledgement */
#define ARM_MPU_ATTR_DEVICE_nGnRE (1U)
/** \brief Device memory type non Gathering, Re-ordering, Early Write Acknowledgement */
#define ARM_MPU_ATTR_DEVICE_nGRE (2U)
/** \brief Device memory type Gathering, Re-ordering, Early Write Acknowledgement */
#define ARM_MPU_ATTR_DEVICE_GRE (3U)
/** \brief Memory Attribute
* \param O Outer memory attributes
* \param I O == ARM_MPU_ATTR_DEVICE: Device memory attributes, else: Inner memory attributes
*/
#define ARM_MPU_ATTR(O, I) (((O & 0xFU) << 4U) | (((O & 0xFU) != 0U) ? (I & 0xFU) : ((I & 0x3U) << 2U)))
/** \brief Normal memory non-shareable */
#define ARM_MPU_SH_NON (0U)
/** \brief Normal memory outer shareable */
#define ARM_MPU_SH_OUTER (2U)
/** \brief Normal memory inner shareable */
#define ARM_MPU_SH_INNER (3U)
/** \brief Memory access permissions
* \param RO Read-Only: Set to 1 for read-only memory.
* \param NP Non-Privileged: Set to 1 for non-privileged memory.
*/
#define ARM_MPU_AP_(RO, NP) (((RO & 1U) << 1U) | (NP & 1U))
/** \brief Region Base Address Register value
* \param BASE The base address bits [31:5] of a memory region. The value is zero extended. Effective address gets 32 byte aligned.
* \param SH Defines the Shareability domain for this memory region.
* \param RO Read-Only: Set to 1 for a read-only memory region.
* \param NP Non-Privileged: Set to 1 for a non-privileged memory region.
* \oaram XN eXecute Never: Set to 1 for a non-executable memory region.
*/
#define ARM_MPU_RBAR(BASE, SH, RO, NP, XN) \
((BASE & MPU_RBAR_BASE_Msk) | \
((SH << MPU_RBAR_SH_Pos) & MPU_RBAR_SH_Msk) | \
((ARM_MPU_AP_(RO, NP) << MPU_RBAR_AP_Pos) & MPU_RBAR_AP_Msk) | \
((XN << MPU_RBAR_XN_Pos) & MPU_RBAR_XN_Msk))
/** \brief Region Limit Address Register value
* \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended.
* \param IDX The attribute index to be associated with this memory region.
*/
#define ARM_MPU_RLAR(LIMIT, IDX) \
((LIMIT & MPU_RLAR_LIMIT_Msk) | \
((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
(MPU_RLAR_EN_Msk))
#if defined(MPU_RLAR_PXN_Pos)
/** \brief Region Limit Address Register with PXN value
* \param LIMIT The limit address bits [31:5] for this memory region. The value is one extended.
* \param PXN Privileged execute never. Defines whether code can be executed from this privileged region.
* \param IDX The attribute index to be associated with this memory region.
*/
#define ARM_MPU_RLAR_PXN(LIMIT, PXN, IDX) \
((LIMIT & MPU_RLAR_LIMIT_Msk) | \
((PXN << MPU_RLAR_PXN_Pos) & MPU_RLAR_PXN_Msk) | \
((IDX << MPU_RLAR_AttrIndx_Pos) & MPU_RLAR_AttrIndx_Msk) | \
(MPU_RLAR_EN_Msk))
#endif
/**
* Struct for a single MPU Region
*/
typedef struct {
uint32_t RBAR; /*!< Region Base Address Register value */
uint32_t RLAR; /*!< Region Limit Address Register value */
} ARM_MPU_Region_t;
/** Enable the MPU.
* \param MPU_Control Default access permissions for unconfigured regions.
*/
__STATIC_INLINE void ARM_MPU_Enable(uint32_t MPU_Control)
{
MPU->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
#endif
__DSB();
__ISB();
}
/** Disable the MPU.
*/
__STATIC_INLINE void ARM_MPU_Disable(void)
{
__DMB();
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
#endif
MPU->CTRL &= ~MPU_CTRL_ENABLE_Msk;
}
#ifdef MPU_NS
/** Enable the Non-secure MPU.
* \param MPU_Control Default access permissions for unconfigured regions.
*/
__STATIC_INLINE void ARM_MPU_Enable_NS(uint32_t MPU_Control)
{
MPU_NS->CTRL = MPU_Control | MPU_CTRL_ENABLE_Msk;
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB_NS->SHCSR |= SCB_SHCSR_MEMFAULTENA_Msk;
#endif
__DSB();
__ISB();
}
/** Disable the Non-secure MPU.
*/
__STATIC_INLINE void ARM_MPU_Disable_NS(void)
{
__DMB();
#ifdef SCB_SHCSR_MEMFAULTENA_Msk
SCB_NS->SHCSR &= ~SCB_SHCSR_MEMFAULTENA_Msk;
#endif
MPU_NS->CTRL &= ~MPU_CTRL_ENABLE_Msk;
}
#endif
/** Set the memory attribute encoding to the given MPU.
* \param mpu Pointer to the MPU to be configured.
* \param idx The attribute index to be set [0-7]
* \param attr The attribute value to be set.
*/
__STATIC_INLINE void ARM_MPU_SetMemAttrEx(MPU_Type* mpu, uint8_t idx, uint8_t attr)
{
const uint8_t reg = idx / 4U;
const uint32_t pos = ((idx % 4U) * 8U);
const uint32_t mask = 0xFFU << pos;
if (reg >= (sizeof(mpu->MAIR) / sizeof(mpu->MAIR[0]))) {
return; // invalid index
}
mpu->MAIR[reg] = ((mpu->MAIR[reg] & ~mask) | ((attr << pos) & mask));
}
/** Set the memory attribute encoding.
* \param idx The attribute index to be set [0-7]
* \param attr The attribute value to be set.
*/
__STATIC_INLINE void ARM_MPU_SetMemAttr(uint8_t idx, uint8_t attr)
{
ARM_MPU_SetMemAttrEx(MPU, idx, attr);
}
#ifdef MPU_NS
/** Set the memory attribute encoding to the Non-secure MPU.
* \param idx The attribute index to be set [0-7]
* \param attr The attribute value to be set.
*/
__STATIC_INLINE void ARM_MPU_SetMemAttr_NS(uint8_t idx, uint8_t attr)
{
ARM_MPU_SetMemAttrEx(MPU_NS, idx, attr);
}
#endif
/** Clear and disable the given MPU region of the given MPU.
* \param mpu Pointer to MPU to be used.
* \param rnr Region number to be cleared.
*/
__STATIC_INLINE void ARM_MPU_ClrRegionEx(MPU_Type* mpu, uint32_t rnr)
{
mpu->RNR = rnr;
mpu->RLAR = 0U;
}
/** Clear and disable the given MPU region.
* \param rnr Region number to be cleared.
*/
__STATIC_INLINE void ARM_MPU_ClrRegion(uint32_t rnr)
{
ARM_MPU_ClrRegionEx(MPU, rnr);
}
#ifdef MPU_NS
/** Clear and disable the given Non-secure MPU region.
* \param rnr Region number to be cleared.
*/
__STATIC_INLINE void ARM_MPU_ClrRegion_NS(uint32_t rnr)
{
ARM_MPU_ClrRegionEx(MPU_NS, rnr);
}
#endif
/** Configure the given MPU region of the given MPU.
* \param mpu Pointer to MPU to be used.
* \param rnr Region number to be configured.
* \param rbar Value for RBAR register.
* \param rlar Value for RLAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegionEx(MPU_Type* mpu, uint32_t rnr, uint32_t rbar, uint32_t rlar)
{
mpu->RNR = rnr;
mpu->RBAR = rbar;
mpu->RLAR = rlar;
}
/** Configure the given MPU region.
* \param rnr Region number to be configured.
* \param rbar Value for RBAR register.
* \param rlar Value for RLAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegion(uint32_t rnr, uint32_t rbar, uint32_t rlar)
{
ARM_MPU_SetRegionEx(MPU, rnr, rbar, rlar);
}
#ifdef MPU_NS
/** Configure the given Non-secure MPU region.
* \param rnr Region number to be configured.
* \param rbar Value for RBAR register.
* \param rlar Value for RLAR register.
*/
__STATIC_INLINE void ARM_MPU_SetRegion_NS(uint32_t rnr, uint32_t rbar, uint32_t rlar)
{
ARM_MPU_SetRegionEx(MPU_NS, rnr, rbar, rlar);
}
#endif
/** Memcopy with strictly ordered memory access, e.g. for register targets.
* \param dst Destination data is copied to.
* \param src Source data is copied from.
* \param len Amount of data words to be copied.
*/
__STATIC_INLINE void ARM_MPU_OrderedMemcpy(volatile uint32_t* dst, const uint32_t* __RESTRICT src, uint32_t len)
{
uint32_t i;
for (i = 0U; i < len; ++i)
{
dst[i] = src[i];
}
}
/** Load the given number of MPU regions from a table to the given MPU.
* \param mpu Pointer to the MPU registers to be used.
* \param rnr First region number to be configured.
* \param table Pointer to the MPU configuration table.
* \param cnt Amount of regions to be configured.
*/
__STATIC_INLINE void ARM_MPU_LoadEx(MPU_Type* mpu, uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
{
const uint32_t rowWordSize = sizeof(ARM_MPU_Region_t)/4U;
if (cnt == 1U) {
mpu->RNR = rnr;
ARM_MPU_OrderedMemcpy(&(mpu->RBAR), &(table->RBAR), rowWordSize);
} else {
uint32_t rnrBase = rnr & ~(MPU_TYPE_RALIASES-1U);
uint32_t rnrOffset = rnr % MPU_TYPE_RALIASES;
mpu->RNR = rnrBase;
while ((rnrOffset + cnt) > MPU_TYPE_RALIASES) {
uint32_t c = MPU_TYPE_RALIASES - rnrOffset;
ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), c*rowWordSize);
table += c;
cnt -= c;
rnrOffset = 0U;
rnrBase += MPU_TYPE_RALIASES;
mpu->RNR = rnrBase;
}
ARM_MPU_OrderedMemcpy(&(mpu->RBAR)+(rnrOffset*2U), &(table->RBAR), cnt*rowWordSize);
}
}
/** Load the given number of MPU regions from a table.
* \param rnr First region number to be configured.
* \param table Pointer to the MPU configuration table.
* \param cnt Amount of regions to be configured.
*/
__STATIC_INLINE void ARM_MPU_Load(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
{
ARM_MPU_LoadEx(MPU, rnr, table, cnt);
}
#ifdef MPU_NS
/** Load the given number of MPU regions from a table to the Non-secure MPU.
* \param rnr First region number to be configured.
* \param table Pointer to the MPU configuration table.
* \param cnt Amount of regions to be configured.
*/
__STATIC_INLINE void ARM_MPU_Load_NS(uint32_t rnr, ARM_MPU_Region_t const* table, uint32_t cnt)
{
ARM_MPU_LoadEx(MPU_NS, rnr, table, cnt);
}
#endif
#endif

View File

@ -0,0 +1,70 @@
/******************************************************************************
* @file tz_context.h
* @brief Context Management for Armv8-M TrustZone
* @version V1.0.1
* @date 10. January 2018
******************************************************************************/
/*
* Copyright (c) 2017-2018 Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined ( __ICCARM__ )
#pragma system_include /* treat file as system include file for MISRA check */
#elif defined (__clang__)
#pragma clang system_header /* treat file as system include file */
#endif
#ifndef TZ_CONTEXT_H
#define TZ_CONTEXT_H
#include <stdint.h>
#ifndef TZ_MODULEID_T
#define TZ_MODULEID_T
/// \details Data type that identifies secure software modules called by a process.
typedef uint32_t TZ_ModuleId_t;
#endif
/// \details TZ Memory ID identifies an allocated memory slot.
typedef uint32_t TZ_MemoryId_t;
/// Initialize secure context memory system
/// \return execution status (1: success, 0: error)
uint32_t TZ_InitContextSystem_S (void);
/// Allocate context memory for calling secure software modules in TrustZone
/// \param[in] module identifies software modules called from non-secure mode
/// \return value != 0 id TrustZone memory slot identifier
/// \return value 0 no memory available or internal error
TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module);
/// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
/// \param[in] id TrustZone memory slot identifier
/// \return execution status (1: success, 0: error)
uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id);
/// Load secure context (called on RTOS thread context switch)
/// \param[in] id TrustZone memory slot identifier
/// \return execution status (1: success, 0: error)
uint32_t TZ_LoadContext_S (TZ_MemoryId_t id);
/// Store secure context (called on RTOS thread context switch)
/// \param[in] id TrustZone memory slot identifier
/// \return execution status (1: success, 0: error)
uint32_t TZ_StoreContext_S (TZ_MemoryId_t id);
#endif // TZ_CONTEXT_H

View File

@ -0,0 +1,486 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file adc.h
**
** Header file for AD Converter functions
** @link ADC Group Some description @endlink
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
#ifndef __ADC_H__
#define __ADC_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup AdcGroup AD Converter (ADC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global definitions
******************************************************************************/
#define ADC_SCAN_CH0_EN (0x1u) /*!< SCAN模式使用ADC CH0 */
#define ADC_SCAN_CH1_EN (0x1u<<1) /*!< SCAN模式使用ADC CH1 */
#define ADC_SCAN_CH2_EN (0x1u<<2) /*!< SCAN模式使用ADC CH2 */
#define ADC_SCAN_CH3_EN (0x1u<<3) /*!< SCAN模式使用ADC CH3 */
#define ADC_SCAN_CH4_EN (0x1u<<4) /*!< SCAN模式使用ADC CH4 */
#define ADC_SCAN_CH5_EN (0x1u<<5) /*!< SCAN模式使用ADC CH5 */
#define ADC_SCAN_CH6_EN (0x1u<<6) /*!< SCAN模式使用ADC CH6 */
#define ADC_SCAN_CH7_EN (0x1u<<7) /*!< SCAN模式使用ADC CH7 */
/******************************************************************************
** Global type definitions
*****************************************************************************/
/**
******************************************************************************
** \brief ADC采样模式
*****************************************************************************/
typedef enum en_adc_op_mode
{
AdcSglMode = 0u, /*!< 单输入通道单次采样模式 */
AdcSCanMode = 1u, /*!< 多输入通道顺序扫描采样模式,多输入通道插队扫描采样模式*/
} en_adc_op_mode_t;
/**
******************************************************************************
** \brief ADC时钟选择
*****************************************************************************/
typedef enum en_adc_clk_sel
{
AdcClkSysTDiv1 = 0u, /*!< PCLK */
AdcClkSysTDiv2 = 1u, /*!< 1/2 PCLK */
AdcClkSysTDiv4 = 2u, /*!< 1/4 PCLK */
AdcClkSysTDiv8 = 3u, /*!< 1/8 PCLK */
} en_adc_clk_div_t;
/**
******************************************************************************
** \brief ADC参考电压
*****************************************************************************/
typedef enum en_adc_ref_vol_sel
{
RefVolSelInBgr1p5 = 0u, /*!<内部参考电压1.5V(SPS<=200kHz)*/
RefVolSelInBgr2p5 = 1u, /*!<内部参考电压2.5V(avdd>3V,SPS<=200kHz)*/
RefVolSelExtern1 = 2u, /*!<外部输入(max avdd) PB01*/
RefVolSelAVDD = 3u, /*!<AVDD*/
}en_adc_ref_vol_sel_t;
/**
******************************************************************************
** \brief ADC采样通道选择
*****************************************************************************/
typedef enum en_adc_samp_ch_sel
{
AdcExInputCH0 = 0u, /*!<使用通道0输入PA00*/
AdcExInputCH1 = 1u, /*!<使用通道1输入PA01*/
AdcExInputCH2 = 2u, /*!<使用通道2输入PA02*/
AdcExInputCH3 = 3u, /*!<使用通道3输入PA03*/
AdcExInputCH4 = 4u, /*!<使用通道4输入PA04*/
AdcExInputCH5 = 5u, /*!<使用通道5输入PA05*/
AdcExInputCH6 = 6u, /*!<使用通道6输入PA06*/
AdcExInputCH7 = 7u, /*!<使用通道7输入PA07*/
AdcExInputCH8 = 8u, /*!<使用通道8输入PB00*/
AdcExInputCH9 = 9u, /*!<使用通道8输入PB01*/
AdcExInputCH10 = 10u, /*!<使用通道8输入PC00*/
AdcExInputCH11 = 11u, /*!<使用通道1输入PC01*/
AdcExInputCH12 = 12u, /*!<使用通道2输入PC02*/
AdcExInputCH13 = 13u, /*!<使用通道3输入PC03*/
AdcExInputCH14 = 14u, /*!<使用通道4输入PC04*/
AdcExInputCH15 = 15u, /*!<使用通道5输入PC05*/
AdcExInputCH16 = 16u, /*!<使用通道6输入PB02*/
AdcExInputCH17 = 17u, /*!<使用通道7输入PB10*/
AdcExInputCH18 = 18u, /*!<使用通道8输入PB11*/
AdcExInputCH19 = 19u, /*!<使用通道8输入PB12*/
AdcExInputCH20 = 20u, /*!<使用通道7输入PB13*/
AdcExInputCH21 = 21u, /*!<使用通道8输入PB14*/
AdcExInputCH22 = 22u, /*!<使用通道8输入PB15*/
AdcExInputCH23 = 23u, /*!<使用通道8输入PC06*/
AdcOPA0Input = 24u, /*!<使用通道8输入OPA0*/
AdcOPA1Input = 25u, /*!<使用通道8输入OPA1*/
AdcOPA2Input = 26u, /*!<使用通道8输入OPA2*/
AdcAVccDiV3Input = 27u, /*!<使用1/3 AVCC(必须使用输入增益)*/
AdcAiTsInput = 28u, /*!<使用BGR_TS(必须使用输入增益)*/
AdcVref1P2Input = 29u, /*!<使用Vref1P2(必须使用输入增益)*/
}en_adc_samp_ch_sel_t;
/**
******************************************************************************
** \brief ADC采样周期数选择
*****************************************************************************/
typedef enum en_adc_samp_time_sel
{
AdcSampTime4Clk = 0u, /*!<4个采样时钟*/
AdcSampTime6Clk = 1u, /*!<6个采样时钟*/
AdcSampTime8Clk = 2u, /*!<8个采样时钟*/
AdcSampTime12Clk = 3u, /*!<12个采样时钟*/
}en_adc_samp_time_sel_t;
/**
******************************************************************************
** \brief ADC周边模块反射源选择
*****************************************************************************/
typedef enum en_adc_trig_sel
{
AdcTrigTimer0 = 0u, /*!<选择timer0中断源自动触发ADC采样*/
AdcTrigTimer1 = 1u, /*!<选择timer1中断源自动触发ADC采样*/
AdcTrigTimer2 = 2u, /*!<选择timer2中断源自动触发ADC采样*/
AdcTrigTimer3 = 3u, /*!<选择timer3中断源自动触发ADC采样*/
AdcTrigTimer4 = 4u, /*!<选择timer4中断源自动触发ADC采样*/
AdcTrigTimer5 = 5u, /*!<选择timer5中断源自动触发ADC采样*/
AdcTrigTimer6 = 6u, /*!<选择timer6中断源自动触发ADC采样*/
AdcTrigUart0 = 7u, /*!<选择uart0中断源自动触发ADC采样*/
AdcTrigUart1 = 8u, /*!<选择uart1中断源自动触发ADC采样*/
AdcTrigLpuart0 = 9u, /*!<选择lpuart0中断源自动触发ADC采样*/
AdcTrigLpuart1 = 10u, /*!<选择lpuart1中断源自动触发ADC采样*/
AdcTrigVC0 = 11u, /*!<选择VC0中断源自动触发ADC采样*/
AdcTrigVC1 = 12u, /*!<选择VC1中断源自动触发ADC采样*/
AdcTrigRTC = 13u, /*!<选择RTC中断源自动触发ADC采样*/
AdcTrigPCA = 14u, /*!<选择PCA中断源自动触发ADC采样*/
AdcTrigSPI0 = 15u, /*!<选择SPI0中断源自动触发ADC采样*/
AdcTrigSPI1 = 16u, /*!<选择SPI1中断源自动触发ADC采样*/
AdcTrigDMA = 17u, /*!<选择DMA中断源自动触发ADC采样*/
AdcTrigPA03 = 18u, /*!<选择PA03中断源自动触发ADC采样*/
AdcTrigPB03 = 19u, /*!<选择PB03中断源自动触发ADC采样*/
AdcTrigPC03 = 20u, /*!<选择PC03中断源自动触发ADC采样*/
AdcTrigPD03 = 21u, /*!<选择PD03中断源自动触发ADC采样*/
AdcTrigPA07 = 22u, /*!<选择PA07中断源自动触发ADC采样*/
AdcTrigPB07 = 23u, /*!<选择PB07中断源自动触发ADC采样*/
AdcTrigPC07 = 24u, /*!<选择PC07中断源自动触发ADC采样*/
AdcTrigPD07 = 25u, /*!<选择PD07中断源自动触发ADC采样*/
AdcTrigPA11 = 26u, /*!<选择PA11中断源自动触发ADC采样*/
AdcTrigPB11 = 27u, /*!<选择PB11中断源自动触发ADC采样*/
AdcTrigPC11 = 28u, /*!<选择PC11中断源自动触发ADC采样*/
AdcTrigPA15 = 29u, /*!<选择PA15中断源自动触发ADC采样*/
AdcTrigPB15 = 30u, /*!<选择PB15中断源自动触发ADC采样*/
AdcTrigPC15 = 31u, /*!<选择PC15中断源自动触发ADC采样*/
}en_adc_trig_sel_t;
/**
******************************************************************************
** \brief ADC外部触发源寄存器选择
*****************************************************************************/
typedef enum en_adc_ext_trig_sel
{
AdcExtTrig0 = 0u, /*!<单次及顺序扫描转换 外部触发源选择寄存器*/
AdcExtTrig1 = 1u, /*!<插队扫描转换 外部触发源选择寄存器*/
}en_adc_ext_trig_sel_t;
/**
******************************************************************************
** \brief ADC顺序转换通道
*****************************************************************************/
typedef enum en_adc_sqr_chmux
{
CH0MUX = 0u, /*!<转换通道0*/
CH1MUX = 1u, /*!<转换通道1*/
CH2MUX = 2u, /*!<转换通道2*/
CH3MUX = 3u, /*!<转换通道3*/
CH4MUX = 4u, /*!<转换通道4*/
CH5MUX = 5u, /*!<转换通道5*/
CH6MUX = 6u, /*!<转换通道6*/
CH7MUX = 7u, /*!<转换通道7*/
CH8MUX = 8u, /*!<转换通道8*/
CH9MUX = 9u, /*!<转换通道9*/
CH10MUX = 10u, /*!<转换通道10*/
CH11MUX = 11u, /*!<转换通道11*/
CH12MUX = 12u, /*!<转换通道12*/
CH13MUX = 13u, /*!<转换通道13*/
CH14MUX = 14u, /*!<转换通道14*/
CH15MUX = 15u, /*!<转换通道15*/
}en_adc_sqr_chmux_t;
/**
******************************************************************************
** \brief ADC插队转换通道
*****************************************************************************/
typedef enum en_adc_jqr_chmux
{
JQRCH0MUX = 0u, /*!<转换通道0*/
JQRCH1MUX = 1u, /*!<转换通道1*/
JQRCH2MUX = 2u, /*!<转换通道2*/
JQRCH3MUX = 3u, /*!<转换通道3*/
}en_adc_jqr_chmux_t;
/**
******************************************************************************
** \brief ADC结果对齐方式
*****************************************************************************/
typedef enum en_adc_align
{
AlignRight = 0u,
AlignLeft = 1u,
}en_adc_align_t;
/******************************************************************************
* Extern type definitions ('typedef') *
******************************************************************************/
/**
******************************************************************************
** \brief ADC配置
*****************************************************************************/
typedef struct stc_adc_cfg
{
/*! ADC操作模式*/
en_adc_op_mode_t enAdcOpMode;
/*! ADC时钟选择*/
en_adc_clk_div_t enAdcClkDiv;
/*! ADC采样时间*/
en_adc_samp_time_sel_t enAdcSampTimeSel;
/*! ADC参考电压*/
en_adc_ref_vol_sel_t enAdcRefVolSel;
/*! ADC输入增益使能*/
boolean_t bAdcInBufEn;
}stc_adc_cfg_t;
/**
******************************************************************************
** \brief ADC DMA触发源寄存器配置
*****************************************************************************/
typedef enum en_adc_dmatrig
{
/*!插队扫描触发DMA读取控制*/
DmaJqr = 0,
/*!顺序扫描触发DMA读取控制*/
DmaSqr = 1
}en_adc_dmatrig_t;
/**
******************************************************************************
** \brief ADC外部触发源寄存器配置
*****************************************************************************/
typedef struct stc_adc_ext_trig_cfg
{
/*! 外部触发源寄存器选择*/
en_adc_ext_trig_sel_t enAdcExtTrigRegSel;
/*! ADC单次及顺序转换触发选择*/
en_adc_trig_sel_t enAdcTrig0Sel;
/*! ADC插队转换触发选择*/
en_adc_trig_sel_t enAdcTrig1Sel;
}stc_adc_ext_trig_cfg_t;
/**
******************************************************************************
** \brief ADC中断配置
*****************************************************************************/
typedef struct stc_adc_irq
{
/*!<ADC插队扫描完成中断*/
boolean_t bAdcJQRIrq;
/*!<ADC顺序扫描完成中断*/
boolean_t bAdcSQRIrq;
/*! ADC区间中断*/
boolean_t bAdcRegCmp;
/*! ADC上超出区间中断*/
boolean_t bAdcHhtCmp;
/*! ADC下超出区间中断*/
boolean_t bAdcLltCmp;
/*!<ADC单次转换完成中断*/
boolean_t bAdcIrq;
}stc_adc_irq_t;
typedef struct stc_adc_threshold_cfg
{
boolean_t bAdcRegCmp ; /*!ADC区间使能*/
boolean_t bAdcHhtCmp ; /*!ADC上超出区间使能*/
boolean_t bAdcLltCmp ; /*!ADC下超出区间使能*/
uint32_t u32AdcRegHighThd; /*!ADC下超出区间*/
uint32_t u32AdcRegLowThd; /*!ADC下超出区间*/
en_adc_samp_ch_sel_t enThCh; /*!阈值比较通道选择*/
}stc_adc_threshold_cfg_t;
/**
******************************************************************************
** \brief ADC中断回调函数
*****************************************************************************/
typedef struct stc_adc_irq_calbakfn_pt
{
/*! ADC插队扫描中断回调函数指针*/
func_ptr_t pfnAdcJQRIrq;
/*! ADC顺序扫描中断回调函数指针*/
func_ptr_t pfnAdcSQRIrq;
/*! ADC区间中断回调函数指针*/
func_ptr_t pfnAdcRegIrq;
/*! ADC上超出区间中断回调函数指针*/
func_ptr_t pfnAdcHhtIrq;
/*! ADC下超出区间中断回调函数指针*/
func_ptr_t pfnAdcLltIrq;
/*! ADC单次转换中断回调函数指针*/
func_ptr_t pfnAdcIrq;
}stc_adc_irq_calbakfn_pt_t;
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//ADC initialization
en_result_t Adc_Init(stc_adc_cfg_t* pstcAdcConfig);
//ADC ExtTrig Register config
en_result_t Adc_ExtTrigCfg(stc_adc_ext_trig_cfg_t* pstcExtTrigConfig);
//ADC de-init
void Adc_DeInit(void);
//ADC conversion start
void Adc_SGL_Start(void);
//ADC conversion stop
void Adc_SGL_Stop(void);
//ADC SQR conversion start
void Adc_SQR_Start(void);
//ADC SQR conversion stop
void Adc_SQR_Stop(void);
//ADC JQR conversion start
void Adc_JQR_Start(void);
//ADC JQR conversion stop
void Adc_JQR_Stop(void);
//ADC conversion enable
void Adc_Enable(void);
//ADC conversion disable
void Adc_Disable(void);
//ADC single covert mode configuration
en_result_t Adc_ConfigSglMode(stc_adc_cfg_t* pstcAdcConfig);
//ADC SQR mode configuration
en_result_t Adc_ConfigSqrMode(stc_adc_cfg_t* pstcAdcConfig, uint8_t u8AdcSampCnt,boolean_t bAdcResultAccEn);
//ADC JQR mode configuration
en_result_t Adc_ConfigJqrMode(stc_adc_cfg_t* pstcAdcConfig, uint8_t u8AdcSampCnt,boolean_t bAdcResultAccEn);
//ADC single covert mode channel configuraion
en_result_t Adc_ConfigSglChannel( en_adc_samp_ch_sel_t enstcAdcSampCh);
//ADC SQR mode channel configuraion
en_result_t Adc_ConfigSqrChannel(en_adc_sqr_chmux_t enstcAdcSqrChMux, en_adc_samp_ch_sel_t enstcAdcSampCh);
//ADC JQR mode channel configuraion
en_result_t Adc_ConfigJqrChannel(en_adc_jqr_chmux_t enstcAdcJqrChMux, en_adc_samp_ch_sel_t enstcAdcSampCh);
//ADC DMA Trigger
en_result_t Adc_ConfigDmaTrig(en_adc_dmatrig_t enAdcDmaTrig);
//ADC IRQ configuration
void Adc_ConfigIrq(stc_adc_irq_t* pstcAdcIrqCfg,
stc_adc_irq_calbakfn_pt_t* pstcAdcIrqCalbaks);
//ADC enable IRQ
void Adc_EnableIrq(void);
//ADC disable IRQ
void Adc_DisableIrq(void);
//ADC enable threshold compare
void Adc_ThresholdCfg(stc_adc_threshold_cfg_t* stcAdcThrCfg);
//ADC get IRQ state
void Adc_GetIrqState(stc_adc_irq_t* pstcAdcIrqState);
//ADC clear IRQ states
void Adc_ClrSglIrqState(void);
void Adc_ClrJqrIrqState(void);
void Adc_ClrSqrIrqState(void);
void Adc_ClrRegIrqState(void);
void Adc_ClrHtIrqState(void);
void Adc_ClrLtIrqState(void);
//查询ADC单次转换状态
boolean_t Adc_PollSglBusyState(void);
//查询ADC顺序扫描转换转换状态
boolean_t Adc_PollSqrBusyState(void);
//查询ADC插队扫描转换状态
boolean_t Adc_PollJqrBusyState(void);
//查询ADC结果比较区间状态
boolean_t Adc_PollRegBusyState(void);
//查询ADC结果比较上阈值状态
boolean_t Adc_PollHTBusyState(void);
//查询ADC结果比较下阈值状态
boolean_t Adc_PollLtBusyState(void);
//获取单次转换采样值
en_result_t Adc_GetSglResult(uint16_t* pu16AdcResult);
//获取顺序扫描采样值
en_result_t Adc_GetSqrResult(uint16_t* pu16AdcResult,uint8_t SQRChannelIndex);
//获取插队扫描采样值
en_result_t Adc_GetJqrResult(uint16_t* pu16AdcResult,uint8_t JQRChannelIndex);
//获取累加采样值
en_result_t Adc_GetAccResult(uint32_t* pu32AdcAccResult);
//clear ADC accumulated result
void Adc_ClrAccResult(void);
//设置参考电压
en_result_t Adc_SetVref(en_adc_ref_vol_sel_t enAdcRefVolSel);
//设置结果对齐方式
en_result_t Adc_SetAlign(en_adc_align_t enAlign);
//@}
#ifdef __cplusplus
}
#endif
#endif /* __ADC_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/

View File

@ -0,0 +1,819 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file adt.h
**
** Headerfile for Advance Timer functions
** @link ADT Group Some description @endlink
**
** - 2018-04-18 Husj First Version
**
******************************************************************************/
#ifndef __ADT_H__
#define __ADT_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup AdtGroup Advance Timer (ADT)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief
*****************************************************************************/
typedef enum en_adt_unit
{
AdtTIM4 = 0u, ///< TIM4
AdtTIM5 = 1u, ///< TIM5
AdtTIM6 = 2u, ///< TIM6
}en_adt_unit_t;
/**
******************************************************************************
** \brief ADT CHx端口定义
*****************************************************************************/
typedef enum en_adt_CHxX_port
{
AdtCHxA = 0u, ///< CHx A端口
AdtCHxB = 1u, ///< CHx B端口
}en_adt_CHxX_port_t;
/**
******************************************************************************
** \brief ADT TRIG端口定义
*****************************************************************************/
typedef enum en_adt_trig_port
{
AdtTrigA = 0u, ///< TIMx 触发A端口
AdtTrigB = 1u, ///< TIMx 触发B端口
AdtTrigC = 2u, ///< TIMx 触发C端口
AdtTrigD = 3u, ///< TIMx 触发D端口
}en_adt_trig_port_t;
/**
******************************************************************************
** \brief ADT通用控制 - Z相输入屏蔽周期数
**
** \note
******************************************************************************/
typedef enum en_adt_gconr_zmsk
{
AdtZMaskDis = 0u, ///< Z相输入屏蔽功能无效
AdtZMask4Cyl = 1u, ///< 位置计数上溢后或下溢后的4个计数周期内的Z相输入被屏蔽
AdtZMask8Cyl = 2u, ///< 位置计数上溢后或下溢后的8个计数周期内的Z相输入被屏蔽
AdtZMask16Cyl = 3u, ///< 位置计数上溢后或下溢后的16个计数周期内的Z相输入被屏蔽
}en_adt_gconr_zmsk_t;
/**
******************************************************************************
** \brief ADT通用控制 -
**
** \note
******************************************************************************/
typedef enum en_adt_cnt_ckdiv
{
AdtClkPClk0 = 0u, ///< PCLK0
AdtClkPClk0Div2 = 1u, ///< PCLK0/2
AdtClkPClk0Div4 = 2u, ///< PCLK0/4
AdtClkPClk0Div8 = 3u, ///< PCLK0/8
AdtClkPClk0Div16 = 4u, ///< PCLK0/16
AdtClkPClk0Div64 = 5u, ///< PCLK0/64
AdtClkPClk0Div256 = 6u, ///< PCLK0/256
AdtClkPClk0Div1024 = 7u, ///< PCLK0/1024
}en_adt_cnt_ckdiv_t;
/**
******************************************************************************
** \brief ADT计数模式
**
** \note
******************************************************************************/
typedef enum en_adt_cnt_mode
{
AdtSawtoothMode = 0u, ///< 锯齿波模式
AdtTriangleModeA = 4u, ///< 三角波A模式
AdtTriangleModeB = 5u, ///< 三角波B模式
}en_adt_cnt_mode_t;
/**
******************************************************************************
** \brief ADT计数方向
**
** \note
******************************************************************************/
typedef enum en_adt_cnt_dir
{
AdtCntDown = 0u, ///< 递减计数
AdtCntUp = 1u, ///< 递加计数
}en_adt_cnt_dir_t;
/**
******************************************************************************
** \brief ADT通用比较基准
**
** \note
******************************************************************************/
typedef enum en_adt_compare
{
AdtCompareA = 0u, ///< 通用比较基准A
AdtCompareB = 1u, ///< 通用比较基准B
AdtCompareC = 2u, ///< 通用比较基准C
AdtCompareD = 3u, ///< 通用比较基准D
}en_adt_compare_t;
/**
******************************************************************************
** \brief ADT专用比较基准
**
** \note
******************************************************************************/
typedef enum en_adt_special_compare
{
AdtSpclCompA = 0u, ///< 专用比较基准A
AdtSpclCompB = 1u, ///< 专用比较基准B
}en_adt_special_compare_t;
/**
******************************************************************************
** \brief ADT端口控制 - TIMx输出状态控制
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_disval
{
AdtTIMxDisValNorm = 0u, ///< 强制输出无效条件0~3中被选择的条件成立时CHx端口正常输出
AdtTIMxDisValHiZ = 1u, ///< 强制输出无效条件0~3中被选择的条件成立时CHx端口输出高阻态
AdtTIMxDisValLow = 2u, ///< 强制输出无效条件0~3中被选择的条件成立时CHx端口输出低电平
AdtTIMxDisValHigh = 3u, ///< 强制输出无效条件0~3中被选择的条件成立时CHx端口输出高电平
}en_adt_pconr_disval_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx强制输出无效条件选择
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_dissel
{
AdtCHxDisSel0 = 0u, ///< 选择强制输出无效条件0
AdtCHxDisSel1 = 1u, ///< 选择强制输出无效条件1
AdtCHxDisSel2 = 2u, ///< 选择强制输出无效条件2
AdtCHxDisSel3 = 3u, ///< 选择强制输出无效条件3
}en_adt_pconr_dissel_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx周期值匹配时端口状态设定
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_perc
{
AdtCHxPeriodLow = 0u, ///< 计数器计数值与周期值相等时CHx端口输出保持为低电平
AdtCHxPeriodHigh = 1u, ///< 计数器计数值与周期值相等时CHx端口输出设定为高电平
AdtCHxPeriodKeep = 2u, ///< 计数器计数值与周期值相等时CHx端口输出设定为先前状态
AdtCHxPeriodInv = 3u, ///< 计数器计数值与周期值相等时CHx端口输出设定为反转电平
}en_adt_pconr_perc_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx比较值匹配时端口状态设定
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_cmpc
{
AdtCHxCompareLow = 0u, ///< 计数器计数值与GCMxR相等时CHx端口输出保持为低电平
AdtCHxCompareHigh = 1u, ///< 计数器计数值与GCMxR相等时CHx端口输出设定为高电平
AdtCHxCompareKeep = 2u, ///< 计数器计数值与GCMxR相等时CHx端口输出设定为先前状态
AdtCHxCompareInv = 3u, ///< 计数器计数值与GCMxR相等时CHx端口输出设定为反转电平
}en_adt_pconr_cmpc_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx端口输出
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_port_out
{
AdtCHxPortOutLow = 0u, ///< CHx端口输出设定为低电平
AdtCHxPortOutHigh = 1u, ///< CHx端口输出设定为高电平
}en_adt_pconr_port_out_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx端口功能模式选择
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_capc
{
AdtCHxCompareOutput = 0u, ///< CHx端口设定为比较输出功能
AdtCHxCompareInput = 1u, ///< CHx端口设定为捕获输入功能
}en_adt_pconr_capc_t;
/**
******************************************************************************
** \brief ADT端口控制 - CHx计数开始停止端口状态选择
**
** \note
******************************************************************************/
typedef enum en_adt_pconr_stastps
{
AdtCHxStateSelSS = 0u, ///< 计数开始或停止时CHx端口输出由STACB、STPCB决定
AdtCHxStateSelKeep = 1u, ///< 计数开始或停止时CHx端口输出设定为先前状态
}en_adt_pconr_stastps_t;
/**
******************************************************************************
** \brief ADT死区控制 - CHx死区分离设定
**
** \note
******************************************************************************/
typedef enum en_adt_dconr_sepa
{
AdtCHxDtSeperate = 0u, ///< DTUAR和DTDAR分别设定
AdtCHxDtEqual = 1u, ///< DTDAR的值和DTUAR的值自动相等
}en_adt_dconr_sepa_t;
/**
******************************************************************************
** \brief ADT滤波控制 - TRIx/TIMxIx端口滤波采样基准时钟选择
**
** \note
******************************************************************************/
typedef enum en_adt_fconr_nofick
{
AdtFltClkPclk0 = 0u, ///< PCLK0
AdtFltClkPclk0Div4 = 1u, ///< PCLK0/4
AdtFltClkPclk0Div16 = 2u, ///< PCLK0/16
AdtFltClkPclk0Div64 = 3u, ///< PCLK0/64
}en_adt_fconr_nofick_t;
/**
******************************************************************************
** \brief ADT有效周期 - TIMx有效周期选择
**
** \note
******************************************************************************/
typedef enum en_adt_vperr_pcnts
{
AdtPeriodCnts0 = 0u, ///< 有效周期选择功能无效
AdtPeriodCnts1 = 1u, ///< 每隔1个周期有效一次
AdtPeriodCnts2 = 2u, ///< 每隔2个周期有效一次
AdtPeriodCnts3 = 3u, ///< 每隔3个周期有效一次
AdtPeriodCnts4 = 4u, ///< 每隔4个周期有效一次
AdtPeriodCnts5 = 5u, ///< 每隔5个周期有效一次
AdtPeriodCnts6 = 6u, ///< 每隔6个周期有效一次
AdtPeriodCnts7 = 7u, ///< 每隔7个周期有效一次
}en_adt_vperr_pcnts_t;
/**
******************************************************************************
** \brief ADT有效周期 -
**
** \note
******************************************************************************/
typedef enum en_adt_vperr_pcnte
{
AdtPeriodCnteDisable = 0u, ///< 有效周期选择功能无效
AdtPeriodCnteMin = 1u, ///< 锯齿波计数上、下溢点或三角波波谷做为计数条件
AdtPeriodCnteMax = 2u, ///< 锯齿波计数上、下溢点或三角波波峰做为计数条件
AdtPeriodCnteBoth = 3u, ///< 锯齿波计数上、下溢点或三角波波峰,波谷做为计数条件
}en_adt_vperr_pcnte_t;
/**
******************************************************************************
** \brief ADT端口触发控制 -
**
** \note
******************************************************************************/
typedef enum en_adt_ttrig_trigxs
{
AdtTrigxSelPA3 = 0u, ///< PA3
AdtTrigxSelPB3 = 1u, ///< PB3
AdtTrigxSelPC3 = 2u, ///< PC3
AdtTrigxSelPD3 = 3u, ///< PD3
AdtTrigxSelPA7 = 4u, ///< PA7
AdtTrigxSelPB7 = 5u, ///< PB7
AdtTrigxSelPC7 = 6u, ///< PC7
AdtTrigxSelPD7 = 7u, ///< PD7
AdtTrigxSelPA11 = 8u, ///< PA11
AdtTrigxSelPB11 = 9u, ///< PB11
AdtTrigxSelPC11 = 10u, ///< PC11
AdtTrigxSelPD1 = 11u, ///< PD1
AdtTrigxSelPA15 = 12u, ///< PA15
AdtTrigxSelPB15 = 13u, ///< PB15
AdtTrigxSelPC5 = 14u, ///< PC5
AdtTrigxSelPD5 = 15u, ///< PD5
}en_adt_ttrig_trigxs_t;
/**
******************************************************************************
** \brief ADT AOS触发控制 - AOSx触发源选择
**
** \note
******************************************************************************/
typedef enum en_adt_itrig_iaosxs
{
AdtAosxTrigSelTim0Int = 0u, ///< TIM0_INT
AdtAosxTrigSelTim1Int = 1u, ///< TIM1_INT
AdtAosxTrigSelTim2Int = 2u, ///< TIM2_INT
AdtAosxTrigSelLpTimInt = 3u, ///< LPTIMER_INT
AdtAosxTrigSelTim4Int = 4u, ///< TIM4_INT
AdtAosxTrigSelTim5Int = 5u, ///< TIM5_INT
AdtAosxTrigSelTim6Int = 6u, ///< TIM6_INT
AdtAosxTrigSelUart0Int = 7u, ///< UART0_INT
AdtAosxTrigSelUart1Int = 8u, ///< UART1_INT
AdtAosxTrigSelLpUartInt = 9u, ///< LPUART_INT
AdtAosxTrigSelVc0Int = 10u, ///< VC0_INT
AdtAosxTrigSelVc1Int = 11u, ///< VC1_INT
AdtAosxTrigSelRtcInt = 12u, ///< RTC_INT
AdtAosxTrigSelPcaInt = 13u, ///< PCA_INT
AdtAosxTrigSelSpiInt = 14u, ///< SPI_INT
AdtAosxTrigSelAdcInt = 15u, ///< ADC_INT
}en_adt_itrig_iaosxs_t;
/**
******************************************************************************
** \brief ADT硬件(///)
**
** \note
******************************************************************************/
typedef enum en_adt_hw_trig
{
AdtHwTrigAos0 = 0u, ///< 从AOS来的事件触发0有效
AdtHwTrigAos1 = 1u, ///< 从AOS来的事件触发1有效
AdtHwTrigAos2 = 2u, ///< 从AOS来的事件触发2有效
AdtHwTrigAos3 = 3u, ///< 从AOS来的事件触发3有效
AdtHwTrigCHxARise = 4u, ///< CHxA端口上采样到上升沿
AdtHwTrigCHxAFall = 5u, ///< CHxA端口上采样到下降沿
AdtHwTrigCHxBRise = 6u, ///< CHxB端口上采样到上升沿
AdtHwTrigCHxBFall = 7u, ///< CHxB端口上采样到下降沿
AdtHwTrigTimTriARise = 8u, ///< TIMTRIA端口上采样到上升沿
AdtHwTrigTimTriAFall = 9u, ///< TIMTRIA端口上采样到下降沿
AdtHwTrigTimTriBRise = 10u, ///< TIMTRIB端口上采样到上升沿
AdtHwTrigTimTriBFall = 11u, ///< TIMTRIB端口上采样到下降沿
AdtHwTrigTimTriCRise = 12u, ///< TIMTRIC端口上采样到上升沿
AdtHwTrigTimTriCFall = 13u, ///< TIMTRIC端口上采样到下降沿
AdtHwTrigTimTriDRise = 14u, ///< TIMTRID端口上采样到上升沿
AdtHwTrigTimTriDFall = 15u, ///< TIMTRID端口上采样到下降沿
AdtHwTrigEnd = 16u,
}en_adt_hw_trig_t;
/**
******************************************************************************
** \brief ADT硬件(/)
**
** \note
******************************************************************************/
typedef enum en_adt_hw_cnt
{
AdtHwCntCHxALowCHxBRise = 0u, ///< CHxA端口为低电平时CHxB端口上采样到上升沿
AdtHwCntCHxALowCHxBFall = 1u, ///< CHxA端口为低电平时CHxB端口上采样到下降沿
AdtHwCntCHxAHighCHxBRise = 2u, ///< CHxA端口为高电平时CHxB端口上采样到上升沿
AdtHwCntCHxAHighCHxBFall = 3u, ///< CHxA端口为高电平时CHxB端口上采样到下降沿
AdtHwCntCHxBLowCHxARise = 4u, ///< CHxB端口为低电平时CHxA端口上采样到上升沿
AdtHwCntCHxBLowCHxAFall = 5u, ///< CHxB端口为低电平时CHxA端口上采样到下降沿
AdtHwCntCHxBHighChxARise = 6u, ///< CHxB端口为高电平时CHxA端口上采样到上升沿
AdtHwCntCHxBHighCHxAFall = 7u, ///< CHxB端口为高电平时CHxA端口上采样到下降沿
AdtHwCntTimTriARise = 8u, ///< TIMTRIA端口上采样到上升沿
AdtHwCntTimTriAFall = 9u, ///< TIMTRIA端口上采样到下降沿
AdtHwCntTimTriBRise = 10u, ///< TIMTRIB端口上采样到上升沿
AdtHwCntTimTriBFall = 11u, ///< TIMTRIB端口上采样到下降沿
AdtHwCntTimTriCRise = 12u, ///< TIMTRIC端口上采样到上升沿
AdtHwCntTimTriCFall = 13u, ///< TIMTRIC端口上采样到下降沿
AdtHwCntTimTriDRise = 14u, ///< TIMTRID端口上采样到上升沿
AdtHwCntTimTriDFall = 15u, ///< TIMTRID端口上采样到下降沿
AdtHwCntAos0 = 16u, ///< 从AOS来的事件触发0有效
AdtHwCntAos1 = 17u, ///< 从AOS来的事件触发1有效
AdtHwCntAos2 = 18u, ///< 从AOS来的事件触发2有效
AdtHwCntAos3 = 19u, ///< 从AOS来的事件触发3有效
AdtHwCntMax = 20u,
}en_adt_hw_cnt_t;
/**
******************************************************************************
** \brief ADT端口刹车极性控制
**
** \note
******************************************************************************/
typedef enum en_adt_ptbrk_polarity
{
AdtPtBrkHigh = 0u, ///< 端口刹车极性高电平有效
AdtPtBrkLow = 1u, ///< 端口刹车极性低电平有效
}en_adt_ptbrk_polarity_t;
/**
******************************************************************************
** \brief ADT PWM展频计数选择
**
** \note
******************************************************************************/
typedef enum en_adt_pwm_dither_type
{
AdtPwmDitherUnderFlow = 0u, ///< PWM展频计数下溢出
AdtPwmDitherOverFlow = 1u, ///< PWM展频计数上溢出
}en_adt_pwm_dither_type_t;
/**
******************************************************************************
** \brief ADT中断类型
**
** \note
******************************************************************************/
typedef enum en_adt_irq_type
{
AdtCMAIrq = 0u, ///< 计数匹配A或捕获输入中断
AdtCMBIrq = 1u, ///< 计数匹配B或捕获输入中断
AdtCMCIrq = 2u, ///< 计数匹配C中断
AdtCMDIrq = 3u, ///< 计数匹配D中断
AdtOVFIrq = 6u, ///< 上溢匹配中断
AdtUDFIrq = 7u, ///< 下溢匹配中断
AdtDTEIrq = 8u, ///< 死区时间错误中断
AdtSAMLIrq = 14u, ///< 同低中断
AdtSAMHIrq = 15u, ///< 同高中断
}en_adt_irq_type_t;
/**
******************************************************************************
** \brief ADT软件同步配置
** \note
******************************************************************************/
typedef struct stc_adt_sw_sync
{
boolean_t bAdTim4; ///< Timer 4
boolean_t bAdTim5; ///< Timer 5
boolean_t bAdTim6; ///< Timer 6
}stc_adt_sw_sync_t;
/**
******************************************************************************
** \brief ADT AOS触发配置
** \note
******************************************************************************/
typedef struct stc_adt_aos_trig_cfg
{
en_adt_itrig_iaosxs_t enAos0TrigSrc; ///< AOS0触发源选择
en_adt_itrig_iaosxs_t enAos1TrigSrc; ///< AOS1触发源选择
en_adt_itrig_iaosxs_t enAos2TrigSrc; ///< AOS2触发源选择
en_adt_itrig_iaosxs_t enAos3TrigSrc; ///< AOS3触发源选择
}stc_adt_aos_trig_cfg_t;
/**
******************************************************************************
** \brief ADT
** \note
******************************************************************************/
typedef struct stc_adt_irq_trig_cfg
{
boolean_t bAdtSpecilMatchBTrigDmaEn; ///< 专用比较基准值匹配B使能触发DMA
boolean_t bAdtSpecilMatchATrigDmaEn; ///< 专用比较基准值匹配A使能触发DMA
boolean_t bAdtUnderFlowTrigDmaEn; ///< 下溢匹配使能触发DMA
boolean_t bAdtOverFlowTrigDmaEn; ///< 上溢匹配使能触发DMA
boolean_t bAdtCntMatchDTrigDmaEn; ///< 计数匹配D使能触发DMA
boolean_t bAdtCntMatchCTrigDmaEn; ///< 计数匹配C使能触发DMA
boolean_t bAdtCntMatchBTrigDmaEn; ///< 计数匹配B使能触发DMA
boolean_t bAdtCntMatchATrigDmaEn; ///< 计数匹配A使能触发DMA
boolean_t bAdtSpecilMatchBTrigEn; ///< 专用比较基准值匹配B使能触发ADC
boolean_t bAdtSpecilMatchATrigEn; ///< 专用比较基准值匹配A使能触发ADC
boolean_t bAdtUnderFlowTrigEn; ///< 下溢匹配使能触发ADC
boolean_t bAdtOverFlowTrigEn; ///< 上溢匹配使能触发ADC
boolean_t bAdtCntMatchDTrigEn; ///< 计数匹配D使能触发ADC
boolean_t bAdtCntMatchCTrigEn; ///< 计数匹配C使能触发ADC
boolean_t bAdtCntMatchBTrigEn; ///< 计数匹配B使能触发ADC
boolean_t bAdtCntMatchATrigEn; ///< 计数匹配A使能触发ADC
}stc_adt_irq_trig_cfg_t;
/**
******************************************************************************
** \brief ADT Trig端口配置
** \note
******************************************************************************/
typedef struct stc_adt_port_trig_cfg
{
en_adt_ttrig_trigxs_t enTrigSrc; ///< 触发源选择
boolean_t bFltEn; ///< 触发源捕获输入滤波使能
en_adt_fconr_nofick_t enFltClk; ///< 滤波采样基准时钟
}stc_adt_port_trig_cfg_t;
/**
******************************************************************************
** \brief ADT Z相输入屏蔽功能配置
** \note
******************************************************************************/
typedef struct stc_adt_zmask_cfg
{
en_adt_gconr_zmsk_t enZMaskCycle; ///< Z相输入屏蔽计数周期选择
boolean_t bFltPosCntMaksEn; ///< Z相输入时的屏蔽周期内位置计数器的清零功能不屏蔽FALSE或屏蔽(TRUE)
boolean_t bFltRevCntMaksEn; ///< Z相输入时的屏蔽周期内公转计数器的计数功能不屏蔽FALSE或屏蔽(TRUE)
}stc_adt_zmask_cfg_t;
/**
******************************************************************************
** \brief ADT TIMxX端口配置
** \note
******************************************************************************/
typedef struct stc_adt_TIMxX_port_cfg
{
en_adt_pconr_capc_t enCap; ///< 端口功能模式
boolean_t bOutEn; ///< 输出使能
en_adt_pconr_perc_t enPerc; ///< 周期值匹配时端口状态
en_adt_pconr_cmpc_t enCmpc; ///< 比较值匹配时端口状态
en_adt_pconr_stastps_t enStaStp; ///< 计数开始停止端口状态选择
en_adt_pconr_port_out_t enStaOut; ///< 计数开始端口输出状态
en_adt_pconr_port_out_t enStpOut; ///< 计数停止端口输出状态
en_adt_pconr_disval_t enDisVal; ///< 强制输出无效时输出状态控制
en_adt_pconr_dissel_t enDisSel; ///< 强制输出无效条件选择
boolean_t bFltEn; ///< 端口捕获输入滤波使能
en_adt_fconr_nofick_t enFltClk; ///< 端口滤波采样基准时钟
}stc_adt_CHxX_port_cfg_t;
/**
******************************************************************************
** \brief ADT刹车端口配置
** \note
******************************************************************************/
typedef struct stc_adt_break_port_cfg
{
boolean_t bPortEn; ///< 端口使能
en_adt_ptbrk_polarity_t enPol; ///< 极性选择
}stc_adt_break_port_cfg_t;
/**
******************************************************************************
** \brief ADT无效条件3配置
** \note
******************************************************************************/
typedef struct stc_adt_disable_3_cfg
{
stc_adt_break_port_cfg_t stcBrkPtCfg[16]; ///< 刹车端口配置
boolean_t bFltEn; ///< 刹车端口滤波使能
en_adt_fconr_nofick_t enFltClk; ///< 滤波采样基准时钟
boolean_t bSwBrk; ///< 软件刹车
}stc_adt_disable_3_cfg_t;
/**
******************************************************************************
** \brief ADT无效条件1配置
** \note
******************************************************************************/
typedef struct stc_adt_disable_1_cfg
{
boolean_t bTim6OutSH; ///< TIM6输出同高
boolean_t bTim5OutSH; ///< TIM5输出同高
boolean_t bTim4OutSH; ///< TIM4输出同高
boolean_t bTim6OutSL; ///< TIM6输出同低
boolean_t bTim5OutSL; ///< TIM5输出同低
boolean_t bTim4OutSL; ///< TIM4输出同低
}stc_adt_disable_1_cfg_t;
/**
******************************************************************************
** \brief ADT PWM展频计数配置
** \note
******************************************************************************/
typedef struct stc_adt_pwm_dither_cfg
{
en_adt_pwm_dither_type_t enAdtPDType; ///< PWM展频计数选择
boolean_t bTimxBPDEn; ///< PWM通道B展频使能
boolean_t bTimxAPDEn; ///< PWM通道A展频使能
}stc_adt_pwm_dither_cfg_t;
/**
******************************************************************************
** \brief ADT基本计数配置
** \note
******************************************************************************/
typedef struct stc_adt_basecnt_cfg
{
en_adt_cnt_mode_t enCntMode; ///< 计数模式
en_adt_cnt_dir_t enCntDir; ///< 计数方向
en_adt_cnt_ckdiv_t enCntClkDiv; ///< 计数时钟选择
}stc_adt_basecnt_cfg_t;
/**
******************************************************************************
** \brief ADT计数状态
** \note
******************************************************************************/
typedef struct stc_adt_cntstate_cfg
{
uint16_t u16Counter; ///< 当前计数器的计数值
boolean_t enCntDir; ///< 计数方向
uint8_t u8ValidPeriod; ///< 有效周期计数
boolean_t bCMSBDF; ///< 向下计数专用比较基准值匹配B标志
boolean_t bCMSBUF; ///< 向上计数专用比较基准值匹配A标志
boolean_t bCMSADF; ///< 向下计数专用比较基准值匹配B标志
boolean_t bCMSAUF; ///< 向上计数专用比较基准值匹配A标志
boolean_t bDTEF; ///< 死区时间错误标志
boolean_t bUDFF; ///< 下溢匹配标志
boolean_t bOVFF; ///< 上溢匹配标志
boolean_t bCMDF; ///< 计数匹配D标志
boolean_t bCMCF; ///< 计数匹配C标志
boolean_t bCMBF; ///< 计数匹配B标志
boolean_t bCMAF; ///< 计数匹配A标志
}stc_adt_cntstate_cfg_t;
/**
******************************************************************************
** \brief ADT有效计数周期
** \note
******************************************************************************/
typedef struct stc_adt_validper_cfg
{
en_adt_vperr_pcnts_t enValidCnt; ///< 有效周期选择
en_adt_vperr_pcnte_t enValidCdt; ///< 有效周期计数条件
boolean_t bPeriodD; ///< 通用信号有效周期选择D
boolean_t bPeriodC; ///< 通用信号有效周期选择C
boolean_t bPeriodB; ///< 通用信号有效周期选择B
boolean_t bPeriodA; ///< 通用信号有效周期选择A
}stc_adt_validper_cfg_t;
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
en_result_t Adt_ConfigHwCntUp(en_adt_unit_t enAdtUnit, en_adt_hw_cnt_t enAdtHwCntUp);
en_result_t Adt_ClearHwCntUp(en_adt_unit_t enAdtUnit);
en_result_t Adt_ConfigHwCntDwn(en_adt_unit_t enAdtUnit, en_adt_hw_cnt_t enAdtHwCntDwn);
en_result_t Adt_ClearHwCntDwn(en_adt_unit_t enAdtUnit);
en_result_t Adt_ConfigHwStart(en_adt_unit_t enAdtUnit, en_adt_hw_trig_t enAdtHwStart);
en_result_t Adt_ClearHwStart(en_adt_unit_t enAdtUnit);
en_result_t Adt_EnableHwStart(en_adt_unit_t enAdtUnit);
en_result_t Adt_DisableHwStart(en_adt_unit_t enAdtUnit);
en_result_t Adt_ConfigHwStop(en_adt_unit_t enAdtUnit, en_adt_hw_trig_t enAdtHwStop);
en_result_t Adt_ClearHwStop(en_adt_unit_t enAdtUnit);
en_result_t Adt_EnableHwStop(en_adt_unit_t enAdtUnit);
en_result_t Adt_DisableHwStop(en_adt_unit_t enAdtUnit);
en_result_t Adt_ConfigHwClear(en_adt_unit_t enAdtUnit, en_adt_hw_trig_t enAdtHwClear);
en_result_t Adt_ClearHwClear(en_adt_unit_t enAdtUnit);
en_result_t Adt_EnableHwClear(en_adt_unit_t enAdtUnit);
en_result_t Adt_DisableHwClear(en_adt_unit_t enAdtUnit);
en_result_t Adt_ConfigHwCaptureA(en_adt_unit_t enAdtUnit, en_adt_hw_trig_t enAdtHwCaptureA);
en_result_t Adt_ClearHwCaptureA(en_adt_unit_t enAdtUnit);
en_result_t Adt_ConfigHwCaptureB(en_adt_unit_t enAdtUnit, en_adt_hw_trig_t enAdtHwCaptureB);
en_result_t Adt_ClearHwCaptureB(en_adt_unit_t enAdtUnit);
en_result_t Adt_SwSyncStart(stc_adt_sw_sync_t* pstcAdtSwSyncStart);
en_result_t Adt_SwSyncStop(stc_adt_sw_sync_t* pstcAdtSwSyncStop);
en_result_t Adt_SwSyncClear(stc_adt_sw_sync_t* pstcAdtSwSyncClear);
en_result_t Adt_GetSwSyncState(stc_adt_sw_sync_t* pstcAdtSwSyncState);
en_result_t Adt_AosTrigConfig(stc_adt_aos_trig_cfg_t* pstcAdtAosTrigCfg);
en_result_t Adt_IrqTrigConfig(en_adt_unit_t enAdtUnit,
stc_adt_irq_trig_cfg_t* pstcAdtIrqTrigCfg);
en_result_t Adt_PortTrigConfig(en_adt_trig_port_t enAdtTrigPort,
stc_adt_port_trig_cfg_t* pstcAdtPortTrigCfg);
en_result_t Adt_CHxXPortConfig(en_adt_unit_t enAdtUnit,
en_adt_CHxX_port_t enAdtCHxXPort,
stc_adt_CHxX_port_cfg_t* pstcAdtCHxXCfg);
en_result_t Adt_EnableBreakPort(uint8_t port, stc_adt_break_port_cfg_t* pstcAdtBrkPtCfg);
void Adt_ClearBrakePort(void);
en_result_t Adt_Disable3Cfg(stc_adt_disable_3_cfg_t* pstcAdtDisable3);
boolean_t Adt_GetPortBrakeFlag(void);
void Adt_ClearPortBrakeFlag(void);
en_result_t Adt_Disable1Cfg(stc_adt_disable_1_cfg_t* pstcAdtDisable1);
boolean_t Adt_GetSameBrakeFlag(void);
void Adt_ClearSameBrakeFlag(void);
en_result_t Adt_PwmDitherConfig(en_adt_unit_t enAdtUnit, stc_adt_pwm_dither_cfg_t* pstcAdtPwmDitherCfg);
en_result_t Adt_Init(en_adt_unit_t enAdtUnit, stc_adt_basecnt_cfg_t* pstcAdtBaseCntCfg);
en_result_t Adt_DeInit(en_adt_unit_t enAdtUnit);
en_result_t Adt_StartCount(en_adt_unit_t enAdtUnit);
en_result_t Adt_StopCount(en_adt_unit_t enAdtUnit);
en_result_t Adt_SetCount(en_adt_unit_t enAdtUnit, uint16_t u16Value);
uint16_t Adt_GetCount(en_adt_unit_t enAdtUnit);
en_result_t Adt_ClearCount(en_adt_unit_t enAdtUnit);
en_result_t Adt_GetCntState(en_adt_unit_t enAdtUnit, stc_adt_cntstate_cfg_t* pstcAdtCntState);
en_result_t Adt_SetPeriod(en_adt_unit_t enAdtUnit, uint16_t u16Period);
en_result_t Adt_SetPeriodBuf(en_adt_unit_t enAdtUnit, uint16_t u16PeriodBuf);
en_result_t Adt_ClearPeriodBuf(en_adt_unit_t enAdtUnit);
en_result_t Adt_SetValidPeriod(en_adt_unit_t enAdtUnit,
stc_adt_validper_cfg_t* pstcAdtValidPerCfg);
en_result_t Adt_SetCompareValue(en_adt_unit_t enAdtUnit,
en_adt_compare_t enAdtCompare,
uint16_t u16Compare);
en_result_t Adt_EnableValueBuf(en_adt_unit_t enAdtUnit,
en_adt_CHxX_port_t enAdtCHxXPort,
boolean_t bCompareBufEn);
en_result_t Adt_ClearValueBuf(en_adt_unit_t enAdtUnit,
en_adt_CHxX_port_t enAdtCHxXPort);
en_result_t Adt_GetCaptureValue(en_adt_unit_t enAdtUnit,
en_adt_CHxX_port_t enAdtCHxXPort,
uint16_t* pu16Capture);
en_result_t Adt_GetCaptureBuf(en_adt_unit_t enAdtUnit,
en_adt_CHxX_port_t enAdtCHxXPort,
uint16_t* pu16CaptureBuf);
en_result_t Adt_SetDTUA(en_adt_unit_t enAdtUnit,
uint16_t u16Value);
en_result_t Adt_SetDTDA(en_adt_unit_t enAdtUnit,
uint16_t u16Value);
en_result_t Adt_ConfigDT(en_adt_unit_t enAdtUnit,
boolean_t bDTEn,
boolean_t bEqual);
en_result_t Adt_ConfigIrq(en_adt_unit_t enAdtUnit,
en_adt_irq_type_t enAdtIrq,
boolean_t bEn,
func_ptr_t pfnIrqCalbak);
en_result_t Adt_GetIrqFlag(en_adt_unit_t enAdtUnit,
en_adt_irq_type_t enAdtIrq,
boolean_t* pbFlag);
en_result_t Adt_ClearIrqFlag(en_adt_unit_t enAdtUnit,
en_adt_irq_type_t enAdtIrq);
en_result_t Adt_ConfigZMask(en_adt_unit_t enAdtUnit,
stc_adt_zmask_cfg_t* pstcAdtZMaskCfg);
//@} // ADT Group
#ifdef __cplusplus
}
#endif
#endif /* __ADT_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,108 @@
/******************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file crc.h
**
** CRC API声明.
**
** - 2016-05-04 LuX V1.0.
**
******************************************************************************/
#ifndef __CRC_H__
#define __CRC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup CrcGroup Cyclic Redundancy Check (CRC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//AES 加密
en_result_t AES_Encrypt(uint32_t* pu32Data, uint32_t *pu32Key, uint32_t *pu32Cipher);
//AES 解密
en_result_t AES_Decrypt(uint32_t *pu32Cipher, uint32_t *pu32Key, uint32_t* pu32Plaintext);
//@} // CRC Group
#ifdef __cplusplus
}
#endif
#endif /* __CRC_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,109 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file bgr.h
**
** BGR API声明.
**
** - 2018-04-21 LuX V1.0.
**
******************************************************************************/
#ifndef __CRC_H__
#define __CRC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup BGR
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///<内部温度传感器使能/关闭
en_result_t Bgr_TempSensorEnable(void);
en_result_t Bgr_TempSensorDisable(void);
///<BGR使能/关闭
en_result_t Bgr_BgrEnable(void);
en_result_t Bgr_BgrDisable(void);
//@} // BGR Group
#ifdef __cplusplus
}
#endif
#endif /* __BGR_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,770 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file bt.h
**
** API声明
** @link BT Group Some description @endlink
**
** History:
** - 2018-04-18 Husj First Version
**
*****************************************************************************/
#ifndef __BT_H__
#define __BT_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup BtGroup Base Timer (BT)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief
*****************************************************************************/
typedef enum en_bt_unit
{
TIM0 = 0u, ///< Timer 0
TIM1 = 1u, ///< Timer 1
TIM2 = 2u, ///< Timer 2
}en_bt_unit_t;
/**
******************************************************************************
** \brief (MODE)(0/1/23)
*****************************************************************************/
typedef enum en_bt_work_mode
{
BtWorkMode0 = 0u, ///< 定时器模式
BtWorkMode1 = 1u, ///< PWC模式
BtWorkMode2 = 2u, ///< 锯齿波模式
BtWorkMode3 = 3u, ///< 三角波模式
}en_bt_work_mode_t;
/**
******************************************************************************
** \brief (GATE_P)(0)
*****************************************************************************/
typedef enum en_bt_m0_gatep
{
BtGatePositive = 0u, ///< 高电平有效
BtGateOpposite = 1u, ///< 低电平有效
}en_bt_m0_gatep_t;
/**
******************************************************************************
** \brief TIM (PRS)(0/1/23)
*****************************************************************************/
typedef enum en_bt_cr_timclkdiv
{
BtPCLKDiv1 = 0u, ///< Div 1
BtPCLKDiv2 = 1u, ///< Div 2
BtPCLKDiv4 = 2u, ///< Div 4
BtPCLKDiv8 = 3u, ///< Div 8
BtPCLKDiv16 = 4u, ///< Div 16
BtPCLKDiv32 = 5u, ///< Div 32
BtPCLKDiv64 = 6u, ///< Div 64
BtPCLKDiv256 = 7u, ///< Div 256
}en_bt_cr_timclkdiv_t;
/**
******************************************************************************
** \brief / (CT)(0/1/23)
*****************************************************************************/
typedef enum en_bt_cr_ct
{
BtTimer = 0u, ///< 定时器功能计数时钟为内部PCLK
BtCounter = 1u, ///< 计数器功能计数时钟为外部ETR
}en_bt_cr_ct_t;
/**
******************************************************************************
** \brief (MD)(0)
*****************************************************************************/
typedef enum en_bt_m0cr_md
{
Bt32bitFreeMode = 0u, ///< 32位计数器/定时器
Bt16bitArrMode = 1u, ///< 自动重载16位计数器/定时器
}en_bt_m0cr_md_t;
/**
******************************************************************************
** \brief BT0/BT1/BT2中断类型数据类型重定义(0/1/23)
*****************************************************************************/
typedef enum en_bt_irq_type
{
BtUevIrq = 0u, ///< 溢出/事件更新中断
BtCA0Irq = 2u, ///< 捕获/比较中断A(仅模式1/23存在)
BtCB0Irq = 5u, ///< 捕获/比较中断B(仅模式23存在)
BtCA0E = 8u, ///< CH0A捕获数据丢失标志(仅模式23存在),不是中断
BtCB0E = 11u, ///< CH0B捕获数据丢失标志(仅模式23存在),不是中断
BtBkIrq = 14u, ///< 刹车中断(仅模式23存在)
BtTrigIrq = 15u, ///< 触发中断(仅模式23存在)
}en_bt_irq_type_t;
/**
******************************************************************************
** \brief (Edg1stEdg2nd)(1)
*****************************************************************************/
typedef enum en_bt_m1cr_Edge
{
BtPwcRiseToRise = 0u, ///< 上升沿到上升沿(周期)
BtPwcFallToRise = 1u, ///< 下降沿到上升沿(低电平)
BtPwcRiseToFall = 2u, ///< 上升沿到下降沿(高电平)
BtPwcFallToFall = 3u, ///< 下降沿到下降沿(周期)
}en_bt_m1cr_Edge_t;
/**
******************************************************************************
** \brief PWC测量测试模式选择数据类型重定义 (Oneshot)(1)
*****************************************************************************/
typedef enum en_bt_m1cr_oneshot
{
BtPwcCycleDetect = 0u, ///< PWC循环测量
BtPwcOneShotDetect = 1u, ///< PWC单次测量
}en_bt_m1cr_oneshot_t;
/**
******************************************************************************
** \brief PWC IA0选择数据类型重定义 (IA0S)(1)
*****************************************************************************/
typedef enum en_bt_m1_mscr_ia0s
{
BtIA0Input = 0u, ///< IAO输入
BtXORInput = 1u, ///< IA0 ETR GATE XOR(TIM0/1/2)/IA0 IA1 IA2 XOR(TIM3)
}en_bt_m1_mscr_ia0s_t;
/**
******************************************************************************
** \brief PWC IB0选择数据类型重定义 (IA0S)(1)
*****************************************************************************/
typedef enum en_bt_m1_mscr_ib0s
{
BtIB0Input = 0u, ///< IBO输入
BtTsInput = 1u, ///< 内部触发TS选择信号
}en_bt_m1_mscr_ib0s_t;
/**
******************************************************************************
** \brief (CCPA0/CCPB0/ETP/BKP)(1/23)
*****************************************************************************/
typedef enum en_bt_port_polarity
{
BtPortPositive = 0u, ///< 正常输入输出
BtPortOpposite = 1u, ///< 反向输入输出
}en_bt_port_polarity_t;
/**
******************************************************************************
** \brief (FLTET/FLTA0/FLAB0)(1/23)
*****************************************************************************/
typedef enum en_bt_flt
{
BtFltNone = 0u, ///< 无滤波
BtFltPCLKCnt3 = 4u, ///< PCLK 3个连续有效
BtFltPCLKDiv4Cnt3 = 5u, ///< PCLK/4 3个连续有效
BtFltPCLKDiv16Cnt3 = 6u, ///< PCLK/16 3个连续有效
BtFltPCLKDiv64Cnt3 = 7u, ///< PCLK/64 3个连续有效
}en_bt_flt_t;
/**
******************************************************************************
** \brief (OCMA/OCMB)(23)
*****************************************************************************/
typedef enum en_bt_m23_fltr_ocm
{
BtForceLow = 0u, ///< 强制为0
BtForceHigh = 1u, ///< 强制为1
BtCMPForceLow = 2u, ///< 比较匹配时强制为0
BtCMPForceHigh = 3u, ///< 比较匹配时强制为1
BtCMPInverse = 4u, ///< 比较匹配时翻转电平
BtCMPOnePrdHigh = 5u, ///< 比较匹配时输出一个计数周期的高电平
BtPWMMode1 = 6u, ///< 通道控制为PWM mode 1
BtPWMMode2 = 7u, ///< 通道控制为PWM mode 2
}en_bt_m23_fltr_ocm_t;
/**
******************************************************************************
** \brief TS数据类型重定义 (TS)(1/23)
*****************************************************************************/
typedef enum en_bt_mscr_ts
{
BtTs0ETR = 0u, ///< ETR外部输入滤波后的相位选择信号
BtTs1TIM0TRGO = 1u, ///< Timer0的TRGO输出信号
BtTs2TIM1TRGO = 2u, ///< Timer1的TRGO输出信号
BtTs3TIM2TRGO = 3u, ///< Timer2的TRGO输出信号
BtTs4TIM3TRGO = 4u, ///< Timer3的TRGO输出信号
//BtTs5IA0ED = 5u, ///< 无效
BtTs6IAFP = 6u, ///< CH0A 外部输输入滤波后的相位选择信号
BtTs7IBFP = 7u, ///< CH0B 外部输输入滤波后的相位选择信
}en_bt_mscr_ts_t;
/**
******************************************************************************
** \brief PWM输出模式选择数据类型重定义 (COMP)(23)
*****************************************************************************/
typedef enum en_bt_m23cr_comp
{
BtIndependentPWM = 0u, ///< 独立PWM输出
BtComplementaryPWM = 1u, ///< 互补PWM输出
}en_bt_m23cr_comp_t;
/**
******************************************************************************
** \brief (DIR)(23)
*****************************************************************************/
typedef enum en_bt_m23cr_dir
{
BtCntUp = 0u, ///< 向上计数
BtCntDown = 1u, ///< 向下计数
}en_bt_m23cr_dir_t;
/**
******************************************************************************
** \brief (PWM2S)(23)
*****************************************************************************/
typedef enum en_bt_m23cr_pwm2s
{
BtDoublePointCmp = 0u, ///< 双点比较使能使用CCRA,CCRB比较控制OCREFA输出
BtSinglePointCmp = 1u, ///< 单点比较使能使用CCRA比较控制OCREFA输出
}en_bt_m23cr_pwm2s_t;
/**
******************************************************************************
** \brief GATE在PWM互补模式下捕获或比较功能 (CSG)(23)
*****************************************************************************/
typedef enum en_bt_m23cr_csg
{
BtPWMCompGateCmpOut = 0u, ///< 在PWM互补模式下Gate作为比较输出
BtPWMCompGateCapIn = 1u, ///< 在PWM互补模式下Gate作为捕获输入
}en_bt_m23cr_csg_t;
/**
******************************************************************************
** \brief (CCR0A,CCR0B)(23)
*****************************************************************************/
typedef enum en_bt_m23_ccrx
{
BtCCR0A = 0u, ///< CCR0A比较捕获寄存器
BtCCR0B = 1u, ///< CCR0B比较捕获寄存器
}en_bt_m23_ccrx_t;
/**
******************************************************************************
** \brief OCREF清除源 (OCCS)(23)
*****************************************************************************/
typedef enum en_bt_m23ce_occs
{
BtOC_Ref_Clr = 0u, ///< 来自VC的OC_Ref_Clr
BtETRf = 1u, ///< 外部ETRf
}en_bt_m23ce_occs_t;
/**
******************************************************************************
** \brief (CIS/CISB)(23)
*****************************************************************************/
typedef enum en_bt_m23_cisa_cisb
{
BtCmpIntNone = 0u, ///< 无比较匹配中断
BtCmpIntRise = 1u, ///< 比较匹配上升沿中断
BtCmpIntFall = 2u, ///< 比较匹配下降沿中断
BtCmpIntRiseFall = 3u, ///< 比较匹配上升沿下降沿中断
}en_bt_m23_cisa_cisb_t;
/**
******************************************************************************
** \brief BT端口控制 - CHx输出状态控制(BKSA/BKSB)(23)
**
** \note
******************************************************************************/
typedef enum en_bt_m23_crch0_bks
{
BtCHxBksHiZ = 0u, ///< 刹车使能时CHx端口输出高阻态
BtCHxBksNorm = 1u, ///< 刹车使能时CHx端口正常输出
BtCHxBksLow = 2u, ///< 刹车使能时CHx端口输出低电平
BtCHxBksHigh = 3u, ///< 刹车使能时CHx端口输出高电平
}en_bt_m23_crch0_bks_t;
/**
******************************************************************************
** \brief BT端口控制 - CHx上升沿下降沿捕获(CRx/CFx)(23)
**
** \note
******************************************************************************/
typedef enum en_bt_m23_crch0_cfx_crx
{
BtCHxCapNone = 0u, ///< CHx通道捕获禁止
BtCHxCapRise = 1u, ///< CHx通道上升沿捕获使能
BtCHxCapFall = 2u, ///< CHx通道下降沿捕获使能
BtCHxCapFallRise = 3u, ///< CHx通道上升沿下降沿捕获都使能
}en_bt_m23_crch0_cfx_crx_t;
/**
******************************************************************************
** \brief BT端口控制 - CHx比较捕获模式(CSA/CSB)(23)
**
** \note
******************************************************************************/
typedef enum en_bt_m23_crch0_csa_csb
{
BtCHxCmpMode = 0u, ///< CHx通道设置为比较模式
BtCHxCapMode = 1u, ///< CHx通道设置为捕获模式
}en_bt_m23_crch0_csa_csb_t;
/**
******************************************************************************
** \brief DMA比较触发选择 (CCDS)(23)
*****************************************************************************/
typedef enum en_bt_m23_mscr_ccds
{
BtCmpTrigDMA = 0u, ///< 比较匹配触发DMA
BtUEVTrigDMA = 1u, ///< 事件更新代替比较匹配触发DMA
}en_bt_m23_mscr_ccds_t;
/**
******************************************************************************
** \brief (MSM)(23)
*****************************************************************************/
typedef enum en_bt_m23_mscr_msm
{
BtSlaveMode = 0u, ///< 从模式
BtMasterMode = 1u, ///< 主模式
}en_bt_m23_mscr_msm_t;
/**
******************************************************************************
** \brief (MMS)(23)
*****************************************************************************/
typedef enum en_bt_m23_mscr_mms
{
BtMasterUG = 0u, ///< UG(软件更新)源
BtMasterCTEN = 1u, ///< CTEN源
BtMasterUEV = 2u, ///< UEV更新源
BtMasterCMPSO = 3u, ///< 比较匹配选择输出源
BtMasterOCA0Ref = 4u, ///< OCA0_Ref源
BtMasterOCB0Ref = 5u, ///< OCB0_Ref源
//BtMasterOCB0Ref = 6u,
//BtMasterOCB0Ref = 7u,
}en_bt_m23_mscr_mms_t;
/**
******************************************************************************
** \brief (SMS)(23)
*****************************************************************************/
typedef enum en_bt_m23_mscr_sms
{
BtSlaveIClk = 0u, ///< 使用内部时钟
BtSlaveResetTIM = 1u, ///< 复位功能
BtSlaveTrigMode = 2u, ///< 触发模式
BtSlaveEClk = 3u, ///< 外部时钟模式
BtSlaveCodeCnt1 = 4u, ///< 正交编码计数模式1
BtSlaveCodeCnt2 = 5u, ///< 正交编码计数模式2
BtSlaveCodeCnt3 = 6u, ///< 正交编码计数模式3
BtSlaveGateCtrl = 7u, ///< 门控功能
}en_bt_m23_mscr_sms_t;
/**
******************************************************************************
** \brief (CTEN)
*****************************************************************************/
typedef enum en_bt_start
{
BtCTENDisable = 0u, ///< 停止
BtCTENEnable = 1u, ///< 运行
}en_bt_start_t;
/**
******************************************************************************
** \brief BaseTimer mode0 (0)
*****************************************************************************/
typedef struct stc_bt_mode0_config
{
en_bt_work_mode_t enWorkMode; ///< 工作模式设置
en_bt_m0_gatep_t enGateP; ///< 门控极性控制
boolean_t bEnGate; ///< 门控使能
en_bt_cr_timclkdiv_t enPRS; ///< 预除频配置
boolean_t bEnTog; ///< 翻转输出使能
en_bt_cr_ct_t enCT; ///< 定时/计数功能选择
en_bt_m0cr_md_t enCntMode; ///< 计数模式配置
func_ptr_t pfnTim0Cb; ///< Timer0中断服务回调函数[void function(void)]
func_ptr_t pfnTim1Cb; ///< Timer1中断服务回调函数[void function(void)]
func_ptr_t pfnTim2Cb; ///< Timer2中断服务回调函数[void function(void)]
}stc_bt_mode0_config_t;
/**
******************************************************************************
** \brief BaseTimer mode1 (1)
*****************************************************************************/
typedef struct stc_bt_mode1_config
{
en_bt_work_mode_t enWorkMode; ///< 工作模式设置
en_bt_cr_timclkdiv_t enPRS; ///< 预除频配置
en_bt_cr_ct_t enCT; ///< 定时/计数功能选择
en_bt_m1cr_oneshot_t enOneShot; ///< 单次测量/循环测量选择
func_ptr_t pfnTim0Cb; ///< Timer0中断服务回调函数[void function(void)]
func_ptr_t pfnTim1Cb; ///< Timer1中断服务回调函数[void function(void)]
func_ptr_t pfnTim2Cb; ///< Timer2中断服务回调函数[void function(void)]
}stc_bt_mode1_config_t;
/**
******************************************************************************
** \brief PWC输入配置结构体定义(1)
*****************************************************************************/
typedef struct stc_bt_pwc_input_config
{
en_bt_mscr_ts_t enTsSel; ///< 触发输入源选择
en_bt_m1_mscr_ia0s_t enIA0Sel; ///< CHA0输入选择
en_bt_m1_mscr_ib0s_t enIB0Sel; ///< CHB0输入选择
en_bt_port_polarity_t enETRPhase; ///< ETR相位选择
en_bt_flt_t enFltETR; ///< ETR滤波设置
en_bt_flt_t enFltIA0; ///< CHA0滤波设置
en_bt_flt_t enFltIB0; ///< CHB0滤波设置
}stc_bt_pwc_input_config_t;
/**
******************************************************************************
** \brief BaseTimer mode23 (23)
*****************************************************************************/
typedef struct stc_bt_mode23_config
{
en_bt_work_mode_t enWorkMode; ///< 工作模式设置
en_bt_m23cr_dir_t enCntDir; ///< 计数方向
en_bt_cr_timclkdiv_t enPRS; ///< 时钟预除频配置
en_bt_cr_ct_t enCT; ///< 定时/计数功能选择
en_bt_m23cr_comp_t enPWMTypeSel; ///< PWM模式选择独立/互补)
en_bt_m23cr_pwm2s_t enPWM2sSel; ///< OCREFA双点比较功能选择
boolean_t bOneShot; ///< 单次触发模式使能/禁止
boolean_t bURSSel; ///< 更新源选择
func_ptr_t pfnTim0Cb; ///< Timer0中断服务回调函数[void function(void)]
func_ptr_t pfnTim1Cb; ///< Timer1中断服务回调函数[void function(void)]
func_ptr_t pfnTim2Cb; ///< Timer2中断服务回调函数[void function(void)]
}stc_bt_mode23_config_t;
/**
******************************************************************************
** \brief GATE在PWM互补模式下捕获或比较功能 (23)
*****************************************************************************/
typedef struct stc_bt_m23_gate_config
{
en_bt_m23cr_csg_t enGateFuncSel; ///< Gate比较、捕获功能选择
boolean_t bGateRiseCap; ///< GATE作为捕获功能时上沿捕获有效控制
boolean_t bGateFallCap; ///< GATE作为捕获功能时下沿捕获有效控制
}stc_bt_m23_gate_config_t;
/**
******************************************************************************
** \brief CHA/CHB通道比较控制 (23)
*****************************************************************************/
typedef struct stc_bt_m23_compare_config
{
en_bt_m23_crch0_csa_csb_t enCh0ACmpCap; ///< CH0A比较/捕获功能选择
en_bt_m23_fltr_ocm_t enCH0ACmpCtrl; ///< CH0A通道比较控制
en_bt_port_polarity_t enCH0APolarity; ///< CH0A输出极性控制
boolean_t bCh0ACmpBufEn; ///< 比较A缓存功能 使能/禁止
en_bt_m23_cisa_cisb_t enCh0ACmpIntSel; ///< CHA比较匹配中断选择
en_bt_m23_crch0_csa_csb_t enCh0BCmpCap; ///< CH0B比较/捕获功能选择
en_bt_m23_fltr_ocm_t enCH0BCmpCtrl; ///< CH0B通道比较控制
en_bt_port_polarity_t enCH0BPolarity; ///< CH0B输出极性控制
boolean_t bCH0BCmpBufEn; ///< 比较B缓存功能 使能/禁止
en_bt_m23_cisa_cisb_t enCH0BCmpIntSel; ///< CHB0比较匹配中断选择
}stc_bt_m23_compare_config_t;
/**
******************************************************************************
** \brief CHA/CHB通道捕获控制 (23)
*****************************************************************************/
typedef struct stc_bt_m23_input_config
{
en_bt_m23_crch0_csa_csb_t enCh0ACmpCap; ///< CH0A比较/捕获功能选择
en_bt_m23_crch0_cfx_crx_t enCH0ACapSel; ///< CH0A捕获边沿选择
en_bt_flt_t enCH0AInFlt; ///< CH0A通道捕获滤波控制
en_bt_port_polarity_t enCH0APolarity; ///< CH0A输入相位
en_bt_m23_crch0_csa_csb_t enCh0BCmpCap; ///< CH0B比较/捕获功能选择
en_bt_m23_crch0_cfx_crx_t enCH0BCapSel; ///< HC0B捕获边沿选择
en_bt_flt_t enCH0BInFlt; ///< CH0B通道捕获滤波控制
en_bt_port_polarity_t enCH0BPolarity; ///< CH0B输入相位
}stc_bt_m23_input_config_t;
/**
******************************************************************************
** \brief ETR输入相位滤波配置结构体定义(23)
*****************************************************************************/
typedef struct stc_bt_m23_etr_input_config
{
en_bt_port_polarity_t enETRPolarity; ///< ETR输入极性设置
en_bt_flt_t enETRFlt; ///< ETR滤波设置
}stc_bt_m23_etr_input_config_t;
/**
******************************************************************************
** \brief BK输入相位滤波配置结构体定义(23)
*****************************************************************************/
typedef struct stc_bt_m23_bk_input_config
{
boolean_t bEnBrake; ///< 刹车使能
boolean_t bEnVC0Brake; ///< 使能VC0刹车
boolean_t bEnVC1Brake; ///< 使能VC1刹车
boolean_t bEnSafetyBk; ///< 使能safety刹车
boolean_t bEnBKSync; ///< TIM0/TIM1/TIM2刹车同步使能
en_bt_m23_crch0_bks_t enBkCH0AStat; ///< 刹车时CHA端口状态设置
en_bt_m23_crch0_bks_t enBkCH0BStat; ///< 刹车时CHB端口状态设置
en_bt_port_polarity_t enBrakePolarity; ///< 刹车BK输入极性设置
en_bt_flt_t enBrakeFlt; ///< 刹车BK滤波设置
}stc_bt_m23_bk_input_config_t;
/**
******************************************************************************
** \brief (23)
*****************************************************************************/
typedef struct stc_bt_m23_dt_config
{
boolean_t bEnDeadTime; ///< 刹车时CHA端口状态设置
uint8_t u8DeadTimeValue; ///< 刹车时CHA端口状态设置
}stc_bt_m23_dt_config_t;
/**
******************************************************************************
** \brief ADC配置结构体定义(23)
*****************************************************************************/
typedef struct stc_bt_m23_adc_trig_config
{
boolean_t bEnTrigADC; ///< 触发ADC全局控制
boolean_t bEnUevTrigADC; ///< 事件更新触发ADC
boolean_t bEnCH0ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH0BCmpTrigADC; ///< CH0B比较匹配触发ADC
}stc_bt_m23_adc_trig_config_t;
/**
******************************************************************************
** \brief DMA触发 (23)
*****************************************************************************/
typedef struct stc_bt_m23_trig_dma_config
{
boolean_t bUevTrigDMA; ///< 更新 触发DMA使能
boolean_t bTITrigDMA; ///< Trig 触发DMA功能
boolean_t bCmpATrigDMA; ///< A捕获比较触发DMA使能
boolean_t bCmpBTrigDMA; ///< B捕获比较触发DMA使能
en_bt_m23_mscr_ccds_t enCmpUevTrigDMA; ///< 比较模式下DMA比较触发选择
}stc_bt_m23_trig_dma_config_t;
/**
******************************************************************************
** \brief (23)
*****************************************************************************/
typedef struct stc_bt_m23_master_slave_config
{
en_bt_m23_mscr_msm_t enMasterSlaveSel; ///< 主从模式选择
en_bt_m23_mscr_mms_t enMasterSrc; ///< 主模式触发源选择
en_bt_m23_mscr_sms_t enSlaveModeSel; ///< 从模式选择
en_bt_mscr_ts_t enTsSel; ///< 触发输入源选择
}stc_bt_m23_master_slave_config_t;
/**
******************************************************************************
** \brief OCREF清除功能 (23)
*****************************************************************************/
typedef struct stc_bt_m23_OCREF_Clr_config
{
en_bt_m23ce_occs_t enOCRefClrSrcSel; ///< OCREF清除源选择
boolean_t bVCClrEn; ///< 是否使能来自VC的OCREF_Clr
}stc_bt_m23_OCREF_Clr_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//中断相关函数
//中断标志获取
boolean_t Bt_GetIntFlag(en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
//中断标志清除
en_result_t Bt_ClearIntFlag(en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
//所有中断标志清除
en_result_t Bt_ClearAllIntFlag(en_bt_unit_t enUnit);
//模式0中断使能
en_result_t Bt_Mode0_EnableIrq(en_bt_unit_t enUnit);
//模式1中断使能
en_result_t Bt_Mode1_EnableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
//模式2中断使能
en_result_t Bt_Mode23_EnableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
//模式0中断禁止
en_result_t Bt_Mode0_DisableIrq(en_bt_unit_t enUnit);
//模式1中断禁止
en_result_t Bt_Mode1_DisableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
//模式2中断禁止
en_result_t Bt_Mode23_DisableIrq (en_bt_unit_t enUnit, en_bt_irq_type_t enBtIrq);
//模式0初始化及相关功能操作
//timer配置及初始化
en_result_t Bt_Mode0_Init(en_bt_unit_t enUnit, stc_bt_mode0_config_t* pstcConfig);
//timer 启动/停止
en_result_t Bt_M0_Run(en_bt_unit_t enUnit);
en_result_t Bt_M0_Stop(en_bt_unit_t enUnit);
//重载值设置
en_result_t Bt_M0_ARRSet(en_bt_unit_t enUnit, uint16_t u16Data);
//16位计数值设置/获取
en_result_t Bt_M0_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
uint16_t Bt_M0_Cnt16Get(en_bt_unit_t enUnit);
//32位计数值设置/获取
en_result_t Bt_M0_Cnt32Set(en_bt_unit_t enUnit, uint32_t u32Data);
uint32_t Bt_M0_Cnt32Get(en_bt_unit_t enUnit);
//翻转输出使能/禁止设定
en_result_t Bt_M0_EnTOG_Output(en_bt_unit_t enUnit, boolean_t bEnOutput);
//模式1初始化及相关功能操作
//timer配置及初始化
en_result_t Bt_Mode1_Init(en_bt_unit_t enUnit, stc_bt_mode1_config_t* pstcConfig);
//PWC 输入配置
en_result_t Bt_M1_Input_Config(en_bt_unit_t enUnit, stc_bt_pwc_input_config_t* pstcConfig);
//PWC测量边沿起始结束选择
en_result_t Bt_M1_PWC_Edge_Sel(en_bt_unit_t enUnit,en_bt_m1cr_Edge_t enEdgeSel);
//timer 启动/停止
en_result_t Bt_M1_Run(en_bt_unit_t enUnit);
en_result_t Bt_M1_Stop(en_bt_unit_t enUnit);
//16位计数值设置/获取
en_result_t Bt_M1_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
uint16_t Bt_M1_Cnt16Get(en_bt_unit_t enUnit);
//脉冲宽度测量结果数值获取
uint16_t Bt_M1_PWC_CapValueGet(en_bt_unit_t enUnit);
//模式23初始化及相关功能操作
//timer配置及初始化
en_result_t Bt_Mode23_Init(en_bt_unit_t enUnit, stc_bt_mode23_config_t* pstcConfig);
//timer 启动/停止
en_result_t Bt_M23_Run(en_bt_unit_t enUnit);
en_result_t Bt_M23_Stop(en_bt_unit_t enUnit);
//PWM输出使能
en_result_t Bt_M23_EnPWM_Output(en_bt_unit_t enUnit, boolean_t bEnOutput, boolean_t bEnAutoOutput);
//重载值设置
en_result_t Bt_M23_ARRSet(en_bt_unit_t enUnit, uint16_t u16Data, boolean_t bArrBufEn);
//16位计数值设置/获取
en_result_t Bt_M23_Cnt16Set(en_bt_unit_t enUnit, uint16_t u16Data);
uint16_t Bt_M23_Cnt16Get(en_bt_unit_t enUnit);
//比较捕获寄存器CCR0A/CCR0B设置/读取
en_result_t Bt_M23_CCR_Set(en_bt_unit_t enUnit, en_bt_m23_ccrx_t enCCRSel, uint16_t u16Data);
uint16_t Bt_M23_CCR_Get(en_bt_unit_t enUnit, en_bt_m23_ccrx_t enCCRSel);
//PWM互补输出模式下GATE功能选择
en_result_t Bt_M23_GateFuncSel(en_bt_unit_t enUnit,stc_bt_m23_gate_config_t* pstcConfig);
//主从模式配置
en_result_t Bt_M23_MasterSlave_Set(en_bt_unit_t enUnit, stc_bt_m23_master_slave_config_t* pstcConfig);
//CH0A/CH0B比较通道控制
en_result_t Bt_M23_PortOutput_Config(en_bt_unit_t enUnit, stc_bt_m23_compare_config_t* pstcConfig);
//CH0A/CH0B输入控制
en_result_t Bt_M23_PortInput_Config(en_bt_unit_t enUnit, stc_bt_m23_input_config_t* pstcConfig);
//ERT输入控制
en_result_t Bt_M23_ETRInput_Config(en_bt_unit_t enUnit, stc_bt_m23_etr_input_config_t* pstcConfig);
//刹车BK输入控制
en_result_t Bt_M23_BrakeInput_Config(en_bt_unit_t enUnit, stc_bt_m23_bk_input_config_t* pstcConfig);
//触发ADC控制
en_result_t Bt_M23_TrigADC_Config(en_bt_unit_t enUnit, stc_bt_m23_adc_trig_config_t* pstcConfig);
//死区功能
en_result_t Bt_M23_DT_Config(en_bt_unit_t enUnit, stc_bt_m23_dt_config_t* pstcConfig);
//重复周期设置
en_result_t Bt_M23_SetValidPeriod(en_bt_unit_t enUnit, uint8_t u8ValidPeriod);
//OCREF清除功能
en_result_t Bt_M23_OCRefClr(en_bt_unit_t enUnit, stc_bt_m23_OCREF_Clr_config_t* pstcConfig);
//使能DMA传输
en_result_t Bt_M23_EnDMA(en_bt_unit_t enUnit, stc_bt_m23_trig_dma_config_t* pstcConfig);
//捕获比较A软件触发
en_result_t Bt_M23_EnSwTrigCapCmpA(en_bt_unit_t enUnit);
//捕获比较B软件触发
en_result_t Bt_M23_EnSwTrigCapCmpB(en_bt_unit_t enUnit);
//软件更新使能
en_result_t Bt_M23_EnSwUev(en_bt_unit_t enUnit);
//软件触发使能
en_result_t Bt_M23_EnSwTrig(en_bt_unit_t enUnit);
//软件刹车使能
en_result_t Bt_M23_EnSwBk(en_bt_unit_t enUnit);
//@} // BtGroup
#ifdef __cplusplus
#endif
#endif /* __BT_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,120 @@
/******************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file crc.h
**
** CRC API声明.
**
** - 2016-05-04 LuX V1.0.
**
******************************************************************************/
#ifndef __CRC_H__
#define __CRC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "sysctrl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup CrcGroup Cyclic Redundancy Check (CRC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//CRC16 编码值获取
uint16_t CRC16_Get8(uint8_t* pu8Data, uint32_t u32Len);
uint16_t CRC16_Get16(uint16_t* pu16Data, uint32_t u32Len);
uint16_t CRC16_Get32(uint32_t* pu32Data, uint32_t u32Len);
//CRC16 校验
en_result_t CRC16_Check8(uint8_t* pu8Data, uint32_t u32Len, uint16_t u16CRC);
en_result_t CRC16_Check16(uint16_t* pu16Data, uint32_t u32Len, uint16_t u16CRC);
en_result_t CRC16_Check32(uint32_t* pu32Data, uint32_t u32Len, uint16_t u16CRC);
//CRC32 编码值获取
uint32_t CRC32_Get8(uint8_t* pu8Data, uint32_t u32Len);
uint32_t CRC32_Get16(uint16_t* pu16Data, uint32_t u32Len);
uint32_t CRC32_Get32(uint32_t* pu32Data, uint32_t u32Len);
//CRC32 校验
en_result_t CRC32_Check8(uint8_t* pu8Data, uint32_t u32Len, uint32_t u32CRC);
en_result_t CRC32_Check16(uint16_t* pu16Data, uint32_t u32Len, uint32_t u32CRC);
en_result_t CRC32_Check32(uint32_t* pu32Data, uint32_t u32Len, uint32_t u32CRC);
//@} // CRC Group
#ifdef __cplusplus
}
#endif
#endif /* __CRC_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,208 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ddl.h
**
** DDL common define.
** @link SampleGroup Some description @endlink
**
** - 2018-04-15 1.0 Lux First version.
**
******************************************************************************/
#ifndef __DDL_H__
#define __DDL_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "base_types.h"
#include "hc32l136.h"
#include "system_hc32l136.h"
#include "sysctrl.h"
//#include "gpio.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/* Macro for initializing local structures to zero */
/******************************************************************************/
#define DDL_ZERO_STRUCT(x) ddl_memclr((uint8_t*)&(x), (uint32_t)(sizeof(x)))
#define DEC2BCD(x) ((((x)/10)<<4) + ((x)%10))
#define BCD2DEC(x) ((((x)>>4)*10) + ((x)&0x0F))
#define setBit(addr,offset,flag) { if( (flag) > 0u){\
*((volatile uint32_t *)(addr)) |= ((1UL)<<(offset));\
}else{\
*((volatile uint32_t *)(addr)) &= (~(1UL<<(offset)));\
}\
}
#define getBit(addr,offset) ((((*((volatile uint32_t *)(addr))) >> (offset)) & 1u)>0?1u:0)
/**
******************************************************************************
** Global Device Series List
******************************************************************************/
#define DDL_DEVICE_SERIES_HC32L136 (0u)
/**
******************************************************************************
** Global Device Package List
******************************************************************************/
// package definitions of HC device.
#define DDL_DEVICE_PACKAGE_HC_C (0x00u)
#define DDL_DEVICE_PACKAGE_HC_F (0x10u)
#define DDL_DEVICE_PACKAGE_HC_J (0x20u)
#define DDL_DEVICE_PACKAGE_HC_K (0x30u)
/******************************************************************************/
/* User Device Setting Include file */
/******************************************************************************/
#include "ddl_device.h" // MUST be included here!
/**
******************************************************************************
** \brief IRQ name definition for all type MCUs
******************************************************************************/
#define PORTA_IRQHandler(void) IRQ000_Handler(void)
#define PORTB_IRQHandler(void) IRQ001_Handler(void)
#define PORTC_IRQHandler(void) IRQ002_Handler(void)
#define PORTD_IRQHandler(void) IRQ003_Handler(void)
#define DMAC_IRQHandler(void) IRQ004_Handler(void)
#define TIM3_IRQHandler(void) IRQ005_Handler(void)
#define UART0_IRQHandler(void) IRQ006_Handler(void)
#define UART1_IRQHandler(void) IRQ007_Handler(void)
#define LPUART0_IRQHandler(void) IRQ008_Handler(void)
#define LPUART1_IRQHandler(void) IRQ009_Handler(void)
#define SPI0_IRQHandler(void) IRQ010_Handler(void)
#define SPI1_IRQHandler(void) IRQ011_Handler(void)
#define I2C0_IRQHandler(void) IRQ012_Handler(void)
#define I2C1_IRQHandler(void) IRQ013_Handler(void)
#define TIM0_IRQHandler(void) IRQ014_Handler(void)
#define TIM1_IRQHandler(void) IRQ015_Handler(void)
#define TIM2_IRQHandler(void) IRQ016_Handler(void)
#define LPTIM_IRQHandler(void) IRQ017_Handler(void)
#define TIM4_IRQHandler(void) IRQ018_Handler(void)
#define TIM5_IRQHandler(void) IRQ019_Handler(void)
#define TIM6_IRQHandler(void) IRQ020_Handler(void)
#define PCA_IRQHandler(void) IRQ021_Handler(void)
#define WDT_IRQHandler(void) IRQ022_Handler(void)
#define RTC_IRQHandler(void) IRQ023_Handler(void)
#define ADC_IRQHandler(void) IRQ024_Handler(void)
#define PCNT_IRQHandler(void) IRQ025_Handler(void)
#define VC0_IRQHandler(void) IRQ026_Handler(void)
#define VC1_IRQHandler(void) IRQ027_Handler(void)
#define LVD_IRQHandler(void) IRQ028_Handler(void)
#define LCD_IRQHandler(void) IRQ029_Handler(void)
#define EF_RAM_IRQHandler(void) IRQ030_Handler(void)
#define CLKTRIM_IRQHandler(void) IRQ031_Handler(void)
/******************************************************************************/
/* Global type definitions ('typedef') */
/******************************************************************************/
/**
******************************************************************************
** \brief Level
**
** Specifies levels.
**
******************************************************************************/
typedef enum en_level
{
DdlLow = 0u, ///< Low level '0'
DdlHigh = 1u ///< High level '1'
} en_level_t;
/**
******************************************************************************
** \brief Generic Flag Code
**
** Specifies flags.
**
******************************************************************************/
typedef enum en_flag
{
DdlClr = 0u, ///< Flag clr '0'
DdlSet = 1u ///< Flag set '1'
} en_stat_flag_t, en_irq_flag_t;
/******************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/******************************************************************************/
/******************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/******************************************************************************/
/*******************************************************************************
* Global function prototypes
******************************************************************************/
extern void ddl_memclr(void* pu8Address, uint32_t u32Count);
uint32_t Log2(uint32_t u32Val);
/**
*******************************************************************************
** This hook is part of wait loops.
******************************************************************************/
extern void DDL_WAIT_LOOP_HOOK(void);
void Debug_UartInit(void);
void delay1ms(uint32_t u32Cnt);
void delay100us(uint32_t u32Cnt);
void delay10us(uint32_t u32Cnt);
#ifdef __cplusplus
}
#endif
#endif /* __DDL_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/

View File

@ -0,0 +1,129 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file debug.h
**
** Headerfile for DEBUG functions
** @link Debug Group Some description @endlink
**
** History:
** - 2018-04-15 Lux First Version
**
******************************************************************************/
#ifndef __DEBUG_H__
#define __DEBUG_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup DebugGroup (DEBUG)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
*******************************************************************************
** \brief
** \note
******************************************************************************/
typedef enum en_debug_module_active
{
DebugTim0 = 0x001u, ///< TIM0
DebugTim1 = 0x002u, ///< TIM1
DebugTim2 = 0x004u, ///< TIM2
DebugLpTim = 0x008u, ///< LPTIM
DebugTim4 = 0x010u, ///< TIM4
DebugTim5 = 0x020u, ///< TIM5
DebugTim6 = 0x040u, ///< TIM6
DebugPca = 0x080u, ///< PCA
DebugWdt = 0x100u, ///< WDT
DebugRtc = 0x200u, ///< RTC
DebugTick = 0x400u, ///< TICK
DebugTim3 = 0x800u, ///< TIM3
}en_debug_module_active_t;
/*******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 在SWD调试界面下使能模块功能
en_result_t Debug_ActiveEnable(en_debug_module_active_t enModule);
///< 在SWD调试界面下暂停模块功能
en_result_t Debug_ActiveDisable(en_debug_module_active_t enModule);
//@} // Debug Group
#ifdef __cplusplus
#endif
#endif /* __DEBUG_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,327 @@
/*****************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file dma.h
**
** A detailed description is available at
** @link DmacGroup Dmac description @endlink
**
** - 2018-03-09 1.0 Hongjh First version for Device Driver Library of Dmac.
**
******************************************************************************/
#ifndef __DMAC_H__
#define __DMAC_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup DmacGroup Direct Memory Access Control(DMAC)
**
******************************************************************************/
//@{
/*******************************************************************************
* Global type definitions ('typedef')
******************************************************************************/
/**
*******************************************************************************
** \brief DMA Channel
**
******************************************************************************/
typedef enum en_dma_channel
{
DmaCh0 = 0U, ///< DMA channel 0
DmaCh1 = 1U, ///< DMA channel 1
DmaChMax = 2U ///< DMA channel max
} en_dma_channel_t;
/**
*******************************************************************************
** \brief DMA priority
**
******************************************************************************/
typedef enum en_dma_priority
{
DmaPriorityFix = 0U, ///< DMA channel priority fix (CH0>CH1)
DmaPriorityLoop = 1U, ///< DMA channel priority loop
} en_dma_priority_t;
/**
*******************************************************************************
** \brief DMA transfer data width
**
******************************************************************************/
typedef enum en_dma_transfer_width
{
Dma8Bit = 0U, ///< 8 bit transfer via DMA
Dma16Bit = 1U, ///< 16 bit transfer via DMA
Dma32Bit = 2U ///< 32 bit transfer via DMA
} en_dma_transfer_width_t;
/**
*******************************************************************************
** \brief DMA transfer mode
**
******************************************************************************/
typedef enum en_dma_transfer_mode
{
DmaBlock = 0U, ///< block transfer via DMA
DmaBurst = 1U, ///< burst transfer via DMA
} en_dma_transfer_mode_t;
/**
*******************************************************************************
** \brief DMA flag
**
******************************************************************************/
typedef enum en_dma_stat
{
DEFAULT = 0U, ///< Reserve
DmaAddOverflow = 1U, ///< DMA address overflow
DmaHALT = 2U, ///< DMA HALT
DmaAccSCRErr = 3U, ///< DMA access source address error
DmaAccDestErr = 4U, ///< DMA access dest address error
DmaTransferComplete = 5U, ///< DMA transfer complete
DmaTransferPause = 7U, ///< DMA transfer pause
} en_dma_stat_t;
/**
*******************************************************************************
** \brief DMA address mode
**
******************************************************************************/
typedef enum en_address_mode
{
AddressIncrease = 0U, ///< Address increased
AddressFix = 1U, ///< Address fixed
} en_address_mode_t;
/**
*******************************************************************************
** \brief DMA repeat tranfer
**
******************************************************************************/
typedef enum en_dma_msk
{
OneTranfer = 0U, ///< One Tranfer
ContinuousTranfer = 1U, ///< Continuous Tranfer
} en_dma_msk_t;
/**
*******************************************************************************
** \brief DMA trigger selection
**
******************************************************************************/
typedef enum stc_dma_trig_sel
{
SWTrig = 0U, ///< Select DMA software trig
SPI0RXTrig = 32U, ///< Select DMA hardware trig 0
SPI0TXTrig = 33U, ///< Select DMA hardware trig 1
SPI1RXTrig = 34U, ///< Select DMA hardware trig 2
SPI1TXTrig = 35U, ///< Select DMA hardware trig 3
ADCJQRTrig = 36U, ///< Select DMA hardware trig 4
ADCSQRTrig = 37U, ///< Select DMA hardware trig 5
LCDTxTrig = 38U, ///< Select DMA hardware trig 6
Uart0RxTrig = 40U, ///< Select DMA hardware trig 8
Uart0TxTrig = 41U, ///< Select DMA hardware trig 9
Uart1RxTrig = 42U, ///< Select DMA hardware trig 10
Uart1TxTrig = 43U, ///< Select DMA hardware trig 11
LpUart0RxTrig = 44U, ///< Select DMA hardware trig 12
LpUart0TxTrig = 45U, ///< Select DMA hardware trig 13
LpUart1RxTrig = 46U, ///< Select DMA hardware trig 14
LpUart1TxTrig = 47U, ///< Select DMA hardware trig 15
TIM0ATrig = 50U, ///< Select DMA hardware trig 18
TIM0BTrig = 51U, ///< Select DMA hardware trig 19
TIM1ATrig = 52U, ///< Select DMA hardware trig 20
TIM1BTrig = 53U, ///< Select DMA hardware trig 21
TIM2ATrig = 54U, ///< Select DMA hardware trig 22
TIM2BTrig = 55U, ///< Select DMA hardware trig 23
TIM3ATrig = 56U, ///< Select DMA hardware trig 24
TIM3BTrig = 57U, ///< Select DMA hardware trig 25
TIM4ATrig = 58U, ///< Select DMA hardware trig 26
TIM4BTrig = 59U, ///< Select DMA hardware trig 27
TIM5ATrig = 60U, ///< Select DMA hardware trig 28
TIM5BTrig = 61U, ///< Select DMA hardware trig 29
TIM6ATrig = 62U, ///< Select DMA hardware trig 30
TIM6BTrig = 63U, ///< Select DMA hardware trig 31
}en_dma_trig_sel_t;
/**
*******************************************************************************
** \brief DMA interrupt selection
**
******************************************************************************/
typedef struct stc_dma_irq
{
boolean_t TrnErrIrq; ///< Select DMA transfer error interrupt
boolean_t TrnCpltIrq; ///< Select DMA transfer completion interrupt
}stc_dma_irq_sel_t;
/**
*******************************************************************************
** \brief DMA configuration
**
******************************************************************************/
typedef struct stc_dma_config
{
en_dma_transfer_mode_t enMode;
uint16_t u16BlockSize; ///< Transfer Block counter
uint16_t u16TransferCnt; ///< Transfer counter
en_dma_transfer_width_t enTransferWidth; ///< DMA transfer width (see #en_dma_transfer_width_t for details)
en_address_mode_t enSrcAddrMode; ///< Source address mode(see #en_source_address_mode_t for details)
en_address_mode_t enDstAddrMode; ///< Destination address mode(see #en_dest_address_mode_t for details)
boolean_t bSrcAddrReloadCtl; ///< Source address reload(TRUE: reload;FALSE: reload forbidden)
boolean_t bDestAddrReloadCtl; ///< Dest address reload(TRUE: reload;FALSE: reload forbidden)
boolean_t bSrcBcTcReloadCtl; ///< Bc/Tc address reload(TRUE: reload;FALSE: reload forbidden)
uint32_t u32SrcAddress; ///< Source address>
uint32_t u32DstAddress; ///< Dest address>
boolean_t bMsk; ///0: clear the bit (CONFA:ENS) after tarnfer;1: remain the bit (CONFA:ENS) after tarnfer
en_dma_trig_sel_t enRequestNum; ///< DMA trigger request number
} stc_dma_config_t;
/**
******************************************************************************
** \brief DMA中断回调函数
*****************************************************************************/
typedef struct stc_dma_irq_calbakfn_pt
{
/*! Dma传输完成中断回调函数指针*/
func_ptr_t pfnDma0TranferCompleteIrq;
/*! Dma传输完成中断回调函数指针*/
func_ptr_t pfnDma1TranferCompleteIrq;
/*! Dma传输错误中断回调函数指针*/
func_ptr_t pfnDma0TranferErrIrq;
/*! Dma传输错误中断回调函数指针*/
func_ptr_t pfnDma1TranferErrIrq;
}stc_dma_irq_calbakfn_pt_t;
/*******************************************************************************
* Global pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
en_result_t Dma_InitChannel(en_dma_channel_t enCh, stc_dma_config_t* pstcConfig);
void Dma_SwTrigger(en_dma_channel_t enCh);
void Dma_Enable(void);
void Dma_Disable(void);
void Dma_Start(en_dma_channel_t enCh);
void Dma_Stop(en_dma_channel_t enCh);
en_result_t Dma_EnableChannel(en_dma_channel_t enCh);
en_result_t Dma_DisableChannel(en_dma_channel_t enCh);
en_result_t Dma_SetTriggerSel(en_dma_channel_t enCh, en_dma_trig_sel_t enTrgSel);
en_result_t Dma_SetSourceAddress(en_dma_channel_t enCh, uint32_t u32Address);
en_result_t Dma_SetDestinationAddress(en_dma_channel_t enCh, uint32_t u32Address);
en_result_t Dma_SetBlockSize(en_dma_channel_t enCh, uint16_t u16BlkSize);
en_result_t Dma_SetTransferCnt(en_dma_channel_t enCh, uint16_t u16TrnCnt);
en_result_t Dma_SetSourceIncMode(en_dma_channel_t enCh, en_address_mode_t enMode);
en_result_t Dma_SetDestinationIncMode(en_dma_channel_t enCh, en_address_mode_t enMode);
en_result_t Dma_EnableSourceRload(en_dma_channel_t enCh);
en_result_t Dma_DisableSourceRload(en_dma_channel_t enCh);
en_result_t Dma_EnableDestinationRload(en_dma_channel_t enCh);
en_result_t Dma_DisableDestinationRload(en_dma_channel_t enCh);
en_result_t Dma_EnableContinusTranfer(en_dma_channel_t enCh);
en_result_t Dma_DisableContinusTranfer(en_dma_channel_t enCh);
en_result_t Dma_EnableBcTcReload(en_dma_channel_t enCh);
en_result_t Dma_DisableBcTcReload(en_dma_channel_t enCh);
void Dma_HaltTranfer(void);
void Dma_RecoverTranfer(void);
en_result_t Dma_PauseChannelTranfer(en_dma_channel_t enCh);
en_result_t Dma_RecoverChannelTranfer(en_dma_channel_t enCh);
en_result_t Dma_SetTransferWidth(en_dma_channel_t enCh, en_dma_transfer_width_t enWidth);
en_result_t Dma_SetChPriority(en_dma_priority_t enPrio);
en_result_t Dma_EnableChannelIrq(en_dma_channel_t enCh);
en_result_t Dma_DisableChannelIrq(en_dma_channel_t enCh);
en_result_t Dma_EnableChannelErrIrq(en_dma_channel_t enCh);
en_result_t Dma_DisableChannelErrIrq(en_dma_channel_t enCh);
en_result_t Dma_ConfigIrq(en_dma_channel_t enCh,stc_dma_irq_sel_t* stcDmaIrqCfg,stc_dma_irq_calbakfn_pt_t* pstcDmaIrqCalbaks);
en_dma_stat_t Dma_GetStat(en_dma_channel_t enCh);
void Dma_ClrStat(en_dma_channel_t enCh);
//@} // DmacGroup
#ifdef __cplusplus
}
#endif
#endif /* __DMAC_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,196 @@
/*************************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file flash.h
**
** FLASH API声明.
**
** - 2017-05-02 LuX V1.0
**
******************************************************************************/
#ifndef __FLASH_H__
#define __FLASH_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup FlashGroup Flash Controller (Flash)
**
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief Flash中断类型重定义
*****************************************************************************/
typedef enum en_flash_int_type
{
FlashPCInt = 1u, ///<擦写PC地址报警中断
FlashSlockInt = 0u, ///<擦写保护报警中断
} en_flash_int_type_t;
/**
******************************************************************************
** \brief Flash读等待周期类型重定义
*****************************************************************************/
typedef enum en_flash_waitcycle
{
FlashWaitCycle0 = 0u, ///< 读等待周期设置为0当HCLK小于等于24MHz时
FlashWaitCycle1 = 1u, ///< 读等待周期设置为1当HCLK大于24MHz时必须至少为1
FlashWaitCycle2 = 2u, ///< 读等待周期设置为2当HCK大于48MHz时必须至少为2
} en_flash_waitcycle_t;
/**
******************************************************************************
** \brief Flash擦写保护范围重定义
*****************************************************************************/
typedef enum en_flash_sector_lock
{
FlashSector0_3 = 0x00000001u, ///<Sector0_3
FlashSector4_7 = 0x00000002u, ///<Sector4_7
FlashSector8_11 = 0x00000004u, ///<Sector8_11
FlashSector12_15 = 0x00000008u, ///<Sector12_15
FlashSector16_19 = 0x00000010u, ///<Sector16_19
FlashSector20_23 = 0x00000020u, ///<Sector20_23
FlashSector24_27 = 0x00000040u, ///<Sector24_27
FlashSector28_31 = 0x00000080u, ///<Sector28_31
FlashSector32_35 = 0x00000100u, ///<Sector32_35
FlashSector36_39 = 0x00000200u, ///<Sector36_39
FlashSector40_43 = 0x00000400u, ///<Sector40_43
FlashSector44_47 = 0x00000800u, ///<Sector44_47
FlashSector48_51 = 0x00001000u, ///<Sector48_51
FlashSector52_55 = 0x00002000u, ///<Sector52_55
FlashSector56_59 = 0x00004000u, ///<Sector56_59
FlashSector60_63 = 0x00008000u, ///<Sector60_63
FlashSector64_67 = 0x00010000u, ///<Sector64_67
FlashSector68_71 = 0x00020000u, ///<Sector68_71
FlashSector72_75 = 0x00040000u, ///<Sector72_75
FlashSector76_79 = 0x00080000u, ///<Sector76_79
FlashSector80_83 = 0x00100000u, ///<Sector80_83
FlashSector84_87 = 0x00200000u, ///<Sector84_87
FlashSector88_91 = 0x00400000u, ///<Sector88_91
FlashSector92_95 = 0x00800000u, ///<Sector92_95
FlashSector96_99 = 0x01000000u, ///<Sector96_99
FlashSector100_103 = 0x02000000u, ///<Sector100_103
FlashSector104_107 = 0x04000000u, ///<Sector104_107
FlashSector108_111 = 0x08000000u, ///<Sector108_111
FlashSector112_115 = 0x10000000u, ///<Sector112_115
FlashSector116_119 = 0x20000000u, ///<Sector116_119
FlashSector120_123 = 0x40000000u, ///<Sector120_123
FlashSector124_127 = (int)0x80000000u, ///<Sector124_127
FlashSectorAll = (int)0xFFFFFFFFu, ///<SectorAll
} en_flash_sector_lock_t;
/**
******************************************************************************
** \brief Redefinition of FLASH register structure
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///<Flash 初始化配置(中断函数、编程时间参数及休眠模式配置)
en_result_t Flash_Init(func_ptr_t pfnFlashCb, uint8_t u8FreqCfg, boolean_t bDpstbEn);
///<Flash 页/全片擦除
en_result_t Flash_SectorErase(uint32_t u32SectorAddr);
en_result_t Flash_ChipErase(void);
///<Flash 字节/半字/字写
en_result_t Flash_WriteByte(uint32_t u32Addr, uint8_t u8Data);
en_result_t Flash_WriteHalfWord(uint32_t u32Addr, uint16_t u16Data);
en_result_t Flash_WriteWord(uint32_t u32Addr, uint32_t u32Data);
///<Flash 编程保护加锁/解锁
en_result_t Flash_Lock(en_flash_sector_lock_t enFlashSector);
en_result_t Flash_Unlock(en_flash_sector_lock_t enFlashSector);
///<Flash 读等待周期设定
en_result_t Flash_WaitCycle(en_flash_waitcycle_t enWaitCycle);
///<中断相关函数
///<中断使能/禁止
en_result_t Flash_EnableIrq(en_flash_int_type_t enFlashIntType);
en_result_t Flash_DisableIrq(en_flash_int_type_t enFlashIntType);
///<中断标志获取
boolean_t Flash_GetIntFlag(en_flash_int_type_t enFlashIntType);
///<中断标志清除
en_result_t Flash_ClearIntFlag(en_flash_int_type_t enFlashIntType);
//@} // FlashGroup
#ifdef __cplusplus
}
#endif
#endif /* __FLASH_H__ */
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/

View File

@ -0,0 +1,506 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file gpio.h
**
** GPIO driver
** @link GPIO Group Some description @endlink
**
** - 2018-04-18
**
******************************************************************************/
#ifndef __GPIO_H__
#define __GPIO_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup GpioGroup General Purpose I/O (GPIO)
**
**
******************************************************************************/
//@{
#define GPIO_GPSZ (0x40u)
/*******************************************************************************
* Global type definitions
******************************************************************************/
/**
*******************************************************************************
** \brief GPIO PORT类型定义
******************************************************************************/
typedef enum en_gpio_port
{
GpioPortA = 0x00u, ///< GPIO PORT A
GpioPortB = 0x40u, ///< GPIO PORT B
GpioPortC = 0x80u, ///< GPIO PORT C
GpioPortD = 0xc0u, ///< GPIO PORT D
}en_gpio_port_t;
/**
*******************************************************************************
** \brief GPIO PIN类型定义
******************************************************************************/
typedef enum en_gpio_pin
{
GpioPin0 = 0u, ///< GPIO PIN0
GpioPin1 = 1u, ///< GPIO PIN1
GpioPin2 = 2u, ///< GPIO PIN2
GpioPin3 = 3u, ///< GPIO PIN3
GpioPin4 = 4u, ///< GPIO PIN4
GpioPin5 = 5u, ///< GPIO PIN5
GpioPin6 = 6u, ///< GPIO PIN6
GpioPin7 = 7u, ///< GPIO PIN7
GpioPin8 = 8u, ///< GPIO PIN8
GpioPin9 = 9u, ///< GPIO PIN9
GpioPin10 = 10u, ///< GPIO PIN10
GpioPin11 = 11u, ///< GPIO PIN11
GpioPin12 = 12u, ///< GPIO PIN12
GpioPin13 = 13u, ///< GPIO PIN13
GpioPin14 = 14u, ///< GPIO PIN14
GpioPin15 = 15u, ///< GPIO PIN15
}en_gpio_pin_t;
/**
*******************************************************************************
** \brief GPIO (AF-Alternate function)
******************************************************************************/
typedef enum en_gpio_af
{
GpioAf0 = 0u, ///< GPIO功能
GpioAf1 = 1u, ///< GPIO AF1:
///< PA:UART1/SPI0/UART0/IR
///< PB:PCA/LPTIM/SPI0/I2C0/I2C1/SPI1
///< PC:LPTIM/SPI1/LPUART0/PCA/LPUART1
///< PD:I2C0/PCA/I2C1
GpioAf2 = 2u, ///< GPIO AF2:
///< PA:LPUART1/TIM0/UART1/PCA/TIM3
///< PB:TIM3/PCLK_OUT/PCA/TIM0/UART0/TIM1/IR/SPI1/I2C1
///< PC:PCNT/TIM5/LPTIM/TIM2/TIM6/TIM4/LPUART0/LPUART1/RTC
///< PD:TIM4/LPUART0/LPUART1
GpioAf3 = 3u, ///< GPIO AF3:
///< PA:TIM0/VC1/TIM1/PCA/TIM3/HCLK_OUT/TIM0/TIM2/I2C1/LVD/LPUART1
///< PB:LPUART0/TIM3/LPUART1/TIM1/TIM2/SPI1/TIM0
///< PC:UART1/PCNT/LPTIM/IR/PCA/TIM2/TIM1/TIM3
///< PD:UART1/TIM1/UART0
GpioAf4 = 4u, ///< GPIO AF4:
///< PA:VC0/TIM1/TIM2/TIM0/TIM3/I2C0/LVD
///< PB:TIM5/TIM6/TIM4/TIM3/UART0/PCA/TIM0/LPUART1/TIM2/LPUART0
///< PC:RESERVED
///< PD:RESERVED
GpioAf5 = 5u, ///< GPIO AF5:
///< PA:TIM1/TIM2/SPI1/TIM5/VC0/VC1/RTC/RCH_OUT/TIM0
///< PB:RCH_OUT/LPUART0/TIM1/LPTIM/TIM2/TIM0/TIM3/TIM6/RTC
///< PC:RESERVED
///< PD:RESERVED
GpioAf6 = 6u, ///< GPIO AF6:
///< PA:TIM3/HCLK_OUT/PCLK_OUT/LVD/XTL_OUT/VC1/TIM4/SPI0/PCNT/RCL_OUT
///< PB:TIM0/XTL_OUT/TIM3/PCNT/LPTIM/TIM2/LPUART1/LPUART0/TIM1/RTC
///< PC:RESERVED
///< PD:RESERVED
GpioAf7 = 7u, ///< GPIO AF7:
///< PA:TIM0/SPI1/TIM5/TIM3/XTH_OUT/LPUART0/TIM4/TIM6/PCNT/PLL_OUT
///< PB:PLL_OUT/TIM2/XTH_OUT/LPTIM/UART0/PCNT/UART1/TIM6/TIM1/LPUART1
///< PC:RESERVED
///< PD:RESERVED
}en_gpio_af_t;
/**
*******************************************************************************
** \brief GPIO输入输出配置数据类型定义
******************************************************************************/
typedef enum en_gpio_dir
{
GpioDirOut = 0u, ///< GPIO 输出
GpioDirIn = 1u, ///< GPIO 输入
}en_gpio_dir_t;
/**
*******************************************************************************
** \brief GPIO端口上拉
******************************************************************************/
typedef enum en_gpio_pupd
{
GpioNoPuPd = 0u, ///< GPIO无上拉下拉
GpioPu = 1u, ///< GPIO上拉
GpioPd = 2u, ///< GPIO下拉
}en_gpio_pupd_t;
/**
*******************************************************************************
** \brief GPIO端口输出驱动能力配置数据类型定义
******************************************************************************/
typedef enum en_gpio_drv
{
GpioDrvH = 0u, ///< GPIO高驱动能力
GpioDrvL = 1u, ///< GPIO低驱动能力
}en_gpio_drv_t;
/**
*******************************************************************************
** \brief GPIO端口开漏输出控制数据类型定义
******************************************************************************/
typedef enum en_gpio_od
{
GpioOdDisable = 0u, ///< GPIO开漏输出关闭
GpioOdEnable = 1u, ///< GPIO开漏输出使能
}en_gpio_od_t;
/**
*******************************************************************************
** \brief GPIO端口输入/线
******************************************************************************/
typedef enum en_gpio_ctrl_mode
{
GpioFastIO = 0u, ///< FAST IO 总线控制模式
GpioAHB = 1u, ///< AHB 总线控制模式
}en_gpio_ctrl_mode_t;
/**
*******************************************************************************
** \brief GPIO中断触发方式类型定义
******************************************************************************/
typedef enum en_gpio_irqtype
{
GpioIrqHigh = 1u, ///< GPIO高电平触发
GpioIrqLow = 2u, ///< GPIO低电平触发
GpioIrqRising = 4u, ///< GPIO上升沿触发
GpioIrqFalling = 8u, ///< GPIO下降沿触发
}en_gpio_irqtype_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary Function
******************************************************************************/
typedef enum en_gpio_sf_irqmode
{
GpioSfIrqDpslpMode = 1u, ///< Deep Sleep模式
GpioSfIrqActSlpMode = 0u, ///< Active/Sleep模式
}en_gpio_sf_irqmode_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionHCLK输出门控类型定义
******************************************************************************/
typedef enum en_gpio_sf_hclkout_g
{
GpioSfHclkOutDisable = 0u, ///< HCLK输出门控关闭
GpioSfHclkOutEnable = 1u, ///< HCLK输出门控使能
}en_gpio_sf_hclkout_g_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionHCLK输出分频选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_hclkout_div
{
GpioSfHclkOutDiv1 = 0u, ///< HCLK
GpioSfHclkOutDiv2 = 1u, ///< HCLK/2
GpioSfHclkOutDiv4 = 2u, ///< HCLK/4
GpioSfHclkOutDiv8 = 3u, ///< HCLK/8
}en_gpio_sf_hclkout_div_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionPCLK输出门控类型定义
******************************************************************************/
typedef enum en_gpio_sf_pclkout_g
{
GpioSfPclkOutDisable = 0u, ///< PCLK输出门控关闭
GpioSfPclkOutEnable = 1u, ///< PCLK输出门控使能
}en_gpio_sf_pclkout_g_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionPCLK输出分频选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_pclkout_div
{
GpioSfPclkOutDiv1 = 0u, ///< PCLK
GpioSfPclkOutDiv2 = 1u, ///< PCLK/2
GpioSfPclkOutDiv4 = 2u, ///< PCLK/4
GpioSfPclkOutDiv8 = 3u, ///< PCLK/8
}en_gpio_sf_pclkout_div_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionIR输出极性选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_irpol
{
GpioSfIrP = 0u, ///< IR正向输出
GpioSfIrN = 1u, ///< IR反向输出
}en_gpio_sf_irpol_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionSSN通道类型定义
******************************************************************************/
typedef enum en_gpio_sf_ssnspi
{
GpioSpi0 = 0u, ///< SPI0 SSN
GpioSpi1 = 1u, ///< SPI1 SSN
}en_gpio_sf_ssnspi_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionSSN与外部时钟输入信号源选择类型定义
******************************************************************************/
typedef enum en_gpio_sf_ssn_extclk
{
GpioSfSsnExtClkH = 0u, ///< 高电平
GpioSfSsnExtClkPA03 = 1u, ///< PA03
GpioSfSsnExtClkPA04 = 2u, ///< PA04
GpioSfSsnExtClkPA06 = 3u, ///< PA06
GpioSfSsnExtClkPA08 = 4u, ///< PA08
GpioSfSsnExtClkPA09 = 5u, ///< PA09
GpioSfSsnExtClkPA12 = 6u, ///< PA12
GpioSfSsnExtClkPA15 = 7u, ///< PA15
GpioSfSsnExtClkPB01 = 8u, ///< PB01
GpioSfSsnExtClkPB02 = 9u, ///< PB02
GpioSfSsnExtClkPB05 = 10u, ///< PB05
GpioSfSsnExtClkPB06 = 11u, ///< PB06
GpioSfSsnExtClkPB09 = 12u, ///< PB09
GpioSfSsnExtClkPB10 = 13u, ///< PB10
GpioSfSsnExtClkPB12 = 14u, ///< PB12
GpioSfSsnExtClkPB14 = 15u, ///< PB14
}en_gpio_sf_ssn_extclk_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary Function
******************************************************************************/
typedef enum en_gpio_sf
{
GpioSf0 = 0u, ///< SF0:PX_SEL的配置功能
GpioSf1 = 1u, ///< SF1
///< TIM_G:UART0_RXD/LPUART0_RXD
///< TIM_E:UART0_RXD/LPUART0_RXD/PCNT_S0
///< TIM_C:UART0_RXD/LPUART0_RXD/UART1_RXD/LPUART1_RXD
///< PCA:PCNT_S1/PCNT_S0
GpioSf2 = 2u, ///< SF2
///< TIM_G:UART1_RXD/LPUART1_RXD
///< TIM_E:UART1_RXD/LPUART1_RXD/LVD_OUT
///< TIM_C:PA00/VC0_OUT/LPUART0_RXD/UART1_RXD
///< PCA:LVD_OUT/PCNT_S1
GpioSf3 = 3u, ///< SF3
///< TIM_G:VC0_OUT/LPUART0
///< TIM_E:VC0_OUT/VC1OUT
///< TIM_C:PA02/PCNT_S0/PCNT_S1
///< PCA:VC0_OUT/LVD_OUT
GpioSf4 = 4u, ///< SF4
///< TIM_G:VC1_OUT/LPUART1
///< TIM_E:LVD_OUT/PCNT_S1/PCNT_S0/VC1_OUT
///< TIM_C:PA05/PA06/PA07/VC0_OUT/VC1_OUT
///< PCA:VC1_OUT
GpioSf5 = 5u, ///< SF5
///< TIM_G:PA03/PA08/PA10/VC0_OUT/PB03
///< TIM_E:PA00/PA01/PA04
///< TIM_C:PA15/PB08/PA08/PA07
///< PCA:PA05/PA06
GpioSf6 = 6u, ///< SF6
///< TIM_G:PB08/PB03/PB04/PA06/PB05
///< TIM_E:PA05/PC09/PC04/PA12/PB06
///< TIM_C:PB06/PB10/PB09/PB03/PB04
///< PCA:PB02/PB04
GpioSf7 = 7u, ///< SF7
///< TIM_G:PB15/PB13/PB11/PC00
///< TIM_E:PA15/PD02/PC08/PA13/PC03
///< TIM_C:PB14/PB13/PC06/PB06
///< PCA:PD02/PC06
}en_gpio_sf_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary Function
******************************************************************************/
typedef enum en_gpio_sf_tim_g
{
GpioSfTim0G = 0u, ///<Tim0定时器GATE输入选择
GpioSfTim1G = 3u, ///<Tim1定时器GATE输入选择
GpioSfTim2G = 6u, ///<Tim2定时器GATE输入选择
GpioSfTim3G = 9u, ///<Tim3定时器GATE输入选择
GpioSfLpTimG = 12u, ///<LPTim定时器GATE输入选择
}en_gpio_sf_tim_g_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionETR类型选择数据类型定义
******************************************************************************/
typedef enum en_gpio_sf_tim_e
{
GpioSfTim0E = 0u, ///<Tim0定时器ETR输入选择
GpioSfTim1E = 3u, ///<Tim1定时器ETR输入选择
GpioSfTim2E = 6u, ///<Tim2定时器ETR输入选择
GpioSfTim3E = 9u, ///<Tim3定时器ETR输入选择
GpioSfLpTimE = 12u, ///<LPTim定时器ETR输入选择
}en_gpio_sf_tim_e_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary Function
******************************************************************************/
typedef enum en_gpio_sf_tim_c
{
GpioSfTim0CA = 0u, ///<Tim0定时器CHA输入选择
GpioSfTim1CA = 3u, ///<Tim1定时器CHA输入选择
GpioSfTim2CA = 6u, ///<Tim2定时器CHA输入选择
GpioSfTim3CA = 9u, ///<Tim3定时器CH0A输入选择
GpioSfTim3CB = 12u, ///<Tim3定时器CH0B输入选择
}en_gpio_sf_tim_c_t;
/**
*******************************************************************************
** \brief GPIO SF-Secondary FunctionPCA捕获选择数据类型定义
******************************************************************************/
typedef enum en_gpio_sf_pca
{
GpioSfPcaCH0 = 0u, ///<PCA_CH0捕获口输入选择
GpioSfPcaECI = 3u, ///<PCA ECI时钟输入选择
}en_gpio_sf_pca_t;
/**
*******************************************************************************
** \brief GPIO
******************************************************************************/
typedef struct
{
en_gpio_dir_t enDir; ///< 端口方向配置
en_gpio_drv_t enDrv; ///< 端口驱动能力配置
en_gpio_pupd_t enPuPd; ///< 端口上下拉配置
en_gpio_od_t enOD; ///< 端口开漏输出配置
en_gpio_ctrl_mode_t enCtrlMode; ///< 端口输入/输出值寄存器总线控制模式配置
}stc_gpio_config_t;
/*******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
Global function prototypes (definition in C source)
*******************************************************************************/
///< GPIO IO初始化/去初始化
en_result_t Gpio_Init(en_gpio_port_t enPort, en_gpio_pin_t enPin, stc_gpio_config_t *pstcGpioCfg);
///< GPIO 获取端口输入电平
boolean_t Gpio_GetInputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin);
uint16_t Gpio_GetInputData(en_gpio_port_t enPort);
///< GPIO 设置端口输出
///< GPIO 端口输出电平配置及获取
en_result_t Gpio_WriteOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin, boolean_t bVal);
boolean_t Gpio_ReadOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 端口/引脚输出电平置位
en_result_t Gpio_SetPort(en_gpio_port_t enPort, uint16_t u16ValMsk);
en_result_t Gpio_SetIO(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 端口/引脚输出电平清零
en_result_t Gpio_ClrPort(en_gpio_port_t enPort, uint16_t u16ValMsk);
en_result_t Gpio_ClrIO(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 端口输出电平置位与清零设置
en_result_t Gpio_SetClrPort(en_gpio_port_t enPort, uint32_t u32ValMsk);
///< GPIO 设置端口为模拟功能
en_result_t Gpio_SetAnalogMode(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 设置端口为端口复用功能
en_result_t Gpio_SetAfMode(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_af_t enAf);
///< GPIO 端口中断控制功能使能/关闭
en_result_t Gpio_EnableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType);
en_result_t Gpio_DisableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType);
///< GPIO 中断状态获取
boolean_t Gpio_GetIrqStatus(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 中断标志清除
en_result_t Gpio_ClearIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin);
///< GPIO 端口辅助功能配置
///< GPIO 中断模式配置
en_result_t Gpio_SfIrqModeConfig(en_gpio_sf_irqmode_t enIrqMode);
///< GPIO IR输出极性配置
en_result_t Gpio_SfIrPolConfig(en_gpio_sf_irpol_t enIrPolMode);
///< GPIO HCLK输出配置
en_result_t Gpio_SfHClkOutputConfig(en_gpio_sf_hclkout_g_t enGate, en_gpio_sf_hclkout_div_t enDiv);
///< GPIO PCLK输出配置
en_result_t Gpio_SfPClkOutputConfig(en_gpio_sf_pclkout_g_t enGate, en_gpio_sf_pclkout_div_t enDiv);
///< GPIO 外部时钟输入配置
en_result_t Gpio_SfExtClkConfig(en_gpio_sf_ssn_extclk_t enExtClk);
///< GPIO SPI SSN输入配置
en_result_t Gpio_SfSsnConfig(en_gpio_sf_ssnspi_t enSpi, en_gpio_sf_ssn_extclk_t enSsn);
///< GPIO Timer 门控输入配置
en_result_t Gpio_SfTimGConfig(en_gpio_sf_tim_g_t enTimG, en_gpio_sf_t enSf);
///< GPIO Timer ETR选择配置
en_result_t Gpio_SfTimEConfig(en_gpio_sf_tim_e_t enTimE, en_gpio_sf_t enSf);
///< GPIO Timer 捕获输入配置
en_result_t Gpio_SfTimCConfig(en_gpio_sf_tim_c_t enTimC, en_gpio_sf_t enSf);
///< GPIO PCA捕获选择配置
en_result_t Gpio_SfPcaConfig(en_gpio_sf_pca_t enPca, en_gpio_sf_t enSf);
//@} // GpioGroup
#ifdef __cplusplus
}
#endif
#endif /* __GPIO_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,119 @@
/******************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file crc.h
**
** CRC API声明.
**
** - 2016-05-04 LuX V1.0.
**
******************************************************************************/
#ifndef __CRC_H__
#define __HDIV_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup CrcGroup Cyclic Redundancy Check (CRC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
typedef struct stc_div_unsigned_result
{
uint32_t Quotient;
uint32_t Remainder;
}stc_div_unsigned_result_t;
typedef struct stc_div_signed_result
{
int32_t Quotient;
int32_t Remainder;
}stc_div_signed_result_t;
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//HDIV
en_result_t Hdiv_Unsigned(uint32_t Dividend,uint16_t Divisor,stc_div_unsigned_result_t* stcDivResult);
en_result_t Hdiv_Signed(int32_t Dividend,int16_t Divisor,stc_div_signed_result_t* stcDivResult);
boolean_t Hdiv_GetEndState(void);
boolean_t Hdiv_GetZeroState(void);
//@} // CRC Group
#ifdef __cplusplus
}
#endif
#endif /* __CRC_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,167 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file i2c.h
**
** Headerfile for I2C functions
**
**
** History:
** - 2018-03-1 CJ First Version
**
*****************************************************************************/
#ifndef __I2C_H__
#define __I2C_H__
#include "ddl.h"
#include "interrupts_hc32l136.h"
/**
*******************************************************************************
** \defgroup I2cGroup Inter-Integrated Circuit (I2C)
**
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief I2C通道选择
*****************************************************************************/
typedef enum en_i2c_channel
{
I2C0 = 0,///<通道0
I2C1 = 1,///<通道1
}en_i2c_channel_t;
/**
******************************************************************************
** \brief I2C功能配置
*****************************************************************************/
typedef enum en_i2c_func
{
I2cMode_En = 0, ///<I2C模块使能
I2cStart_En = 1, ///<开始信号
I2cStop_En = 2, ///<结束信号
I2cAck_En = 3, ///<应答信号
I2cHlm_En = 4, ///<高速使能
I2cBaud_En = 5, ///<波特率使能
}en_i2c_func_t;
/**
******************************************************************************
** \brief I2C从机地址配置
*****************************************************************************/
typedef struct stc_i2c_addr
{
uint8_t Addr; ///<从机模式地址
uint8_t Gc; ///<广播地址使能
}stc_i2c_addr_t;
/**
******************************************************************************
** \brief I2C初始化配置结构
*****************************************************************************/
typedef struct stc_i2c_config
{
en_i2c_func_t enFunc; ///<功能使能
uint8_t u8Tm; ///<波特率计数器配置
stc_i2c_addr_t stcSlaveAddr;///<从机地址
func_ptr_t pfnI2c0Cb; ///<中断服务函数指针
func_ptr_t pfnI2c1Cb;
boolean_t bTouchNvic; ///<是否使能NVIC
}stc_i2c_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//I2C初始化函数
en_result_t I2C_Init(en_i2c_channel_t enCh,stc_i2c_config_t *pstcI2CCfg);
//I2C模块关闭函数
en_result_t I2C_DeInit(en_i2c_channel_t enCh);
//设置波特率配置寄存器
en_result_t I2C_SetBaud(en_i2c_channel_t enCh,uint8_t u8Tm);
//I2C功能设置函数
en_result_t I2C_SetFunc(en_i2c_channel_t enCh,en_i2c_func_t enFunc);
//I2C功能清除函数
en_result_t I2C_ClearFunc(en_i2c_channel_t enCh,en_i2c_func_t enFunc);
//获取中断标记SI
boolean_t I2C_GetIrq(en_i2c_channel_t enCh);
//清除中断标记SI
en_result_t I2C_ClearIrq(en_i2c_channel_t enCh);
//获取状态
uint8_t I2C_GetState(en_i2c_channel_t enCh);
//写从机地址函数
en_result_t I2C_WriteSlaveAddr(en_i2c_channel_t enCh,stc_i2c_addr_t *pstcSlaveAddr);
//主发送函数
en_result_t I2C_MasterWriteData(en_i2c_channel_t enCh,uint8_t u8DevAddr,uint8_t u8Addr,uint8_t *pu8Data,uint32_t u32Len);
//从发送函数
en_result_t I2C_SlaveWriteData(en_i2c_channel_t enCh,uint8_t *pu8Data,uint32_t *u32Len);
//字节写函数
en_result_t I2C_WriteByte(en_i2c_channel_t enCh,uint8_t u8Data);
//主接收函数
en_result_t I2C_MasterReadData(en_i2c_channel_t enCh,uint8_t u8DevAddr,uint8_t *pu8Data,uint8_t u8Addr,uint32_t u32Len);
//主接收函数
en_result_t I2C_SlaveReadData(en_i2c_channel_t enCh,uint8_t *pu8Data,uint32_t *pu32Len);
//字节读函数
uint8_t I2C_ReadByte(en_i2c_channel_t enCh);
//@} // I2cGroup
#ifdef __cplusplus
#endif
#endif /* __I2C_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file interrupts_hc32l136.h
**
** Interrupt common define.
** @link IRQGroup Some description @endlink
**
** - 2018-04-15 1.0 Lux First version.
**
******************************************************************************/
#ifndef __INTERRUPTS_HC32L136_H__
#define __INTERRUPTS_HC32L136_H__
/******************************************************************************/
/* Include files */
/******************************************************************************/
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define DDL_IRQ_LEVEL_DEFAULT 3u
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
*******************************************************************************
** \brief
** \note
******************************************************************************/
typedef enum en_irq_level
{
IrqLevel0 = 0u, ///< 优先级0
IrqLevel1 = 1u, ///< 优先级1
IrqLevel2 = 2u, ///< 优先级2
IrqLevel3 = 3u, ///< 优先级3
} en_irq_level_t;
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 系统中断使能开关
void EnableNvic(IRQn_Type enIrq, en_irq_level_t enLevel, boolean_t bEn);
#ifdef __cplusplus
}
#endif
#endif /* __INTERRUPTS_HC32L136_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,270 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file lcd.h
**
** Headerfile for LCD functions
**
**
** History:
** - 2018-05-03 CJ First Version
**
*****************************************************************************/
#ifndef __LCD_H__
#define __LCD_H__
#include "ddl.h"
#include "interrupts_hc32l136.h"
/**
*******************************************************************************
** \def group LCD Group LCD
**
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define LCDFULLWRITE 0XFFFFFFFF ///<LCD全显
#define LCDFULLCLEAR 0X00000000 ///<LCD全清
#define LCDRAM0_7SIZE 31
#define LCDRAM8_FSIZE 7
#define LCDRAMSIZE 0x0F
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief LCD bias源选择
*****************************************************************************/
typedef enum en_lcd_biassrc
{
LcdInRes_High = 6,///<内部电阻分压,大功耗模式
LcdInRes_Low = 4,///<内部电阻分压,小功耗模式
LcdInRes_Mid = 2,///<内部电阻分压,中功耗模式
LcdExtCap = 1,///<外部电容分压模式
LcdExtRes = 0,///<外部电阻模式
}en_lcd_biassrc_t;
/**
******************************************************************************
** \brief LCD duty源选择
*****************************************************************************/
typedef enum en_lcd_duty
{
LcdStatic = 0,///<静态
LcdDuty2 = 1,///<1/2duty
LcdDuty3 = 2,///<1/3duty
LcdDuty4 = 3,///<1/4duty
LcdDuty6 = 5,///<1/6duty
LcdDuty8 = 7,///<1/8duty
}en_lcd_duty_t;
/**
******************************************************************************
** \brief LCD bias配置
*****************************************************************************/
typedef enum en_lcd_bias
{
LcdBias3 = 0,///<1/3 BIAS
LcdBias2 = 1,///<1/2 BIAS
}en_lcd_bias_t;
/**
******************************************************************************
** \brief LCD
*****************************************************************************/
typedef enum en_lcd_cpclk
{
LcdClk2k = 0,///<2k
LcdClk4k = 1,///<4k
LcdClk8k = 2,///<8k
LcdClk16k = 3,///<16k
}en_lcd_cpclk_t;
/**
******************************************************************************
** \brief LCD
*****************************************************************************/
typedef enum en_lcd_scanclk
{
LcdClk64hz = 0,///<64hz
LcdClk128hz = 1,///<128hz
LcdClk256hz = 2,///<256hz
LcdClk512hz = 3,///<512hz
}en_lcd_scanclk_t;
/**
******************************************************************************
** \brief LCD功能使能
*****************************************************************************/
typedef enum en_lcd_func
{
LcdEn = 0,///<模块使能
LcdBlinkEn = 1,///<LCD闪屏使能
}en_lcd_func_t;
/**
******************************************************************************
** \brief LCD显示模式
*****************************************************************************/
typedef enum en_lcd_dispmode
{
LcdMode0 = 0,///<模式0
LcdMode1 = 1,///<模式1
}en_lcd_dispmode_t;
/**
******************************************************************************
** \brief LCD时钟源选择
*****************************************************************************/
typedef enum en_lcd_clk
{
LcdXTL = 1,///<外部32k
LcdRCL = 0,///<内部32k
}en_lcd_clk_t;
/**
******************************************************************************
** \brief LCD显示SEG COM端口配置
*****************************************************************************/
typedef struct stc_lcd_segcom
{
uint32_t u32Seg0_31; ///<SEG0-31配置
boolean_t bMux; ///<SEG32-35
uint8_t u8Com0_3; ///<COM0-3配置
union Seg32_39VLcdCom7_4 ///<Seg32_39/Com7_4配置
{
uint8_t SegVLcdCom;
struct
{
uint8_t Seg39Com4 :1;
uint8_t Seg38Com5 :1;
uint8_t Seg37Com6 :1;
uint8_t Seg36Com7 :1;
uint8_t Seg35LcdH :1;
uint8_t Seg34Lcd3 :1;
uint8_t Seg33Lcd2 :1;
uint8_t Seg32Lcd1 :1;
}Bits;
}Seg32_39VLcdCom7_4_t;
}stc_lcd_segcom_t;
/**
******************************************************************************
** \brief LCD端口配置参数
*****************************************************************************/
typedef struct stc_lcd_segcompara
{
en_lcd_duty_t enDuty; ///<占空比
en_lcd_biassrc_t enBiasSrc; ///<时钟源
uint8_t u8MaxSeg; ///<最大SEG口
}stc_lcd_segcompara_t;
/**
******************************************************************************
** \brief I2C初始化配置结构
*****************************************************************************/
typedef struct stc_lcd_config
{
en_lcd_biassrc_t enBiasSrc; ///<Bias源选择
en_lcd_duty_t enDuty; ///<占空比选择
en_lcd_bias_t enBias; ///bias配置
en_lcd_cpclk_t enCpClk; ///<电压泵时钟频率选择
en_lcd_scanclk_t enScanClk; ///<扫描频率选择
en_lcd_dispmode_t enDispMode;///<显示模式选择
en_lcd_clk_t enClk; ///<模块clk选择
boolean_t bTouchNvic; ///<是否使能NVIC
}stc_lcd_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//LCD初始化函数
en_result_t LCD_Init(stc_lcd_config_t *pstcLcdCfg);
//lcd模块关闭函数
en_result_t LCD_DeInit(void);
//lcd 时钟源选择函数
en_result_t LCD_SetClkSrc(en_lcd_clk_t enLcdClk);
//lcd bias源选择函数
en_result_t LCD_SelBiasSrc(en_lcd_biassrc_t enBiasSrc);
//lcd duty配置函数
en_result_t LCD_SetDuty(en_lcd_duty_t enDuty);
//lcd bias配置函数
en_result_t LCD_SetBias(en_lcd_bias_t enBias);
//lcd电压泵时钟频率选择
en_result_t LCD_SelCpClk(en_lcd_cpclk_t enCpClk);
//lcd扫描频率选择
en_result_t LCD_SelScanClk(en_lcd_scanclk_t enScanClk);
//lcd 功能使能禁止函数
en_result_t LCD_EnFunc(en_lcd_func_t enFunc,boolean_t bFlag);
//lcd显示模式函数
en_result_t LCD_SetDispMode(en_lcd_dispmode_t enDispMode);
//lcd对比度设置
en_result_t LCD_SetContrast(uint8_t u8Contrast);
//lcd闪屏计数器设置
en_result_t LCD_SetBlinkCnt(uint8_t u8BlinkCnt);
//lcd中断清除
en_result_t LCD_ClrIntState(void);
//LCD运行模式获取端口配置
en_result_t LCD_GetSegCom(stc_lcd_segcompara_t *pstcSegComPara,stc_lcd_segcom_t *pstcSegCom);
//lcd segcom端口配置
en_result_t LCD_SetSegCom(stc_lcd_segcom_t *pstcSegCom);
//lcd全显
en_result_t LCD_FullDisp(void);
//lcd全清
en_result_t LCD_ClearDisp(void);
//lcd写RAM函数
en_result_t LCD_WriteRam(uint16_t u16Row, uint32_t u32List, boolean_t bData);
en_result_t LCD_WriteRam0_7Int32(uint8_t u8Row,uint32_t u32Data);
en_result_t LCD_WriteRam8_FInt8(uint8_t u8Row,uint8_t u8Data);
//@} // LCDGroup
#ifdef __cplusplus
#endif
#endif /* __LCD_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,147 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file lpm.h
**
** Lpm API声明
**
**
** History:
** - 2017-06-06 Lux V1.0
**
*****************************************************************************/
#ifndef __LPM_H__
#define __LPM_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup LpmGroup Low Power Management (LPM)
**
**
******************************************************************************/
//@{
/******************************************************************************
** Global pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief 使 (SEVONPEND)
*****************************************************************************/
typedef enum en_lpm_sevonpend
{
SevPndDisable = 0u, ///< 事件挂起禁止
SevPndEnable = 1u, ///< 事件挂起使能
}en_lpm_sevonpend_t;
/**
******************************************************************************
** \brief 使 (SLEEPDEEP)
*****************************************************************************/
typedef enum en_lpm_sleepdeep
{
SlpDpDisable = 0u, ///< 深度睡眠禁止
SlpDpEnable = 1u, ///< 深度睡眠使能
}en_lpm_sleepdeep_t;
/**
******************************************************************************
** \brief 退使 (SLEEPONEXIT)
*****************************************************************************/
typedef enum en_lpm_sleeponexit
{
SlpExtDisable = 0u, ///< 异常退出进睡眠禁止
SlpExtEnable = 1u, ///< 异常退出进睡眠使能
}en_lpm_sleeponexit_t;
/**
******************************************************************************
** \brief Low Power Mode
*****************************************************************************/
typedef struct stc_lpm_config
{
en_lpm_sevonpend_t enSEVONPEND; ///< 使能:每次新中断会产生一个事件,如果使用WFE休眠,则可用于唤醒处理器.
en_lpm_sleepdeep_t enSLEEPDEEP; ///< 使能:执行WFI进入深度休眠;不使能:执行WFI进入休眠.
en_lpm_sleeponexit_t enSLEEPONEXIT; ///< 使能:退出异常处理并返回时,处理器自动进入休眠模式;不使能:该特性禁止.
}stc_lpm_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
///<功能配置及操作函数
///<低功耗模式配置
en_result_t Lpm_Config(stc_lpm_config_t* pstcConfig);
///<进入低功耗模式
void Lpm_GotoLpmMode(void);
//@} // LpmGroup
#ifdef __cplusplus
#endif
#endif /* __LPM_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,211 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file lpt.h
**
** API声明
**
**
** History:
** - 2018-04-15 Husj First version
**
*****************************************************************************/
#ifndef __LPT_H__
#define __LPT_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
*******************************************************************************
** \defgroup LptGroup Low Power Timer (LPT)
**
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief GATE (GATE_P)
*****************************************************************************/
typedef enum en_lpt_gatep
{
LptActHighLevel = 0u, ///< 高电平有效
LptActLowLevel = 1u, ///< 低电平有效
}en_lpt_gatep_t;
/**
******************************************************************************
** \brief (GATE)
*****************************************************************************/
typedef enum en_lpt_gate
{
LptGateDisable = 0u, ///< 无门控
LptGateEnable = 1u, ///< 门控使能
}en_lpt_gate_t;
/**
******************************************************************************
** \brief Lptimer (TCK_SEL)
*****************************************************************************/
typedef enum en_lpt_clksel
{
LptPCLK = 0u, ///< PCLK
LptXIL32K = 2u, ///< XIL32K
LptIRC32K = 3u, ///< IRC32K
}en_lpt_clksel_t;
/**
******************************************************************************
** \brief 使 (TOG_EN)
*****************************************************************************/
typedef enum en_lpt_toggle
{
LptTogDisable = 0u, ///< 翻转输出禁止
LptTogEnable = 1u, ///< 翻转输出使能
}en_lpt_toggle_t;
/**
******************************************************************************
** \brief / (CT)
*****************************************************************************/
typedef enum en_lpt_function
{
LptTimer = 0u, ///< 定时器功能
LptCounter = 1u, ///< 计数器功能
}en_lpt_function_t;
/**
******************************************************************************
** \brief (MD)
*****************************************************************************/
typedef enum en_lpt_mode
{
Lpt16bitFreeMode = 0u, ///< 无重载16位计数器/定时器
Lpt16bitArrMode = 1u, ///< 自动重装载16位计数器/定时器
}en_lpt_mode_t;
/**
******************************************************************************
** \brief (TR)
*****************************************************************************/
typedef enum en_lpt_start
{
LptTRDisable = 0u, ///< 停止
LptTREnable = 1u, ///< 运行
}en_lpt_start_t;
/**
******************************************************************************
** \brief Lptimer
*****************************************************************************/
typedef struct stc_lpt_config
{
en_lpt_gatep_t enGateP; ///< 门控极性控制
en_lpt_gate_t enGate; ///< 门控使能
en_lpt_clksel_t enTckSel; ///< 时钟选择
en_lpt_toggle_t enTog; ///< 翻转输出使能
en_lpt_function_t enCT; ///< 定时/计数模式选择
en_lpt_mode_t enMD; ///< 工作模式选择
func_ptr_t pfnLpTimCb; ///< LpTimer中断服务回调函数[void function(void)]
}stc_lpt_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//中断相关函数
//中断标志获取
boolean_t Lpt_GetIntFlag(void);
//中断标志清除
en_result_t Lpt_ClearIntFlag(void);
//中断使能/禁止
en_result_t Lpt_EnableIrq (void);
en_result_t Lpt_DisableIrq(void);
//初始化及相关功能操作
//Lptimer配置及初始化
en_result_t Lpt_Init(stc_lpt_config_t* pstcConfig);
//Lptimer 启动/停止
en_result_t Lpt_Run(void);
en_result_t Lpt_Stop(void);
//重载值设置
en_result_t Lpt_ARRSet(uint16_t u16Data);
//计数值获取
en_result_t Lpt_Cnt16Set(uint16_t u16Data);
uint16_t Lpt_Cnt16Get(void);
//@} // LptGroup
#ifdef __cplusplus
#endif
#endif /* __LPT_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,325 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file uart.h
**
** Headerfile for LPUART functions
**
**
** History:
** - 2017-05-10 Cathy First Version
**
*****************************************************************************/
#ifndef __LPUART_H__
#define __LPUART_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup LPUartGroup Universal Asynchronous Receiver/Transmitter (LPUART)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
**\brief LPuart通道选择
******************************************************************************/
typedef enum en_lpuart_channel
{
LPUART0 = 0u, ///<串口2
LPUART1 = 1u, ///<串口3
}en_lpuart_channel_t;
/**
******************************************************************************
** \brief lpuart sclk时钟源选择
******************************************************************************/
typedef enum en_lpuart_sclk_sel
{
LPUart_Pclk = 0u, ///<pclk
LPUart_Pclk_1 = 1u, ///<pclk
LPUart_Xtl = 2u, ///<外部低速晶振
LPUart_Rcl = 3u, ///<内部低速晶振
} en_lpuart_sclksel_t;
/**
******************************************************************************
** \brief lpuart多主机模式地址帧/
******************************************************************************/
typedef enum en_lpuart_mmdorck
{
LPUartDataOrAddr = 0u, ///<多主机模式时通过读写SBUF[8]决定帧为数据帧或地址帧
LPUartEven = 1u, ///<非多主机模式偶校验
LPUartOdd = 2u, ///<非多主机模式奇校验
}en_lpuart_mmdorck_t;
/**
******************************************************************************
** \brief lpuart多主机模式配置
******************************************************************************/
typedef enum en_lpuart_multimode
{
LPUartNormal = 0u, ///<正常工作模式
LPUartMulti = 1u, ///<多主机工作模式
}en_lpuart_multimode_t;
/**
******************************************************************************
** \brief lpuart多主机模式及从机地址和地址掩码配置
******************************************************************************/
typedef struct stc_lpuart_multimode
{
en_lpuart_multimode_t enMulti_mode; ///<多主机模式配置
uint8_t u8SlaveAddr; ///<从机地址
uint8_t u8SaddEn; ///<从及地址掩码
}stc_lpuart_multimode_t;
/**
******************************************************************************
** \brief lpuart
******************************************************************************/
typedef enum en_lpuart_mode
{
LPUartMode0 = 0u, ///<模式0
LPUartMode1 = 1u, ///<模式1
LPUartMode2 = 2u, ///<模式2
LPUartMode3 = 3u, ///<模式3
} en_lpuart_mode_t;
/**
******************************************************************************
** \brief lpuart stop长度选择
******************************************************************************/
typedef enum en_lpuart_stop
{
LPUart1bit = 0u, ///<1位停止位
LPUart15bit = 1u, ///<1.5位停止位
LPUart2bit = 2u, ///<2位停止位
} en_lpuart_stop_t;
/**
******************************************************************************
** \brief lpuart 使
******************************************************************************/
typedef enum en_lpuart_func
{
LPUartTx = 0u, ///<mode0模式代表TX
LPUartRx = 1u, ///<非mode0模式代表RX and TX ,mode0模式代表RX
LPUartDmaTx = 3u, ///<DMA发送使能
LPUartDmaRx = 4u, ///<DMA接收使能
LPUartCtsRts = 5u, ///<硬件流使能
}en_lpuart_func_t;
/**
******************************************************************************
** \brief lpuart中断使能控制
******************************************************************************/
typedef enum en_lpuart_irq_sel
{
LPUartTxIrq = 0u, ///<发送中断使能
LPUartRxIrq = 1u, ///<接收中断使能
LPUartFEIrq = 3u, ///<帧错误中断使能
LPUartCtsIrq = 4u, ///<CTS信号翻转中断使能
LPUartPEIrq = 5u, ///<奇偶校验中断使能
LPUartTxEIrq = 6u, ///<TX空中断使能
}en_lpuart_irq_sel_t;
/**
******************************************************************************
** \brief lpuart发送接收中断处理函数接口
******************************************************************************/
typedef struct stc_lpuart_irq_cb
{
func_ptr_t pfnTxIrqCb; ///<发送中断服务函数
func_ptr_t pfnRxFEIrqCb; ///<接收帧错误中断服务函数
func_ptr_t pfnRxIrqCb; ///<接收中断服务函数
func_ptr_t pfnCtsIrqCb; ///<CTS信号翻转中断服务函数
func_ptr_t pfnPEIrqCb; ///<奇偶校验错误中断服务函数
}stc_lpuart_irq_cb_t;
/**
******************************************************************************
** \brief lpuart
******************************************************************************/
typedef enum en_lpuart_status
{
LPUartCts = 0u, ///<CTS信号标记
LPUartRC = 1u, ///<接收数据完成标记
LPUartTC = 2u, ///<发送数据完成标记
LPUartPE = 3u, ///<奇偶校验错误标记
LPUartFE = 4u, ///<帧错误标记
LPUartCtsIf = 5u, ///CTS中断标志
LPUartTxe = 6u, ///TXbuff空标记
}en_lpuart_status_t;
/**
******************************************************************************
** \brief lpuart
******************************************************************************/
typedef struct stc_lpuart_instance_data
{
uint32_t u32Idx; ///< 通道号
M0P_LPUART_TypeDef *pstcInstance; ///< 通道寄存器地址
stc_lpuart_irq_cb_t stcLPUartInternIrqCb; ///< 通道中断服务函数
} stc_lpuart_instance_data_t;
/**
******************************************************************************
** \brief lpuart
******************************************************************************/
typedef enum en_lpuart_clkdiv
{
LPUart16Or32Div = 0u,///<模式0无效模式1/3为16分频模式2为32分频
LPUart8Or16Div = 1u,///<模式0无效模式1/3为8分频模式2为16分频
LPUart4Or8Div = 2u,///<模式0无效模式1/3为4分频模式2为8分频
}en_lpuart_clkdiv_t;
/**
******************************************************************************
** \brief lpuart
******************************************************************************/
typedef struct stc_lpuart_sclk_sel
{
en_lpuart_clkdiv_t enSclk_Prs; ///<分频选择
en_lpuart_sclksel_t enSclk_sel; ///<传输时钟选择
}stc_lpuart_sclk_sel_t;
/**
******************************************************************************
** \brief lpuart
******************************************************************************/
typedef struct stc_lpuart_baud
{
uint32_t u32Sclk; ///<sclk
en_lpuart_mode_t enRunMode; ///< 四种模式配置
uint32_t u32Baud; ///< 波特率
} stc_lpuart_baud_t;
/**
******************************************************************************
** \lpuart
******************************************************************************/
typedef struct stc_lpuart_config
{
en_lpuart_mode_t enRunMode; ///< 四种模式配置
stc_lpuart_sclk_sel_t* pstcLpuart_clk; ///<时钟源配置
en_lpuart_stop_t enStopBit; ///<停止位长度
stc_lpuart_multimode_t* pstcMultiMode; ///<多主机模式配置
stc_lpuart_irq_cb_t* pstcIrqCb; ///<中断服务函数
boolean_t bTouchNvic; ///<NVIC中断使能
} stc_lpuart_config_t;
//中断相关设置函数
en_result_t LPUart_EnableIrq(uint8_t u8Idx,
en_lpuart_irq_sel_t enIrqSel);
en_result_t LPUart_DisableIrq(uint8_t u8Idx,
en_lpuart_irq_sel_t enIrqSel);
// 总初始化处理
en_result_t LPUart_Init(uint8_t u8Idx,
stc_lpuart_config_t* pstcConfig);
//LPUART模块工作模式设置函数
en_result_t LPUart_SetMode(uint8_t u8Idx,en_lpuart_mode_t enMode);
//LPUART模块工作模式设置函数
en_result_t LPUart_SetMultiMode(uint8_t u8Idx,stc_lpuart_multimode_t* pstcMultiConfig);
//LPUART通道多主机模式发送数据/地址帧或者奇偶校验配置TB8
en_result_t LPUart_SetMMDOrCk(uint8_t u8Idx,en_lpuart_mmdorck_t enTb8);
//从机地址配置
en_result_t LPUart_SetSaddr(uint8_t u8Idx,uint8_t u8Addr);
//从机地址掩码配置
en_result_t LPUart_SetSaddrEn(uint8_t u8Idx,uint8_t u8Addren);
//停止位配置
en_result_t LPUart_SetStopBit(uint8_t u8Idx,uint8_t u8Len);
//数据寄存器bit8位获取
boolean_t LPUart_GetRb8(uint8_t u8Idx);
//时钟源选择
en_result_t LPUart_SelSclk(uint8_t u8Idx,en_lpuart_sclksel_t enClk);
//时钟源时钟获取
uint32_t LPUart_GetSclk(uint8_t u8Idx);
//采样分频设置
en_result_t LPUart_SetClkDiv(uint8_t u8Idx,en_lpuart_clkdiv_t enClkDiv);
//波特率设置值计算
uint16_t LPUart_CalScnt(uint8_t u8Idx,stc_lpuart_baud_t *pstcBaud);
//波特率设置
en_result_t LPUart_SetBaud(uint8_t u8Idx,uint16_t u16Scnt);
//获取波特率
uint32_t LPUart_GetBaud(uint8_t u8Idx,uint8_t u8Mode,uint32_t u32Pclk);
//功能使能和禁止
en_result_t LPUart_EnableFunc(uint8_t u8Idx, en_lpuart_func_t enFunc);
en_result_t LPUart_DisableFunc(uint8_t u8Idx, en_lpuart_func_t enFunc);
//某个状态bit获取函数
boolean_t LPUart_GetStatus(uint8_t u8Idx,en_lpuart_status_t enStatus);
//某个状态bit状态位的清除
en_result_t LPUart_ClrStatus(uint8_t u8Idx,en_lpuart_status_t enStatus);
//整个状态寄存器获取
uint8_t LPUart_GetIsr(uint8_t u8Idx);
//整个状态寄存器清除
en_result_t LPUart_ClrIsr(uint8_t u8Idx);
//数据查询方式的发送操作
en_result_t LPUart_SendData(uint8_t u8Idx, uint8_t u8Data);
//数据查询方式的接收操作
uint8_t LPUart_ReceiveData(uint8_t u8Idx);
//@} // LPUartGroup
#ifdef __cplusplus
#endif
#endif /* __UART_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,208 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file lvd.h
**
** Headerfile for Low Voltage Detector functions
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
#ifndef __LVD_H__
#define __LVD_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup LvdGroup Low Voltage Detector (LVD)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief LVD输入电压源
**
** \note
******************************************************************************/
typedef enum en_lvd_input
{
LvdInputVCC = 0u, ///< Vcc
LvdInputPC13 = 1u, ///< PC13
LvdInputPB08 = 2u, ///< PB08
LvdInputPB07 = 3u, ///< PB07
}en_lvd_input_t;
/**
******************************************************************************
** \brief LVD监测电压选择
**
** \note
******************************************************************************/
typedef enum en_lvd_threshold
{
LvdTH1p8V = 0u, ///< 1.8V
LvdTH1p9V = 1u, ///< 1.9V
LvdTH2p0V = 2u, ///< 2.0V
LvdTH2p1V = 3u, ///< 2.1V
LvdTH2p2V = 4u, ///< 2.2V
LvdTH2p3V = 5u, ///< 2.3V
LvdTH2p4V = 6u, ///< 2.4V
LvdTH2p5V = 7u, ///< 2.5V
LvdTH2p6V = 8u, ///< 2.6V 默认电压
LvdTH2p7V = 9u, ///< 2.7V
LvdTH2p8V = 10u, ///< 2.8V
LvdTH2p9V = 11u, ///< 2.9V
LvdTH3p0V = 12u, ///< 3.0V
LvdTH3p1V = 13u, ///< 3.1V
LvdTH3p2V = 14u, ///< 3.2V
LvdTH3p3V = 15u, ///< 3.3V
}en_lvd_threshold_t;
/**
******************************************************************************
** \brief LVD输出滤波时间
**
** \note
******************************************************************************/
typedef enum en_lvd_filter_time
{
LvdFilter30us = 0u, ///< 30us
LvdFilter40us = 1u, ///< 40us
LvdFilter50us = 2u, ///< 50us
LvdFilter130us = 3u, ///< 130us
LvdFilter480us = 4u, ///< 480us
LvdFilter1800us = 5u, ///< 1.8ms
LvdFilter7d3ms = 6u, ///< 7.3ms
LvdFilter29ms = 7u, ///< 29ms
}en_lvd_filter_time_t;
/**
******************************************************************************
** \brief LVD中断触发方式
**
** \note
******************************************************************************/
typedef enum en_lvd_irq_type
{
LvdIrqHigh = 0u, ///< 高电平触发
LvdIrqRise = 1u, ///< 上升沿触发
LvdIrqFall = 2u, ///< 下降沿触发
}en_lvd_irq_type_t;
/**
******************************************************************************
** \brief LVD配置
** \note
******************************************************************************/
typedef struct stc_lvd_config
{
boolean_t bLvdReset; ///< TRUE-重启,FALSE-中断
en_lvd_input_t enInput; ///< LVD输入电压源
en_lvd_threshold_t enThreshold; ///< LVD监测电压
boolean_t bFilter; ///< 是否使用输出滤波
en_lvd_filter_time_t enFilterTime; ///< 输出滤波时间
en_lvd_irq_type_t enIrqType; ///< 中断触发方式
func_ptr_t pfnIrqCbk; ///< 中断回调函数
}stc_lvd_config_t;
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//irq enable/disable
en_result_t Lvd_EnableIrq(en_lvd_irq_type_t enType);
void Lvd_DisableIrq(void);
// irq function
void Lvd_ClearIrq(void);
boolean_t Lvd_GetIrqStat(void);
// fliter function
boolean_t Lvd_GetFilterResult(void);
//init/deinit function
void Lvd_Init(stc_lvd_config_t *pstcConfig);
void Lvd_DeInit(void);
//LVD function enable/disable
void Lvd_Enable(void);
void Lvd_Disable(void);
//@} // LvdGroup
#ifdef __cplusplus
}
#endif
#endif /* __LVD_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,205 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file OPA.h
**
** Headerfile for OPA functions
** @link OPA Group Some description @endlink
**
** History:
** - 2018-04-15 Devi First Version
**
******************************************************************************/
#ifndef __OPA_H__
#define __OPA_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup OPAGroup (OPA)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/**
*******************************************************************************
** \brief OPA通道选择
** \note
******************************************************************************/
typedef enum en_opa_channel
{
OPA0 = 0u, ///<<OPA0
OPA1 = 1u, ///<<OPA1
OPA2 = 2u, ///<<OPA2
}en_opa_channel_t;
/**
*******************************************************************************
** \brief OPA反向增益选择
** \note
******************************************************************************/
typedef enum en_opa_invert_pagagain
{
Gain15 = 0u, ///< 反向增益15倍
Gain07 = 1u, ///< 反向增益7倍
Gain13_3 = 2u, ///< 反向增益13/3倍
Gain03 = 3u, ///< 反向增益3倍
Gain05_3 = 4u, ///< 反向增益5/3倍
Gain01 = 5u, ///< 反向增益1倍
Gain01_3 = 6u, ///< 反向增益1/3倍
Gain11_5 = 7u, ///< 反向增益11/5倍
}en_opa_invert_pagagain_t;
/**
*******************************************************************************
** \brief OPA正向增益选择
** \note
******************************************************************************/
typedef enum en_opa_noinvert_pagagain
{
Gain16 = 0u, ///< 正向增益16倍
Gain08 = 1u, ///< 正向增益8倍
Gain16_3 = 2u, ///< 正向增益16/3倍
Gain04 = 3u, ///< 正向增益4倍
Gain08_3 = 4u, ///< 正向增益8/3倍
Gain02 = 5u, ///< 正向增益2倍
Gain04_3 = 6u, ///< 正向增益4/3倍
Gain16_5 = 7u, ///< 正向增益16/5倍
}en_opa_noinvert_pagagain_t;
/**
*******************************************************************************
** \brief
******************************************************************************/
typedef enum opa_metergain
{
OpaMeterGain3 = 0u,
OpaMeterGain1_3 = 1u,
OpaMeterGain1 = 2u,
}en_opa_metergain_t;
/**
*******************************************************************************
** \brief opa
******************************************************************************/
typedef enum opa_modesel
{
OpaUintMode = 0u, ///< PGA单位增益
OpaForWardMode = 1u, ///< 正向输入PGA
OpaOppositeMode = 2u, ///< 反向输入PGA
OpaThreeOppMode = 3u, ///< 3个OPA级联反向输入PGA
OpaThreeForMode = 4u, ///< 3个OPA级联正向输入PGA
OpaDiffMode = 5u, ///< 两运放差分输入PGA
OpaMeterMode = 6u, ///< 仪表放大器
OpaGpMode = 7u, ///< 通用运放
}en_opa_modesel_t;
/**
*******************************************************************************
** \brief opa
******************************************************************************/
typedef enum opa_calsel
{
OpaSoftMode = 0u, ///< 软件控制
OpaSoftTriggerMode = 1u, ///< 软件触发
OpaADCTriggerMode = 2u, ///< ADC触发
}en_opa_calsel_t;
/**
******************************************************************************
** \brief OPA增益配置
*****************************************************************************/
typedef struct stc_opa_gain_config
{
en_opa_invert_pagagain_t enInGain; ///< 反向增益
en_opa_noinvert_pagagain_t enNoInGain; ///< 正向增益
}stc_opa_gain_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< OPA初始化
en_result_t OPA_Init(void);
///< OPA去初始化
en_result_t OPA_DeInit(void);
///< OPA基本功能设置
en_result_t OPA_Operate(en_opa_channel_t enchannel ,en_opa_modesel_t enMode,stc_opa_gain_config_t *pstrGain);
///< OPA三级联设置
en_result_t OPA_ThreeOperate(en_opa_modesel_t enMode,stc_opa_gain_config_t *pstrGain0,stc_opa_gain_config_t *pstrGain1,stc_opa_gain_config_t *pstrGain2);
///< OPA 仪表模式
en_result_t OPA_MeterOperate(en_opa_metergain_t enGainMode);
///< OPA校正模式
en_result_t OPA_Cal(en_opa_calsel_t enCalMode);
//@} // OPA Group
#ifdef __cplusplus
#endif
#endif /* __OPA_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,301 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file pca.h
**
** PCAAPI声明
**
**
** History:
** - 2017-04-15 Husj First version
**
*****************************************************************************/
#ifndef __PCA_H__
#define __PCA_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup PcaGroup Programmable Counter Array (PCA)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief PCA
*****************************************************************************/
typedef enum en_pca_module
{
Module0 = 0u, ///< 模块0
Module1 = 1u, ///< 模块1
Module2 = 2u, ///< 模块2
Module3 = 3u, ///< 模块3
Module4 = 4u, ///< 模块4
}en_pca_module_t;
/**
******************************************************************************
** \brief PCA / (CR)
*****************************************************************************/
typedef enum en_pca_start
{
CRStop = 0u, ///< 停止计数
CRStart = 1u, ///< 开始计数
}en_pca_start_t;
/**
******************************************************************************
** \brief PCA IDLE / (CIDL)
*****************************************************************************/
typedef enum en_pca_cidl
{
IdleGoOn = 0u, ///< 休眠模式下 PCA继续工作
IdleStop = 1u, ///< 休眠模式下 PCA停止工作
}en_pca_cidl_t;
/**
******************************************************************************
** \brief PCA 4 WDT功能控制数据类型重定义 (WDTE)
*****************************************************************************/
typedef enum en_pca_wdte
{
PCAWDTDisable = 0u, ///< 关闭 PCA模块4 WDT功能
PCAWDTEnable = 1u, ///< 启动 PCA模块4 WDT功能
}en_pca_wdte_t;
/**
******************************************************************************
** \brief PCA (CPS)
*****************************************************************************/
typedef enum en_pca_clksel
{
PCAPCLKDiv32 = 0u, ///< PCLK/32
PCAPCLKDiv16 = 1u, ///< PCLK/16
PCAPCLKDiv8 = 2u, ///< PCLK/8
PCAPCLKDiv4 = 3u, ///< PCLK/4
PCAPCLKDiv2 = 4u, ///< PCLK/2
PCATimer0Over = 5u, ///< timer0 overflow
PCATimer1Over = 6u, ///< timer1 overflow
PCAECI = 7u, ///< ECI 外部时钟,时钟PCLK四分频采样
}en_pca_clksel_t;
/**
******************************************************************************
** \brief PCA (ECOM)
*****************************************************************************/
typedef enum en_pca_ecom
{
ECOMDisable = 0u, ///< 禁止比较器功能
ECOMEnable = 1u, ///< 允许比较器功能
}en_pca_ecom_t;
/**
******************************************************************************
** \brief PCA 沿 (CAPP)
*****************************************************************************/
typedef enum en_pca_capp
{
CAPPDisable = 0u, ///< 禁止上升沿捕获
CAPPEnable = 1u, ///< 允许上升沿捕获
}en_pca_capp_t;
/**
******************************************************************************
** \brief PCA 沿 (CAPN)
*****************************************************************************/
typedef enum en_pca_capn
{
CAPNDisable = 0u, ///< 禁止下降沿捕获
CAPNEnable = 1u, ///< 允许下降沿捕获
}en_pca_capn_t;
/**
******************************************************************************
** \brief PCA (MAT)
*****************************************************************************/
typedef enum en_pca_mat
{
MATDisable = 0u, ///< 禁止匹配
MATEnable = 1u, ///< 允许匹配
}en_pca_mat_t;
/**
******************************************************************************
** \brief PCA (TOG)
*****************************************************************************/
typedef enum en_pca_tog
{
TOGDisable = 0u, ///< 禁止翻转功能
TOGEnable = 1u, ///< 允许翻转功能
}en_pca_tog_t;
/**
******************************************************************************
** \brief PCA 8bit脉宽调制控制数据类型重定义 (8bitPWM)
*****************************************************************************/
typedef enum en_pca_pwm_8_bit
{
PCA8bitPWMDisable = 0u, ///< 禁止 PWM功能
PCA8bitPWMEnable = 1u, ///< 允许CCPx引脚作为PWM输出
}en_pca_8bit_pwm_t;
/**
******************************************************************************
** \brief PCA 16bit脉宽调制控制数据类型重定义 (16bitPWM)
*****************************************************************************/
typedef enum en_pca_pwm_16_bit
{
PCA16bitPWMDisable = 0u, ///< 16bitPWM 禁止
PCA16bitPWMEnable = 1u, ///< 16bitPWM 使能
}en_pca_16bit_pwm_t;
/**
******************************************************************************
** \brief PCA
*****************************************************************************/
typedef struct stc_pca_config
{
en_pca_cidl_t enCIDL; ///< 模式下启/停控制
en_pca_wdte_t enWDTE; ///< WDT功能控制
en_pca_clksel_t enCPS; ///< 时钟分频及时钟源选择功能
func_ptr_t pfnPcaCb; ///< Pca中断服务回调函数[void function(void)]
}stc_pca_config_t;
/**
******************************************************************************
** \brief PCA
*****************************************************************************/
typedef struct stc_pca_capmodconfig
{
en_pca_ecom_t enECOM; ///< 允许比较器功能控制
en_pca_capp_t enCAPP; ///< 正沿捕获控制
en_pca_capn_t enCAPN; ///< 负沿捕获控制
en_pca_mat_t enMAT; ///< 匹配控制
en_pca_tog_t enTOG; ///< 翻转控制
en_pca_8bit_pwm_t en8bitPWM; ///< 8位脉宽调制控制
}stc_pca_capmodconfig_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//Interrupt related
//PCA中断标志获取
boolean_t Pca_GetIntFlag(en_pca_module_t enModule);
//PCA计数器中断标志获取
boolean_t Pca_GetCntIntFlag(void);
//PCA中断标志清除
en_result_t Pca_ClearIntFlag(en_pca_module_t enModule);
//PCA计数器中断标志清除
en_result_t Pca_ClearCntIntFlag(void);
//PCA中断使能
en_result_t Pca_EnableIrq (en_pca_module_t enModule);
//PCA计数器中断使能
en_result_t Pca_EnableCntIrq (void);
//PCA中断关闭
en_result_t Pca_DisableIrq(en_pca_module_t enModule);
//PCA计数器中断关闭
en_result_t Pca_DisableCntIrq(void);
//PCA配置及操作
//PCA初始化
en_result_t Pca_Init(stc_pca_config_t* pstcConfig);
//PCA捕获模式配置
en_result_t Pca_CapModConfig(en_pca_module_t enModule, stc_pca_capmodconfig_t* pstcCapMod);
//PCA计数器启动/停止
en_result_t Pca_Run(void);
en_result_t Pca_Stop(void);
//PCA16位比较数据设置
en_result_t Pca_CmpData16Set(en_pca_module_t enModule, uint16_t u16Data);
//PCA捕获16位数据获取
uint16_t Pca_CapData16Get(en_pca_module_t enModule);
//PCA比较数据高8位设置
en_result_t Pca_CmpDataHSet(en_pca_module_t enModule, uint8_t u8Data);
//PCA比较数据低8位设置
en_result_t Pca_CmpDataLSet(en_pca_module_t enModule, uint8_t u8Data);
//PCA计数值设置/获取
en_result_t Pca_Cnt16Set(uint16_t u16Data);
uint16_t Pca_Cnt16Get(void);
//PCA周期重载值设置/获取
en_result_t Pca_CARRSet(uint16_t u16Data);
uint16_t Pca_CARRGet(void);
//PCA 增强PWM功能使能/禁止
en_result_t Pca_Enable16bitPWM(void);
en_result_t Pca_Disable16bitPWM(void);
//PCA比较高速输出标志获取
boolean_t Pca_GetCmpHighFlag(en_pca_module_t enModule);
//@} // PcaGroup
#ifdef __cplusplus
#endif
#endif /* __PCA_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,214 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file pcnt.h
**
** Headerfile for PCNT functions
** @link PCNT Group Some description @endlink
**
** History:
** - 2018-04-15 Devi First Version
**
******************************************************************************/
#ifndef __PCNT_H__
#define __PCNT_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup PCNTGroup (PCNT)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/**
*******************************************************************************
** \brief PCNT S1通道极性选择
** \note
******************************************************************************/
typedef enum en_pcnt_s1sel
{
S1P_Noinvert = 0u, ///<<S1通道极性不取反
S1P_Invert = 1u, ///<<S1通道极性取反
}en_pcnt_s1sel_t;
/**
*******************************************************************************
** \brief PCNT S0通道极性选择
** \note
******************************************************************************/
typedef enum en_pcnt_s0sel
{
S0P_Noinvert = 0u, ///<<S0通道极性不取反
S0P_Invert = 1u, ///<<S0通道极性取反
}en_pcnt_s0sel_t;
/**
*******************************************************************************
** \brief PCNT
** \note
******************************************************************************/
typedef enum en_pcnt_direcsel
{
Direct_Add = 0u, ///<<加计数
Direct_Sub = 1u, ///<<减计数
}en_pcnt_direcsel_t;
/**
*******************************************************************************
** \brief PCNT
** \note
******************************************************************************/
typedef enum en_pcnt_clksel
{
CLK_Pclk = 1u, ///<<PCLK
CLK_Xtl = 2u, ///<<XTL
CLK_Rcl = 3u, ///<<RCL
}en_pcnt_clksel_t;
/**
*******************************************************************************
** \brief PCNT
** \note
******************************************************************************/
typedef enum en_pcnt_modesel
{
Single_Mode = 1u, ///<<单通道脉冲计数模式
Special_Mode = 2u, ///<<双通道非正交脉冲计数模式
Double_Mode = 3u, ///<<双通道正交脉冲计数模式
}en_pcnt_modesel_t;
/**
******************************************************************************
** \brief PCNT
*****************************************************************************/
typedef enum en_pcnt_status
{
PCNT_S1E = 0x80, ///<S1通道脉冲解码错误
PCNT_S0E = 0x40, ///<S0通道脉冲解码错误
PCNT_BB = 0x20, ///<脉冲解码错误
PCNT_FE = 0x10, ///<采样周期脉冲解码错误
PCNT_DIR = 0x08, ///<反向改变中断
PCNT_TO = 0x04, ///<超时中断标识
PCNT_OV = 0x02, ///<上溢中断标识
PCNT_UF = 0x01, ///<下溢中断标识
}en_pcnt_status_t;
/**
******************************************************************************
** \brief PCNT
*****************************************************************************/
typedef struct stc_pcnt_config
{
en_pcnt_s1sel_t bS1Sel; ///< S1通道极性选择
en_pcnt_s0sel_t bS0Sel; ///< S0通道极性选择
en_pcnt_direcsel_t u8Direc; ///< 计数方向选择
en_pcnt_clksel_t u8Clk; ///< 计数时钟选择
en_pcnt_modesel_t u8Mode; ///< 脉冲计数模式选择
boolean_t bFLTEn; ///< 滤波控制使能
uint8_t u8FLTDep; ///< 滤波阀值
uint8_t u8FLTClk; ///< 滤波时钟
boolean_t bTOEn; ///< 超时使能
uint16_t u16TODep; ///< 超时阀值
uint8_t u8IrqStatus; ///< 中断方式
boolean_t bIrqEn; ///< 中断使能
func_ptr_t pfnIrqCb; ///< 中断回调函数
}stc_pcnt_config_t;
//PCNT 中断
void Pcnt_IRQHandler(void);
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< PCNT初始化
en_result_t PCNT_Init(stc_pcnt_config_t* pstcPcntConfig);
///< PCNT去初始化
void PCNT_DeInit(void);
///< PCNT 参数设置
en_result_t PCNT_Parameter(uint8_t start,uint8_t end);
///< PCNT 读取PCNT 方向
en_pcnt_direcsel_t PCNT_Direction(void);
///< PCNT 读取PCNT 计数值
uint16_t PCNT_Count(void);
///< PCNT 读取PCNT 溢出值
uint16_t PCNT_TopCount(void);
///< PCNT 设置PCNT
void PCNT_Run(boolean_t work);
///< PCNT获取状态
boolean_t PCNT_GetStatus(en_pcnt_status_t enStatus);
///< PCNT清除状态
void PCNT_ClrStatus(en_pcnt_status_t enStatus);
///< PCNT设置中断
void PCNT_SetIrqStatus(en_pcnt_status_t enStatus);
//@} // PCNT Group
#ifdef __cplusplus
#endif
#endif /* __PCNT_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,166 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file reset.h
**
** Headerfile for reset functions
**
**
** History:
** - 2018-04-21 Lux First Version
**
******************************************************************************/
#ifndef __RESET_H__
#define __RESET_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup ResetGroup Reset (RST)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/*******************************************************************************
* Global definitions
******************************************************************************/
/**
*******************************************************************************
** \brief
** \note
******************************************************************************/
typedef enum
{
ResetUart0 = 0x00000001u, ///< 串口0
ResetUart1 = 0x00000002u, ///< 串口1
ResetLpUart0 = 0x00000004u, ///< 低功耗串口0
ResetLpUart1 = 0x00000008u, ///< 低功耗串口1
ResetI2c0 = 0x00000010u, ///< I2C0
ResetI2c1 = 0x00000020u, ///< I2C1
ResetSpi0 = 0x00000040u, ///< SPI0
ResetSpi1 = 0x00000080u, ///< SPI1
ResetBaseTim = 0x00000100u, ///< BASETIM
ResetLpTim = 0x00000200u, ///< LPTIM
ResetAdvTim = 0x00000400u, ///< ADVTIM
ResetTim3 = 0x00000800u, ///< TIM3
ResetOpa = 0x00002000u, ///< OPA
ResetPca = 0x00004000u, ///< PCA
ResetAdc = 0x00010000u, ///< ADC
ResetVc = 0x00020000u, ///< VC
ResetRng = 0x00040000u, ///< RNG
ResetPcnt = 0x00080000u, ///< PCNT
ResetRtc = 0x00100000u, ///< RTC
ResetTrim = 0x00200000u, ///< TRIM
ResetLcd = 0x00400000u, ///< LCD
ResetTick = 0x01000000u, ///< TICK
ResetSwd = 0x02000000u, ///< SWD
ResetCrc = 0x04000000u, ///< CRC
ResetAes = 0x08000000u, ///< AES
ResetGpio = 0x10000000u, ///< GPIO
ResetDma = 0x20000000u, ///< DMA
ResetDiv = 0x40000000u, ///< DIV
}en_reset_peripheral_t;
/**
*******************************************************************************
** \brief
**
** \note
******************************************************************************/
typedef struct
{
uint8_t u8Por5V :1; ///< 5V启动复位
uint8_t u8Por1_5V :1; ///< 1.5V启动复位
uint8_t u8Lvd :1; ///< 低电压检测复位
uint8_t u8Wdt :1; ///< 看门狗复位
uint8_t u8Pca :1; ///< PCA复位
uint8_t u8Lockup :1; ///< 系统异常复位
uint8_t u8Sysreq :1; ///< 软件复位
uint8_t u8RSTB :1; ///< RESET脚 复位
}stc_reset_cause_t;
/*******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/*******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 获得复位源
en_result_t Reset_GetCause(stc_reset_cause_t *pstcOut);
///< 清除复位源
en_result_t Reset_Clear(stc_reset_cause_t stcval);
///< 外设模块复位控制
en_result_t Reset_SetPeripheralReset(en_reset_peripheral_t enPeri,boolean_t bFlag);
//@} // ResetGroup
#ifdef __cplusplus
#endif
#endif /* __RESET_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,108 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file rng.h
**
** Headerfile for RNG functions
** @link RNG Group Some description @endlink
**
** History:
** - 2018-04-15 Lux First Version
**
******************************************************************************/
#ifndef __RNG_H__
#define __RNG_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup RngGroup (RNG)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/*******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 随机数初始化(上电第一次生成随机数)
en_result_t Rng_Init(void);
///< 生成随机数(非上电第一次生成随机数)
en_result_t Rng_Generate(void);
///< 获取64bits随机数执行随机数初始化或生成随机数函数后可使用该函数获取随机数值
uint32_t Rng_GetData0(void);
uint32_t Rng_GetData1(void);
//@} // Rng Group
#ifdef __cplusplus
#endif
#endif /* __RNG_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,298 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file rtc.h
**
** Headerfile for RTC functions
**
**
** History:
** - 2017-05-10 Cathy First Version
**
*****************************************************************************/
#ifndef __RTC_H__
#define __RTC_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup RtcGroup Real Time Clock (RTC)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief rtc时钟源选择
*****************************************************************************/
typedef enum en_rtc_clk
{
RtcClk32768 = 0u, ///<外部32.768k
RtcClk32768_1 = 1u, ///<外部32.768k
RtcClk32 = 2u, ///<内部RC32
RtcClk32_1 = 3u, ///<内部RC32
RtcClkHxt128 = 4u, ///<外部晶振4M
RtcClkHxt256 = 5u, ///<外部晶振8M
RtcClkHxt512 = 6u, ///<外部晶振16M
RtcClkHxt1024 = 7u, ///<外部晶振32M
}en_rtc_clk_t;
/**
******************************************************************************
** \brief rtc周期中断方式选择
*****************************************************************************/
typedef enum en_rtc_cyc
{
RtcPrads = 0u, ///<月、天、时分秒
RtcPradx = 1u, ///<step 0.5s
}en_rtc_cyc_t;
/**
******************************************************************************
** \brief rtc 12h制或24h制方式选择
*****************************************************************************/
typedef enum en_rtc_ampm
{
Rtc12h = 0u, ///<12h
Rtc24h = 1u, ///<24h
}en_rtc_ampm_t;
/**
******************************************************************************
** \brief prds中断周期
*****************************************************************************/
typedef enum en_rtc_cycprds
{
Rtc_None = 0u, ///<无周期中断
Rtc_05S = 1u, ///<0.5S中断
Rtc_1S = 2u, ///<1s
Rtc_1Min = 3u, ///<1min
Rtc_1H = 4u, ///<1h
Rtc_1Day = 5u, ///<1d
Rtc_1Mon = 6u, ///<1月
Rtc_1Mon_1 = 7u, ///<1月
}en_rtc_cycprds_t;
/**
******************************************************************************
** \brief rtc周期中断总配置
*****************************************************************************/
typedef struct stc_rtc_cyc_sel
{
en_rtc_cyc_t enCyc_sel; ///<周期类型配置
en_rtc_cycprds_t enPrds_sel;///<周期配置
uint8_t u8Prdx;
}stc_rtc_cyc_sel_t;
/**
******************************************************************************
** \brief
*****************************************************************************/
typedef struct stc_rtc_alarmset
{
uint8_t u8Minute; ///<闹钟分钟
uint8_t u8Hour; ///<闹钟小时
uint8_t u8Week; ///<闹钟周
}stc_rtc_alarmset_t;
/**
******************************************************************************
** \brief 使
*****************************************************************************/
typedef enum en_rtc_alarmirq
{
Rtc_AlarmInt_Disable = 0u,///<闹钟中断禁止
Rtc_AlarmInt_Enable = 1u,///<闹钟中断使能
}en_rtc_alarmirq_t;
/**
******************************************************************************
** \brief rtc 1hz补偿功能开启设置
*****************************************************************************/
typedef enum en_rtc_compen_en
{
Rtc_Comp_Disable = 0u,///<时钟补偿禁止
Rtc_Comp_Enable = 1u,///<时钟补偿使能
}en_rtc_compen_en_t;
/**
******************************************************************************
** \brief rtc计数功能使能设置
*****************************************************************************/
typedef enum en_rtc_count_en
{
Rtc_Count_Disable = 0u,///<计数禁止
Rtc_Count_Enable = 1u,///<计数使能
}en_rtc_count_en_t;
/**
******************************************************************************
** \brief rtc计数模式还是读写模式状态
*****************************************************************************/
typedef enum en_rtc_status
{
RtcRunStatus = 0u, ///<计数状态
RtcRdWStatus = 1u, ///<读写状态
}en_rtc_status_t;
/**
******************************************************************************
** \brief rtc
*****************************************************************************/
typedef enum en_rtc_status_irq
{
RtcAlmf = 0u, ///<闹钟中断请求
RtcPrdf = 1u, ///<周期中断请求
}en_rtc_status_irq_t;
/**
******************************************************************************
** \brief rtc时钟年
*****************************************************************************/
typedef struct stc_rtc_time
{
uint8_t u8Second; ///<秒
uint8_t u8Minute; ///<分
uint8_t u8Hour; ///<时
uint8_t u8DayOfWeek; ///<周
uint8_t u8Day; ///<日
uint8_t u8Month; ///<月
uint8_t u8Year; ///<年
} stc_rtc_time_t;
/**
******************************************************************************
** \brief rtc功能描述
******************************************************************************/
typedef enum en_rtc_func
{
RtcCount = 0u, ///< RTC计数使能
RtcAlarmEn = 1u, ///< RTC闹钟使能
Rtc_ComenEn = 2u, ///<RTC补偿使能
Rtc1HzOutEn = 3u, ///<使能1hz输出
}en_rtc_func_t;
/**
******************************************************************************
** \brief rtc
*****************************************************************************/
typedef struct stc_rtc_irq_cb
{
func_ptr_t pfnAlarmIrqCb; ///<闹钟中断服务函数
func_ptr_t pfnTimerIrqCb; ///<周期中断服务函数
}stc_rtc_irq_cb_t, stc_rtc_intern_cb_t;
/**
******************************************************************************
** \brief rtc
*****************************************************************************/
typedef struct stc_rtc_config
{
en_rtc_clk_t enClkSel; ///<时钟源配置
en_rtc_ampm_t enAmpmSel; ///<时制配置
stc_rtc_cyc_sel_t* pstcCycSel; ///<周期配置
stc_rtc_time_t* pstcTimeDate; ///<时间日期初值配置
stc_rtc_irq_cb_t* pstcIrqCb; ///<中断服务函数
boolean_t bTouchNvic; ///<NVIC中断配置
} stc_rtc_config_t;
//rtc 计数时钟源选择
en_result_t Rtc_SelClk(en_rtc_clk_t enClk);
//rtc 计数周期设置
en_result_t Rtc_SetCyc(stc_rtc_cyc_sel_t* pstcCyc);
//rtc ampm模式设置
en_result_t Rtc_SetAmPm(en_rtc_ampm_t enMode);
//rtc时制模式获取
boolean_t Rtc_GetHourMode(void);
//rtc 闹钟相关配置
en_result_t Rtc_SetAlarmTime(stc_rtc_alarmset_t* pstcAlarmTime);
en_result_t Rtc_GetAlarmTime(stc_rtc_alarmset_t* pstcAlarmTime);
//1hz 输出模式及补偿值设置
en_result_t Rtc_Set1HzMode(boolean_t bMode);
en_result_t Rtc_SetCompCr(uint16_t u16Cr);
//周计算
uint8_t Rtc_CalWeek(uint8_t* pu8Date);
//判断是否闰年
uint8_t Rtc_CheckLeapYear(uint8_t u8year);
//12时制上午或下午读取
boolean_t Rtc_RDAmPm(void);
//rtc 读写时间计数器
en_result_t Rtc_WriteDateTime(stc_rtc_time_t* pstcTimeDate,boolean_t bUpdateTime,
boolean_t bUpdateDate);
en_result_t Rtc_ReadDateTime(stc_rtc_time_t* pstcTimeDate);
//格式转换函数
uint8_t Change_DateTimeFormat(uint8_t u8sr);
//时间格式检查函数
en_result_t Rtc_CheckDateTimeFormat(uint8_t* pu8TimeDate,uint8_t u8Mode);
//数据大小判断函数
en_result_t Check_BCD_Format(uint8_t u8data, uint8_t u8limit_min, uint8_t u8limit_max);
//获取某年某月最大天数
uint8_t Get_Month_Max_Day(uint8_t u8month, uint8_t u8year);
//rtc 读取当前状态(读写状态或计数状态),中断请求状态、中断清除状态
en_result_t Rtc_EnAlarmIrq(en_rtc_alarmirq_t enIrqEn);
boolean_t Rtc_RDStatus(void);
boolean_t Rtc_GetIrqStatus(en_rtc_status_irq_t enIrqSel);
en_result_t Rtc_ClrIrqStatus(en_rtc_status_irq_t enIrqSel);
//rtc功能使能禁止函数
en_result_t Rtc_EnableFunc(en_rtc_func_t enFunc);
en_result_t Rtc_DisableFunc(en_rtc_func_t enFunc);
//rtc初始化、禁止函数
en_result_t Rtc_Init(stc_rtc_config_t* pstcRtcConfig);
en_result_t Rtc_DeInit(void);
//@} // RtcGroup
#ifdef __cplusplus
#endif
#endif /* __RTC_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,212 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED , ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file spi.h
**
** Headerfile for SPI functions
**
**
** History:
** - 2017-05-17 1.0 Devi First Version
**
*****************************************************************************/
#ifndef __SPI_H__
#define __SPI_H__
/******************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
//@{
/******************************************************************************
* Global type definitions
*****************************************************************************/
/**
******************************************************************************
** \brief SPI
******************************************************************************/
typedef enum en_spi_channel
{
Spi0 = 0u, ///< SPI通道0
Spi1 = 1u, ///< SPI通道1
}en_spi_channel_t;
/**
******************************************************************************
** \brief SPI 使
******************************************************************************/
typedef enum en_spi_en
{
SpiEnable = 1u, ///< SPI模块使能
SpiDisable = 0u, ///< SPI模块禁止
}en_spi_en_t;
/**
******************************************************************************
** \brief SPI
******************************************************************************/
typedef enum en_spi_mode
{
SpiMaster = 1u, ///<主机
SpiSlave = 0u, ///<从机
}en_spi_mode_t;
/**
******************************************************************************
** \brief SPI
******************************************************************************/
typedef enum en_spi_cpol
{
Spicpollow = 0u, ///<极性为低
Spicpolhigh = 1u, ///<极性为高
}en_spi_cpol_t;
/**
******************************************************************************
** \brief SPI
******************************************************************************/
typedef enum en_spi_cpha
{
Spicphafirst = 0u, ///<第一边沿采样
Spicphasecond = 1u, ///<第二边沿采样
}en_spi_cpha_t;
/**
******************************************************************************
** \brief SPI
*****************************************************************************/
typedef enum en_spi_clk_div
{
SpiClkDiv2 = 0u, ///<2分频
SpiClkDiv4 = 1u, ///<4分频
SpiClkDiv8 = 2u, ///<8分频
SpiClkDiv16 = 3u, ///<16分频
SpiClkDiv32 = 4u, ///<32分频
SpiClkDiv64 = 5u, ///<64分频
SpiClkDiv128 = 6u, ///<128分频
}en_spi_clk_div_t;
/**
******************************************************************************
** \brief SPI
*****************************************************************************/
typedef enum en_spi_cspin
{
SpiCsLow = 0u, ///<片选低电平
SpiCsHigh = 1u, ///<片选高电平
}en_spi_cspin_t;
/**
******************************************************************************
** \brief SPI
*****************************************************************************/
typedef enum en_spi_status
{
SpiIf = 0x80, ///<传输结束中断标志
SpiSserr = 0x20, ///<从机模式错误标志
SpiMdf = 0x10, ///<主机模式错误标志
SpiBusy = 0x08, ///<SPI总线忙标志
SpiTxe = 0x04, ///<发送缓冲器器空标志
SpiRxne = 0x02, ///<接受缓冲器非空标志
}en_spi_status_t;
/**
******************************************************************************
** \brief SPI
*****************************************************************************/
typedef enum en_spi_func
{
SpiRxNeIe = 0x40, ///<接收缓冲器非空中断使能
SpiTxEIe = 0x20, ///<发送缓冲器空中断使能
SpiDmaTxEn = 0x10, ///<DMA硬件访问发送使能
SpiDmaRxEn = 0x08, ///<DMA硬件访问接收使能
}en_spi_func_t;
/**
******************************************************************************
** \brief SPI
*****************************************************************************/
typedef struct stc_spi_config
{
boolean_t bMasterMode; ///< 主从模式选择
uint8_t u8BaudRate; ///< 波特率设置
boolean_t bCPOL; ///< 时钟极性选择
boolean_t bCPHA; ///< 时钟相位选择
boolean_t bIrqEn; ///< 中断使能
func_ptr_t pfnSpi0IrqCb; ///< 中断回调函数
func_ptr_t pfnSpi1IrqCb; ///< 中断回调函数
}stc_spi_config_t;
//SPI 中断
void Spi_IRQHandler(en_spi_channel_t enCh);
//SPI 获取状态
uint8_t Spi_GetState(en_spi_channel_t enCh);
boolean_t Spi_GetStatus(en_spi_channel_t enCh,en_spi_status_t enStatus);
//SPI 清除中断标记
en_result_t Spi_ClearStatus(en_spi_channel_t enCh);
//SPI初始化函数
en_result_t Spi_Init(en_spi_channel_t enCh,stc_spi_config_t* pstcSpiConfig);
//SPI 功能使能禁止函数
en_result_t Spi_FuncEn(en_spi_channel_t enCh,en_spi_func_t enFunc,boolean_t bFlag);
//SPI关闭函数
en_result_t Spi_DeInit(en_spi_channel_t enCh);
//SPI 配置主发送的电平
void Spi_SetCS(en_spi_channel_t enCh,boolean_t bFlag);
//SPI 发送数据
en_result_t Spi_SendData(en_spi_channel_t enCh,uint8_t u8Data);
//SPI 主机接收数据
uint8_t Spi_ReceiveData(en_spi_channel_t enCh,boolean_t bMasterOrSlave);
//@} // Spi Group
#ifdef __cplusplus
}
#endif
#endif /* __SPI_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,457 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file sysctrl.h
**
** Headerfile for SYSCTRL functions
** @link SYSCTRL Group Some description @endlink
**
** History:
** - 2018-04-15 Lux First Version
**
******************************************************************************/
#ifndef __SYSCTRL_H__
#define __SYSCTRL_H__
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup SysCtrlGroup (SYSCTRL)
**
******************************************************************************/
//@{
/**
*******************************************************************************
** function prototypes.
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
#define SYSTEM_XTH 32*1000*1000u //默认32MHz,具体值应根据实际系统修改
#define SYSTEM_XTL 32768u //默认32768Hz,具体值应根据实际系统修改
/**
*******************************************************************************
** \brief
** \note
******************************************************************************/
typedef enum en_sysctrl_clk_source
{
SysctrlClkRCH = 0u, ///< 内部高速时钟
SysctrlClkXTH = 1u, ///< 外部高速时钟
SysctrlClkRCL = 2u, ///< 内部低速时钟
SysctrlClkXTL = 3u, ///< 外部低速时钟
SysctrlClkPLL = 4u, ///< PLL时钟
}en_sysctrl_clk_source_t;
/**
*******************************************************************************
** \brief RCH频率值枚举类型定义
******************************************************************************/
typedef enum en_sysctrl_rch_freq
{
SysctrlRchFreq4MHz = 0u, ///< 4MHz
SysctrlRchFreq8MHz = 1u, ///< 8MHz
SysctrlRchFreq16MHz = 2u, ///< 16MHz
SysctrlRchFreq22_12MHz = 3u, ///< 22.12MHz
SysctrlRchFreq24MHz = 4u, ///< 24MHz
}en_sysctrl_rch_freq_t;
/**
*******************************************************************************
** \brief XTAL驱动能力类型定义
******************************************************************************/
typedef enum en_sysctrl_xtal_driver
{
SysctrlXtalDriver0 = 0u, ///< 最弱驱动能力
SysctrlXtalDriver1 = 1u, ///< 弱驱动能力
SysctrlXtalDriver2 = 3u, ///< 一般驱动能力
SysctrlXtalDriver3 = 3u, ///< 最强驱动能力
}en_sysctrl_xtal_driver_t;
/**
*******************************************************************************
** \brief XTH频率值范围选择类型定义
******************************************************************************/
typedef enum en_sysctrl_xth_freq
{
SysctrlXthFreq4_6MHz = 0u, ///< 4~6MHz
SysctrlXthFreq6_12MHz = 1u, ///< 6~12MHz
SysctrlXthFreq12_20MHz = 2u, ///< 12~20MHz
SysctrlXthFreq20_32MHz = 3u, ///< 20~32MHz
}en_sysctrl_xth_freq_t;
/**
*******************************************************************************
** \brief XTH时钟稳定周期数类型定义
******************************************************************************/
typedef enum en_sysctrl_xth_cycle
{
SysctrlXthStableCycle256 = 0u, ///< 256 个周期数
SysctrlXthStableCycle1024 = 1u, ///< 1024 个周期数
SysctrlXthStableCycle4096 = 2u, ///< 4096 个周期数
SysctrlXthStableCycle16384 = 3u, ///< 16384 个周期数
}en_sysctrl_xth_cycle_t;
/**
*******************************************************************************
** \brief RCL频率值枚举类型定义
******************************************************************************/
typedef enum en_sysctrl_rcl_freq
{
SysctrlRclFreq32768 = 0u, ///< 32.768KHz
SysctrlRclFreq38400 = 1u, ///< 38.4KHz
}en_sysctrl_rcl_freq_t;
/**
*******************************************************************************
** \brief RCL时钟稳定周期数类型定义
******************************************************************************/
typedef enum en_sysctrl_rcl_cycle
{
SysctrlRclStableCycle4 = 0u, ///< 4 个周期数
SysctrlRclStableCycle16 = 1u, ///< 16 个周期数
SysctrlRclStableCycle64 = 2u, ///< 64 个周期数
SysctrlRclStableCycle256 = 3u, ///< 256 个周期数
}en_sysctrl_rcl_cycle_t;
/**
*******************************************************************************
** \brief XTL时钟稳定周期数类型定义
******************************************************************************/
typedef enum en_sysctrl_xtl_cycle
{
SysctrlXtlStableCycle256 = 0u, ///< 256 个周期数
SysctrlXtlStableCycle1024 = 1u, ///< 1024 个周期数
SysctrlXtlStableCycle4096 = 2u, ///< 4096 个周期数
SysctrlXtlStableCycle16384 = 3u, ///< 16384 个周期数
}en_sysctrl_xtl_cycle_t;
/**
*******************************************************************************
** \brief XTL晶体振幅枚举类型定义
******************************************************************************/
typedef enum en_sysctrl_xtl_amp
{
SysctrlXtlAmp0 = 0u, ///< 最小振幅
SysctrlXtlAmp1 = 1u, ///< 小振幅
SysctrlXtlAmp2 = 2u, ///< 一般振幅
SysctrlXtlAmp3 = 3u, ///< 最大振幅
}en_sysctrl_xtl_amp_t;
/**
*******************************************************************************
** \brief PLL时钟稳定周期数类型定义
******************************************************************************/
typedef enum en_sysctrl_pll_cycle
{
SysctrlPllStableCycle128 = 0u, ///< 128个周期数
SysctrlPllStableCycle256 = 1u, ///< 256个周期数
SysctrlPllStableCycle512 = 2u, ///< 512个周期数
SysctrlPllStableCycle1024 = 3u, ///< 1024个周期数
SysctrlPllStableCycle2048 = 4u, ///< 2048个周期数
SysctrlPllStableCycle4096 = 5u, ///< 4096个周期数
SysctrlPllStableCycle8192 = 6u, ///< 8192个周期数
SysctrlPllStableCycle16384 = 7u, ///< 16384个周期数
}en_sysctrl_pll_cycle_t;
/**
*******************************************************************************
** \brief PLL输入频率范围类型定义
******************************************************************************/
typedef enum en_sysctrl_pll_infreq
{
SysctrlPllInFreq4_6MHz = 0u, ///< 4~16MHz
SysctrlPllInFreq6_12MHz = 1u, ///< 6~12MHz
SysctrlPllInFreq12_20MHz = 2u, ///< 12~20MHz
SysctrlPllInFreq20_24MHz = 3u, ///< 20~24MHz
}en_sysctrl_pll_infreq_t;
/**
*******************************************************************************
** \brief PLL输出频率范围类型定义
******************************************************************************/
typedef enum en_sysctrl_pll_outfreq
{
SysctrlPllOutFreq8_12MHz = 0u, ///< 8~12MHz
SysctrlPllOutFreq12_18MHz = 1u, ///< 12~18MHz
SysctrlPllOutFreq18_24MHz = 2u, ///< 18~24MHz
SysctrlPllOutFreq24_36MHz = 3u, ///< 24~36MHz
SysctrlPllOutFreq36_48MHz = 4u, ///< 36~48MHz
}en_sysctrl_pll_outfreq_t;
/**
*******************************************************************************
** \brief PLL输入时钟源类型定义
******************************************************************************/
typedef enum en_sysctrl_pll_clksource
{
SysctrlPllXthXtal = 0u, ///< XTH晶振输入的时钟
SysctrlPllXthPd00In = 2u, ///< XTH从端口PD00输入的时钟
SysctrlPllRch = 3u, ///< RCH时钟
}en_sysctrl_pll_clksource_t;
/**
*******************************************************************************
** \brief PLL输入时钟源类型定义
******************************************************************************/
typedef enum en_sysctrl_pll_mul
{
SysctrlPllMul1 = 1u, ///< 1倍频
SysctrlPllMul2 = 2u, ///< 2倍频
SysctrlPllMul3 = 3u, ///< 3倍频
SysctrlPllMul4 = 4u, ///< 4倍频
SysctrlPllMul5 = 5u, ///< 5倍频
SysctrlPllMul6 = 6u, ///< 6倍频
SysctrlPllMul7 = 7u, ///< 7倍频
SysctrlPllMul8 = 8u, ///< 8倍频
SysctrlPllMul9 = 9u, ///< 9倍频
SysctrlPllMul10 = 10u, ///< 10倍频
SysctrlPllMul11 = 11u, ///< 11倍频
SysctrlPllMul12 = 12u, ///< 12倍频
}en_sysctrl_pll_mul_t;
/**
*******************************************************************************
** \brief HCLK时钟分频系数类型定义
******************************************************************************/
typedef enum en_sysctrl_hclk_div
{
SysctrlHclkDiv1 = 0u, ///< SystemClk
SysctrlHclkDiv2 = 1u, ///< SystemClk/2
SysctrlHclkDiv4 = 2u, ///< SystemClk/4
SysctrlHclkDiv8 = 3u, ///< SystemClk/8
SysctrlHclkDiv16 = 4u, ///< SystemClk/16
SysctrlHclkDiv32 = 5u, ///< SystemClk/32
SysctrlHclkDiv64 = 6u, ///< SystemClk/64
SysctrlHclkDiv128 = 7u, ///< SystemClk/128
}en_sysctrl_hclk_div_t;
/**
*******************************************************************************
** \brief PCLK分频系数
******************************************************************************/
typedef enum en_sysctrl_pclk_div
{
SysctrlPclkDiv1 = 0u, ///< HCLK
SysctrlPclkDiv2 = 1u, ///< HCLK/2
SysctrlPclkDiv4 = 2u, ///< HCLK/4
SysctrlPclkDiv8 = 3u, ///< HCLK/8
}en_sysctrl_pclk_div_t;
/**
*******************************************************************************
** \brief RTC高速时钟补偿时钟频率数据类型定义
******************************************************************************/
typedef enum en_sysctrl_rtc_adjust
{
SysctrlRTC4MHz = 0u, ///< 4MHz
SysctrlRTC6MHz = 1u, ///< 6MHz
SysctrlRTC8MHz = 2u, ///< 8MHz
SysctrlRTC12MHz = 3u, ///< 12MHz
SysctrlRTC16MHz = 4u, ///< 16MHz
SysctrlRTC20MHz = 5u, ///< 20MHz
SysctrlRTC24MHz = 6u, ///< 24MHz
SysctrlRTC32MHz = 7u, ///< 32MHz
}en_sysctrl_rtc_adjust_t;
/**
*******************************************************************************
** \brief
******************************************************************************/
typedef enum en_sysctrl_func
{
SysctrlWkupByRCHEn =0u, ///< 唤醒时使用RCH时钟
SysctrlEXTHEn =1u, ///< 使能外部高速时钟从输入引脚PD00输入
SysctrlEXTLEn =2u, ///< 使能外部低速速时钟从输入引脚PC14输入
SysctrlXTLAlwaysOnEn =3u, ///< 使能后XTL_EN只可置位
SysctrlClkFuncRTCLpmEn =4u, ///< 使能RTC低功耗模式
SysctrlCMLockUpEn =5u, ///< 使能后CPU执行无效指令会复位MCU
SysctrlSWDUseIOEn =6u, ///< SWD端口设为IO功能
}en_sysctrl_func_t;
/**
*******************************************************************************
** \brief
******************************************************************************/
typedef enum en_sysctrl_peripheral_gate
{
SysctrlPeripheralUart0 = 0u, ///< 串口0
SysctrlPeripheralUart1 = 1u, ///< 串口1
SysctrlPeripheralLpUart0 = 2u, ///< 低功耗串口0
SysctrlPeripheralLpUart1 = 3u, ///< 低功耗串口1
SysctrlPeripheralI2c0 = 4u, ///< I2C0
SysctrlPeripheralI2c1 = 5u, ///< I2C1
SysctrlPeripheralSpi0 = 6u, ///< SPI0
SysctrlPeripheralSpi1 = 7u, ///< SPI1
SysctrlPeripheralBTim = 8u, ///< 基础定时器
SysctrlPeripheralLpTim = 9u, ///< 低功耗定时器
SysctrlPeripheralAdvTim = 10u, ///< 高级定时器
SysctrlPeripheralTim3 = 11u, ///< 定时器3
SysctrlPeripheralOpa = 13u, ///< OPA
SysctrlPeripheralPca = 14u, ///< 可编程计数阵列
SysctrlPeripheralWdt = 15u, ///< 看门狗
SysctrlPeripheralAdcBgr = 16u, ///< ADC&BGR
SysctrlPeripheralVcLvd = 17u, ///< 电压比较和低电压检测
SysctrlPeripheralRng = 18u, ///< RNG
SysctrlPeripheralPcnt = 19u, ///< PCNT
SysctrlPeripheralRtc = 20u, ///< RTC
SysctrlPeripheralTrim = 21u, ///< 时钟校准
SysctrlPeripheralLcd = 22u, ///< LCD
SysctrlPeripheralTick = 24u, ///< 系统定时器
SysctrlPeripheralSwd = 25u, ///< SWD
SysctrlPeripheralCrc = 26u, ///< CRC
SysctrlPeripheralAes = 27u, ///< AES
SysctrlPeripheralGpio = 28u, ///< GPIO
SysctrlPeripheralDma = 29u, ///< DMA
SysctrlPeripheralDiv = 30u, ///< 除法器
SysctrlPeripheralFlash = 31u, ///< Flash
}en_sysctrl_peripheral_gate_t;
/**
*******************************************************************************
** \brief
******************************************************************************/
typedef struct
{
en_sysctrl_clk_source_t enClkSrc; ///< 时钟源选择
en_sysctrl_hclk_div_t enHClkDiv; ///< HCLK分频系数
en_sysctrl_pclk_div_t enPClkDiv; ///< PCLK分频系数
}stc_sysctrl_clk_config_t;
/**
*******************************************************************************
** \brief
******************************************************************************/
typedef struct
{
en_sysctrl_pll_infreq_t enInFreq; ///< PLL输入时钟频率范围选择
en_sysctrl_pll_outfreq_t enOutFreq; ///< PLL输出时钟频率范围选择
en_sysctrl_pll_clksource_t enPllClkSrc; ///< PLL输入时钟源选择
en_sysctrl_pll_mul_t enPllMul; ///< PLL倍频系数选择
}stc_sysctrl_pll_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
///< 系统时钟初始化API:用于上电后,系统工作之前对主频及外设时钟进行初始化;
///< 注意1使用该初始化函数前需要根据系统必须优先设置目标内部时钟源的TRIM值或外部时钟源的频率范围
///< 注意2XTH、XTL的频率范围设定需要根据外部晶振决定
///< 注意3本驱动默认宏定义SYSTEM_XTH=32MHz,SYSTEM_XTL=32768Hz,如使用其它外部晶振,必须修改这两个宏定义的值。
en_result_t Sysctrl_ClkInit(stc_sysctrl_clk_config_t *pstcCfg);
///< 系统时钟去初始化API:恢复为上电默认状态->PCLK=HCLK=SystemClk=RCH4MHz
en_result_t Sysctrl_ClkDeInit(void);
///< 系统时钟模块的基本功能设置
///< 注意使能需要使用的时钟源之前必须优先设置目标内部时钟源的TRIM值或外部时钟源的频率范围
en_result_t Sysctrl_ClkSourceEnable(en_sysctrl_clk_source_t enSource, boolean_t bFlag);
///<外部晶振驱动配置系统初始化Sysctrl_ClkInit()之后可根据需要配置外部晶振的驱动能力时钟初始化Sysctrl_ClkInit()默认为最大值;
en_result_t Sysctrl_XTHDriverConfig(en_sysctrl_xtal_driver_t enDriver);
en_result_t Sysctrl_XTLDriverConfig(en_sysctrl_xtl_amp_t enAmp, en_sysctrl_xtal_driver_t enDriver);
///<时钟稳定周期设置:系统初始化Sysctrl_ClkInit()之后,可根据需要配置时钟开启后的稳定之间,默认为最大值;
en_result_t Sysctrl_SetXTHStableTime(en_sysctrl_xth_cycle_t enCycle);
en_result_t Sysctrl_SetRCLStableTime(en_sysctrl_rcl_cycle_t enCycle);
en_result_t Sysctrl_SetXTLStableTime(en_sysctrl_xtl_cycle_t enCycle);
en_result_t Sysctrl_SetPLLStableTime(en_sysctrl_pll_cycle_t enCycle);
///<系统时钟源切换并更新系统时钟如果需要在系统时钟初始化Sysctrl_ClkInit()之后切换主频时钟源,则使用该函数;
///< 时钟切换前后必须根据目标频率值设置Flash读等待周期可配置插入周期为0、1、2
///< 注意!!!当HCLK大于24MHz时FLASH等待周期插入必须至少为1,否则程序运行可能产生未知错误
en_result_t Sysctrl_SysClkSwitch(en_sysctrl_clk_source_t enSource);
///< 时钟源频率设定:根据系统情况,单独设置不同时钟源的频率值;
///< 时钟频率设置前必须根据目标频率值设置Flash读等待周期可配置插入周期为0、1、2
///< 其中XTL的时钟由外部晶振决定无需设置。
en_result_t Sysctrl_SetRCHTrim(en_sysctrl_rch_freq_t enRCHFreq);
en_result_t Sysctrl_SetRCLTrim(en_sysctrl_rcl_freq_t enRCLFreq);
en_result_t Sysctrl_SetXTHFreq(en_sysctrl_xth_freq_t enXTHFreq);
en_result_t Sysctrl_SetPLLFreq(stc_sysctrl_pll_config_t *pstcPLLCfg);
///< 时钟分频设置:根据系统情况单独设置HCLK、PCLK的分配值;
en_result_t Sysctrl_SetHCLKDiv(en_sysctrl_hclk_div_t enHCLKDiv);
en_result_t Sysctrl_SetPCLKDiv(en_sysctrl_pclk_div_t enPCLKDiv);
///< 时钟频率获取根据系统需要获取当前HCLK及PCLK的频率值
uint32_t Sysctrl_GetHClkFreq(void);
uint32_t Sysctrl_GetPClkFreq(void);
///< 外设门控开关/状态获取:用于控制外设模块的使能,使用该模块的功能之前,必须使能该模块的门控时钟;
en_result_t Sysctrl_SetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral, boolean_t bFlag);
boolean_t Sysctrl_GetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral);
///< 系统功能配置:用于设置其他系统相关特殊功能;
en_result_t Sysctrl_SetFunc(en_sysctrl_func_t enFunc, boolean_t bFlag);
///< RTC高速时钟补偿:用于设置RTC高速时钟下的频率补偿
en_result_t Sysctrl_SetRTCAdjustClkFreq(en_sysctrl_rtc_adjust_t enRtcAdj);
//@} // Sysctrl Group
#ifdef __cplusplus
#endif
#endif /* __SYSCTRL_H__ */
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,788 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file bt.h
**
** API声明
** @link BT Timer3 Group Some description @endlink
**
** History:
** - 2018-04-29 Husj First Version
**
*****************************************************************************/
#ifndef __TIMER0_H__
#define __TIMER0_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup Tim0Group Base Timer (BT)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief Timer3
*****************************************************************************/
typedef enum en_tim0_channel
{
Tim0CH0 = 0u, ///< Timer3通道0
Tim0CH1 = 1u, ///< Timer3通道1
Tim0CH2 = 2u, ///< Timer3通道2
}en_tim0_channel_t;
/**
******************************************************************************
** \brief (MODE)(0/1/23)
*****************************************************************************/
typedef enum en_tim0_work_mode
{
Tim0WorkMode0 = 0u, ///< 定时器模式
Tim0WorkMode1 = 1u, ///< PWC模式
Tim0WorkMode2 = 2u, ///< 锯齿波模式
Tim0WorkMode3 = 3u, ///< 三角波模式
}en_tim0_work_mode_t;
/**
******************************************************************************
** \brief (GATE_P)(0)
*****************************************************************************/
typedef enum en_tim0_m0cr_gatep
{
Tim0GatePositive = 0u, ///< 高电平有效
Tim0GateOpposite = 1u, ///< 低电平有效
}en_tim0_m0cr_gatep_t;
/**
******************************************************************************
** \brief TIM3 (PRS)(0/1/23)
*****************************************************************************/
typedef enum en_tim0_cr_timclkdiv
{
Tim0PCLKDiv1 = 0u, ///< Div 1
Tim0PCLKDiv2 = 1u, ///< Div 2
Tim0PCLKDiv4 = 2u, ///< Div 4
Tim0PCLKDiv8 = 3u, ///< Div 8
Tim0PCLKDiv16 = 4u, ///< Div 16
Tim0PCLKDiv32 = 5u, ///< Div 32
Tim0PCLKDiv64 = 6u, ///< Div 64
Tim0PCLKDiv256 = 7u, ///< Div 256
}en_tim0_cr_timclkdiv_t;
/**
******************************************************************************
** \brief / (CT)(0/1/23)
*****************************************************************************/
typedef enum en_tim0_cr_ct
{
Tim0Timer = 0u, ///< 定时器功能计数时钟为内部PCLK
Tim0Counter = 1u, ///< 计数器功能计数时钟为外部ETR
}en_tim0_cr_ct_t;
/**
******************************************************************************
** \brief (MD)(0)
*****************************************************************************/
typedef enum en_tim0_m0cr_md
{
Tim032bitFreeMode = 0u, ///< 32位计数器/定时器
Tim016bitArrMode = 1u, ///< 自动重装载16位计数器/定时器
}en_tim0_m0cr_md_t;
/**
******************************************************************************
** \brief TIM3中断类型数据类型重定义(0/1/23)
*****************************************************************************/
typedef enum en_tim0_irq_type
{
Tim0UevIrq = 0u, ///< 溢出/事件更新中断
Tim0CA0Irq = 2u, ///< CH0A捕获/比较中断(仅模式1/23存在)
Tim0CA1Irq = 3u, ///< CH1A捕获/比较中断(仅模式23存在)
Tim0CA2Irq = 4u, ///< CH2A捕获/比较中断(仅模式23存在)
Tim0CB0Irq = 5u, ///< CH0B捕获/比较中断(仅模式23存在)
Tim0CB1Irq = 6u, ///< CH1B捕获/比较中断(仅模式23存在)
Tim0CB2Irq = 7u, ///< CH2B捕获/比较中断(仅模式23存在)
Tim0CA0E = 8u, ///< CH0A捕获数据丢失标志(仅模式23存在)(不是中断)
Tim0CA1E = 9u, ///< CH1A捕获数据丢失标志(仅模式23存在)(不是中断)
Tim0CA2E = 10u, ///< CH2A捕获数据丢失标志(仅模式23存在)(不是中断)
Tim0CB0E = 11u, ///< CH0B捕获数据丢失标志(仅模式23存在)(不是中断)
Tim0CB1E = 12u, ///< CH1B捕获数据丢失标志(仅模式23存在)(不是中断)
Tim0CB2E = 13u, ///< CH2B捕获数据丢失标志(仅模式23存在)(不是中断)
Tim0BkIrq = 14u, ///< 刹车中断(仅模式23存在
Tim0TrigIrq = 15u, ///< 触发中断(仅模式23存在
}en_tim0_irq_type_t;
/**
******************************************************************************
** \brief (Edg1stEdg2nd)(1)
*****************************************************************************/
typedef enum en_tim0_m1cr_Edge
{
Tim0PwcRiseToRise = 0u, ///< 上升沿到上升沿(周期)
Tim0PwcFallToRise = 1u, ///< 下降沿到上升沿(低电平)
Tim0PwcRiseToFall = 2u, ///< 上升沿到下降沿(高电平)
Tim0PwcFallToFall = 3u, ///< 下降沿到下降沿(周期)
}en_tim0_m1cr_Edge_t;
/**
******************************************************************************
** \brief PWC测量测试模式选择数据类型重定义 (Oneshot)(1)
*****************************************************************************/
typedef enum en_tim0_m1cr_oneshot
{
Tim0PwcCycleDetect = 0u, ///< PWC循环测量
Tim0PwcOneShotDetect = 1u, ///< PWC单次测量
}en_tim0_m1cr_oneshot_t;
/**
******************************************************************************
** \brief PWC IA0选择数据类型重定义 (IA0S)(1)
*****************************************************************************/
typedef enum en_tim0_m1_mscr_ia0s
{
Tim0IA0Input = 0u, ///< IAO输入
Tim0XORInput = 1u, ///< IA0 ETR GATE XOR(TIM0/1/2)/IA0 IA1 IA2 XOR(TIM3)
}en_tim0_m1_mscr_ia0s_t;
/**
******************************************************************************
** \brief PWC IB0选择数据类型重定义 (IA0S)(1)
*****************************************************************************/
typedef enum en_tim0_m1_mscr_ib0s
{
Tim0IB0Input = 0u, ///< IBO输入
Tim0TsInput = 1u, ///< 内部触发TS选择信号
}en_tim0_m1_mscr_ib0s_t;
/**
******************************************************************************
** \brief (CCPA0/CCPB0/ETP/BKP)(1/23)
*****************************************************************************/
typedef enum en_tim0_port_polarity
{
Tim0PortPositive = 0u, ///< 正常输入输出
Tim0PortOpposite = 1u, ///< 反向输入输出
}en_tim0_port_polarity_t;
/**
******************************************************************************
** \brief (FLTET/FLTA0/FLAB0)(1/23)
*****************************************************************************/
typedef enum en_tim0_flt
{
Tim0FltNone = 0u, ///< 无滤波
Tim0FltPCLKCnt3 = 4u, ///< PCLK 3个连续有效
Tim0FltPCLKDiv4Cnt3 = 5u, ///< PCLK/4 3个连续有效
Tim0FltPCLKDiv16Cnt3 = 6u, ///< PCLK/16 3个连续有效
Tim0FltPCLKDiv64Cnt3 = 7u, ///< PCLK/64 3个连续有效
}en_tim0_flt_t;
/**
******************************************************************************
** \brief (OCMA/OCMB)(23)
*****************************************************************************/
typedef enum en_tim0_m23_fltr_ocm
{
Tim0ForceLow = 0u, ///< 强制为0
Tim0ForceHigh = 1u, ///< 强制为1
Tim0CMPForceLow = 2u, ///< 比较匹配时强制为0
Tim0CMPForceHigh = 3u, ///< 比较匹配时强制为1
Tim0CMPInverse = 4u, ///< 比较匹配时翻转电平
Tim0CMPOnePrdHigh = 5u, ///< 比较匹配时输出一个计数周期的高电平
Tim0PWMMode1 = 6u, ///< 通道控制为PWM mode 1
Tim0PWMMode2 = 7u, ///< 通道控制为PWM mode 2
}en_tim0_m23_fltr_ocm_t;
/**
******************************************************************************
** \brief TS数据类型重定义 (TS)(1/23)
*****************************************************************************/
typedef enum en_tim0_mscr_ts
{
Tim0Ts0ETR = 0u, ///< ETR外部输入滤波后的相位选择信号
Tim0Ts1TIM0TRGO = 1u, ///< Timer0的TRGO输出信号
Tim0Ts2TIM1TRGO = 2u, ///< Timer1的TRGO输出信号
Tim0Ts3TIM2TRGO = 3u, ///< Timer2的TRGO输出信号
Tim0Ts4TIM3TRGO = 4u, ///< Timer3的TRGO输出信号
//Tim0Ts5IA0ED = 5u, ///< 无效
Tim0Ts6IAFP = 6u, ///< CH0A 外部输输入滤波后的相位选择信号
Tim0Ts7IBFP = 7u, ///< CH0B 外部输输入滤波后的相位选择信
}en_tim0_mscr_ts_t;
/**
******************************************************************************
** \brief PWM输出模式选择数据类型重定义 (COMP)(23)
*****************************************************************************/
typedef enum en_tim0_m23cr_comp
{
Tim0IndependentPWM = 0u, ///< 独立PWM输出
Tim0ComplementaryPWM = 1u, ///< 互补PWM输出
}en_tim0_m23cr_comp_t;
/**
******************************************************************************
** \brief (DIR)(23)
*****************************************************************************/
typedef enum en_tim0_m23cr_dir
{
Tim0CntUp = 0u, ///< 向上计数
Tim0CntDown = 1u, ///< 向下计数
}en_tim0_m23cr_dir_t;
/**
******************************************************************************
** \brief (PWM2S)(23)
*****************************************************************************/
typedef enum en_tim0_m23cr_pwm2s
{
Tim0DoublePointCmp = 0u, ///< 双点比较使能使用CCRA,CCRB比较控制OCREFA输出
Tim0SinglePointCmp = 1u, ///< 单点比较使能使用CCRA比较控制OCREFA输出
}en_tim0_m23cr_pwm2s_t;
/**
******************************************************************************
** \brief GATE在PWM互补模式下捕获或比较功能 (CSG)(23)
*****************************************************************************/
typedef enum en_tim0_m23cr_csg
{
Tim0PWMCompGateCmpOut = 0u, ///< 在PWM互补模式下Gate作为比较输出
Tim0PWMCompGateCapIn = 1u, ///< 在PWM互补模式下Gate作为捕获输入
}en_tim0_m23cr_csg_t;
/**
******************************************************************************
** \brief (CCR0A,CCR0B)(23)
*****************************************************************************/
typedef enum en_tim0_m23_ccrx
{
Tim0CCR0A = 0u, ///< CCR0A比较捕获寄存器
Tim0CCR0B = 1u, ///< CCR0B比较捕获寄存器
Tim0CCR1A = 2u, ///< CCR1A比较捕获寄存器
Tim0CCR1B = 3u, ///< CCR1B比较捕获寄存器
Tim0CCR2A = 4u, ///< CCR2A比较捕获寄存器
Tim0CCR2B = 5u, ///< CCR2B比较捕获寄存器
}en_tim0_m23_ccrx_t;
/**
******************************************************************************
** \brief OCREF清除源 (OCCS)(23)
*****************************************************************************/
typedef enum en_tim0_m23ce_occs
{
Tim0OC_Ref_Clr = 0u, ///< 来自VC的OC_Ref_Clr
Tim0ETRf = 1u, ///< 外部ETRf
}en_tim0_m23ce_occs_t;
/**
******************************************************************************
** \brief (CIS/CISB)(23)
*****************************************************************************/
typedef enum en_tim0_m23_cisa_cisb
{
Tim0CmpIntNone = 0u, ///< 无比较匹配中断
Tim0CmpIntRise = 1u, ///< 比较匹配上升沿中断
Tim0CmpIntFall = 2u, ///< 比较匹配下降沿中断
Tim0CmpIntRiseFall = 3u, ///< 比较匹配上升沿下降沿中断
}en_tim0_m23_cisa_cisb_t;
/**
******************************************************************************
** \brief TIM3端口控制 - CHx输出状态控制(BKSA/BKSB)(23)
**
** \note
******************************************************************************/
typedef enum en_tim0_m23_crchx_bks
{
Tim0CHxBksHiZ = 0u, ///< 刹车使能时CHx端口输出高阻态
Tim0CHxBksNorm = 1u, ///< 刹车使能时CHx端口正常输出
Tim0CHxBksLow = 2u, ///< 刹车使能时CHx端口输出低电平
Tim0CHxBksHigh = 3u, ///< 刹车使能时CHx端口输出高电平
}en_tim0_m23_crchx_bks_t;
/**
******************************************************************************
** \brief TIM3端口控制 - CHx上升沿下降沿捕获(CRx/CFx)(23)
**
** \note
******************************************************************************/
typedef enum en_tim0_m23_crch0_cfx_crx
{
Tim0CHxCapNone = 0u, ///< CHx通道捕获禁止
Tim0CHxCapRise = 1u, ///< CHx通道上升沿捕获使能
Tim0CHxCapFall = 2u, ///< CHx通道下降沿捕获使能
Tim0CHxCapFallRise = 3u, ///< CHx通道上升沿下降沿捕获都使能
}en_tim0_m23_crch0_cfx_crx_t;
/**
******************************************************************************
** \brief TIM3端口控制 - CHx比较捕获模式(CSA/CSB)(23)
**
** \note
******************************************************************************/
typedef enum en_tim0_m23_crch0_csa_csb
{
Tim0CHxCmpMode = 0u, ///< CHx通道设置为比较模式
Tim0CHxCapMode = 1u, ///< CHx通道设置为捕获模式
}en_tim0_m23_crch0_csa_csb_t;
/**
******************************************************************************
** \brief DMA比较触发选择 (CCDS)(23)
*****************************************************************************/
typedef enum en_tim0_m23_mscr_ccds
{
Tim0CmpTrigDMA = 0u, ///< 比较匹配触发DMA
Tim0UEVTrigDMA = 1u, ///< 事件更新代替比较匹配触发DMA
}en_tim0_m23_mscr_ccds_t;
/**
******************************************************************************
** \brief (MSM)(23)
*****************************************************************************/
typedef enum en_tim0_m23_mscr_msm
{
Tim0SlaveMode = 0u, ///< 从模式
Tim0MasterMode = 1u, ///< 主模式
}en_tim0_m23_mscr_msm_t;
/**
******************************************************************************
** \brief (MMS)(23)
*****************************************************************************/
typedef enum en_tim0_m23_mscr_mms
{
Tim0MasterUG = 0u, ///< UG(软件更新)源
Tim0MasterCTEN = 1u, ///< CTEN源
Tim0MasterUEV = 2u, ///< UEV更新源
Tim0MasterCMPSO = 3u, ///< 比较匹配选择输出源
Tim0MasterOCA0Ref = 4u, ///< OCA0_Ref源
Tim0MasterOCB0Ref = 5u, ///< OCB0_Ref源
//Tim0MasterOCB0Ref = 6u,
//Tim0MasterOCB0Ref = 7u,
}en_tim0_m23_mscr_mms_t;
/**
******************************************************************************
** \brief (SMS)(23)
*****************************************************************************/
typedef enum en_tim0_m23_mscr_sms
{
Tim0SlaveIClk = 0u, ///< 使用内部时钟
Tim0SlaveResetTIM = 1u, ///< 复位功能
Tim0SlaveTrigMode = 2u, ///< 触发模式
Tim0SlaveEClk = 3u, ///< 外部时钟模式
Tim0SlaveCodeCnt1 = 4u, ///< 正交编码计数模式1
Tim0SlaveCodeCnt2 = 5u, ///< 正交编码计数模式2
Tim0SlaveCodeCnt3 = 6u, ///< 正交编码计数模式3
Tim0SlaveGateCtrl = 7u, ///< 门控功能
}en_tim0_m23_mscr_sms_t;
/**
******************************************************************************
** \brief (CTEN)
*****************************************************************************/
typedef enum en_tim0_start
{
Tim0CTENDisable = 0u, ///< 停止
Tim0CTENEnable = 1u, ///< 运行
}en_tim0_start_t;
/**
******************************************************************************
** \brief TIM3 mode0 (0)
*****************************************************************************/
typedef struct stc_tim0_mode0_config
{
en_tim0_work_mode_t enWorkMode; ///< 工作模式设置
en_tim0_m0cr_gatep_t enGateP; ///< 门控极性控制
boolean_t bEnGate; ///< 门控使能
en_tim0_cr_timclkdiv_t enPRS; ///< 预除频配置
boolean_t bEnTog; ///< 翻转输出使能
en_tim0_cr_ct_t enCT; ///< 定时/计数功能选择
en_tim0_m0cr_md_t enCntMode; ///< 计数模式配置
func_ptr_t pfnTim0Cb; ///< Timer3中断服务回调函数[void function(void)]
}stc_tim0_mode0_config_t;
/**
******************************************************************************
** \brief TIM3 mode1 (1)
*****************************************************************************/
typedef struct stc_tim0_mode1_config
{
en_tim0_work_mode_t enWorkMode; ///< 工作模式设置
en_tim0_cr_timclkdiv_t enPRS; ///< 预除频配置
en_tim0_cr_ct_t enCT; ///< 定时/计数功能选择
en_tim0_m1cr_oneshot_t enOneShot; ///< 单次测量/循环测量选择
func_ptr_t pfnTim0Cb; ///< Timer3中断服务回调函数[void function(void)]
}stc_tim0_mode1_config_t;
/**
******************************************************************************
** \brief PWC输入配置结构体定义(1)
*****************************************************************************/
typedef struct stc_tim0_pwc_input_config
{
en_tim0_mscr_ts_t enTsSel; ///< 触发输入源选择
en_tim0_m1_mscr_ia0s_t enIA0Sel; ///< CHA0输入选择
en_tim0_m1_mscr_ib0s_t enIB0Sel; ///< CHB0输入选择
en_tim0_port_polarity_t enETRPhase; ///< ETR相位选择
en_tim0_flt_t enFltETR; ///< ETR滤波设置
en_tim0_flt_t enFltIA0; ///< CHA0滤波设置
en_tim0_flt_t enFltIB0; ///< CHB0滤波设置
}stc_tim0_pwc_input_config_t;
/**
******************************************************************************
** \brief TIM3 mode23 (23)
*****************************************************************************/
typedef struct stc_tim0_mode23_config
{
en_tim0_work_mode_t enWorkMode; ///< 工作模式设置
en_tim0_m23cr_dir_t enCntDir; ///< 计数方向
en_tim0_cr_timclkdiv_t enPRS; ///< 时钟预除频配置
en_tim0_cr_ct_t enCT; ///< 定时/计数功能选择
en_tim0_m23cr_comp_t enPWMTypeSel; ///< PWM模式选择独立/互补)
en_tim0_m23cr_pwm2s_t enPWM2sSel; ///< OCREFA双点比较功能选择
boolean_t bOneShot; ///< 单次触发模式使能/禁止
boolean_t bURSSel; ///< 更新源选择
func_ptr_t pfnTim0Cb; ///< Timer3中断服务回调函数[void function(void)]
}stc_tim0_mode23_config_t;
/**
******************************************************************************
** \brief GATE在PWM互补模式下捕获或比较功能 (23)
*****************************************************************************/
typedef struct stc_tim0_m23_gate_config
{
en_tim0_m23cr_csg_t enGateFuncSel; ///< Gate比较、捕获功能选择
boolean_t bGateRiseCap; ///< GATE作为捕获功能时上沿捕获有效控制
boolean_t bGateFallCap; ///< GATE作为捕获功能时下沿捕获有效控制
}stc_tim0_m23_gate_config_t;
/**
******************************************************************************
** \brief CHA/CHB通道比较控制 (23)
*****************************************************************************/
typedef struct stc_tim0_m23_compare_config
{
en_tim0_m23_crch0_csa_csb_t enCHxACmpCap; ///< CH0A比较/捕获功能选择
en_tim0_m23_fltr_ocm_t enCHxACmpCtrl; ///< CH0A通道比较控制
en_tim0_port_polarity_t enCHxAPolarity; ///< CH0A输出极性控制
boolean_t bCHxACmpBufEn; ///< 比较A缓存功能 使能/禁止
en_tim0_m23_cisa_cisb_t enCHxACmpIntSel; ///< CHA比较匹配中断选择
en_tim0_m23_crch0_csa_csb_t enCHxBCmpCap; ///< CH0B比较/捕获功能选择
en_tim0_m23_fltr_ocm_t enCHxBCmpCtrl; ///< CH0B通道比较控制
en_tim0_port_polarity_t enCHxBPolarity; ///< CH0B输出极性控制
boolean_t bCHxBCmpBufEn; ///< 比较B缓存功能 使能/禁止
en_tim0_m23_cisa_cisb_t enCHxBCmpIntSel; ///< CHB0比较匹配中断选择
}stc_tim0_m23_compare_config_t;
/**
******************************************************************************
** \brief CHA/CHB通道捕获控制 (23)
*****************************************************************************/
typedef struct stc_tim0_m23_input_config
{
en_tim0_m23_crch0_csa_csb_t enCHxACmpCap; ///< CH0A比较/捕获功能选择
en_tim0_m23_crch0_cfx_crx_t enCHxACapSel; ///< CH0A捕获边沿选择
en_tim0_flt_t enCHxAInFlt; ///< CH0A通道捕获滤波控制
en_tim0_port_polarity_t enCHxAPolarity; ///< CH0A输入相位
en_tim0_m23_crch0_csa_csb_t enCHxBCmpCap; ///< CH0A比较/捕获功能选择
en_tim0_m23_crch0_cfx_crx_t enCHxBCapSel; ///< CH0B捕获边沿选择
en_tim0_flt_t enCHxBInFlt; ///< CH0B通道捕获滤波控制
en_tim0_port_polarity_t enCHxBPolarity; ///< CH0B输入相位
}stc_tim0_m23_input_config_t;
/**
******************************************************************************
** \brief ETR输入相位滤波配置结构体定义(23)
*****************************************************************************/
typedef struct stc_tim0_m23_etr_input_config
{
en_tim0_port_polarity_t enETRPolarity; ///< ETR输入极性设置
en_tim0_flt_t enETRFlt; ///< ETR滤波设置
}stc_tim0_m23_etr_input_config_t;
/**
******************************************************************************
** \brief BK输入相位滤波配置结构体定义(23)
*****************************************************************************/
typedef struct stc_tim0_m23_bk_input_config
{
boolean_t bEnBrake; ///< 刹车使能
boolean_t bEnVC0Brake; ///< 使能VC0刹车
boolean_t bEnVC1Brake; ///< 使能VC1刹车
boolean_t bEnSafetyBk; ///< 使能safety刹车
boolean_t bEnBKSync; ///< TIM0/TIM1/TIM2刹车同步使能
en_tim0_m23_crchx_bks_t enBkCH0AStat; ///< 刹车时CHA端口状态设置
en_tim0_m23_crchx_bks_t enBkCH0BStat; ///< 刹车时CHB端口状态设置
en_tim0_m23_crchx_bks_t enBkCH1AStat; ///< 刹车时CHA端口状态设置
en_tim0_m23_crchx_bks_t enBkCH1BStat; ///< 刹车时CHB端口状态设置
en_tim0_m23_crchx_bks_t enBkCH2AStat; ///< 刹车时CHA端口状态设置
en_tim0_m23_crchx_bks_t enBkCH2BStat; ///< 刹车时CHB端口状态设置
en_tim0_port_polarity_t enBrakePolarity; ///< 刹车BK输入极性设置
en_tim0_flt_t enBrakeFlt; ///< 刹车BK滤波设置
}stc_tim0_m23_bk_input_config_t;
/**
******************************************************************************
** \brief (23)
*****************************************************************************/
typedef struct stc_tim0_m23_dt_config
{
boolean_t bEnDeadTime; ///< 刹车时CHA端口状态设置
uint8_t u8DeadTimeValue; ///< 刹车时CHA端口状态设置
}stc_tim0_m23_dt_config_t;
/**
******************************************************************************
** \brief ADC配置结构体定义(23)
*****************************************************************************/
typedef struct stc_tim0_m23_adc_trig_config
{
boolean_t bEnTrigADC; ///< 触发ADC全局控制
boolean_t bEnUevTrigADC; ///< 事件更新触发ADC
boolean_t bEnCH0ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH0BCmpTrigADC; ///< CH0B比较匹配触发ADC
boolean_t bEnCH1ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH1BCmpTrigADC; ///< CH0B比较匹配触发ADC
boolean_t bEnCH2ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH2BCmpTrigADC; ///< CH0B比较匹配触发ADC
}stc_tim0_m23_adc_trig_config_t;
/**
******************************************************************************
** \brief DMA触发 (23)
*****************************************************************************/
typedef struct stc_tim0_m23_trig_dma_config
{
boolean_t bUevTrigDMA; ///< 更新 触发DMA使能
boolean_t bTITrigDMA; ///< Trig 触发DMA功能
boolean_t bCmpA0TrigDMA; ///< CH0A捕获比较触发DMA使能
boolean_t bCmpB0TrigDMA; ///< CH0B捕获比较触发DMA使能
boolean_t bCmpA1TrigDMA; ///< CH1A捕获比较触发DMA使能
boolean_t bCmpB1TrigDMA; ///< CH1B捕获比较触发DMA使能
boolean_t bCmpA2TrigDMA; ///< CH2A捕获比较触发DMA使能
boolean_t bCmpB2TrigDMA; ///< CH2B捕获比较触发DMA使能
en_tim0_m23_mscr_ccds_t enCmpUevTrigDMA; ///< 比较模式下DMA比较触发选择
}stc_tim0_m23_trig_dma_config_t;
/**
******************************************************************************
** \brief (23)
*****************************************************************************/
typedef struct stc_tim0_m23_master_slave_config
{
en_tim0_m23_mscr_msm_t enMasterSlaveSel; ///< 主从模式选择
en_tim0_m23_mscr_mms_t enMasterSrc; ///< 主模式触发源选择
en_tim0_m23_mscr_sms_t enSlaveModeSel; ///< 从模式选择
en_tim0_mscr_ts_t enTsSel; ///< 触发输入源选择
}stc_tim0_m23_master_slave_config_t;
/**
******************************************************************************
** \brief OCREF清除功能 (23)
*****************************************************************************/
typedef struct stc_tim0_m23_OCREF_Clr_config
{
en_tim0_m23ce_occs_t enOCRefClrSrcSel; ///< OCREF清除源选择
boolean_t bVCClrEn; ///< 是否使能来自VC的OCREF_Clr
}stc_tim0_m23_OCREF_Clr_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//中断相关函数
//中断标志获取
boolean_t Tim0_GetIntFlag(en_tim0_irq_type_t enTim0Irq);
//中断标志清除
en_result_t Tim0_ClearIntFlag(en_tim0_irq_type_t enTim0Irq);
//所有中断标志清除
en_result_t Tim0_ClearAllIntFlag(void);
//模式0中断使能
en_result_t Tim0_Mode0_EnableIrq(void);
//模式1中断使能
en_result_t Tim0_Mode1_EnableIrq (en_tim0_irq_type_t enTim0Irq);
//模式2中断使能
en_result_t Tim0_Mode23_EnableIrq (en_tim0_irq_type_t enTim0Irq);
//模式0中断禁止
en_result_t Tim0_Mode0_DisableIrq(void);
//模式1中断禁止
en_result_t Tim0_Mode1_DisableIrq (en_tim0_irq_type_t enTim0Irq);
//模式2中断禁止
en_result_t Tim0_Mode23_DisableIrq (en_tim0_irq_type_t enTim0Irq);
//模式0初始化及相关功能操作
//timer配置及初始化
en_result_t Tim0_Mode0_Init(stc_tim0_mode0_config_t* pstcConfig);
//timer 启动/停止
en_result_t Tim0_M0_Run(void);
en_result_t Tim0_M0_Stop(void);
//重载值设置
en_result_t Tim0_M0_ARRSet(uint16_t u16Data);
//16位计数值设置/获取
en_result_t Tim0_M0_Cnt16Set(uint16_t u16Data);
uint16_t Tim0_M0_Cnt16Get(void);
//32位计数值设置/获取
en_result_t Tim0_M0_Cnt32Set(uint32_t u32Data);
uint32_t Tim0_M0_Cnt32Get(void);
//翻转输出使能/禁止设定
en_result_t Tim0_M0_EnTOG_Output(boolean_t bEnOutput);
//模式1初始化及相关功能操作
//timer配置及初始化
en_result_t Tim0_Mode1_Init(stc_tim0_mode1_config_t* pstcConfig);
//PWC 输入配置
en_result_t Tim0_M1_Input_Config(stc_tim0_pwc_input_config_t* pstcConfig);
//PWC测量边沿起始结束选择
en_result_t Tim0_M1_PWC_Edge_Sel(en_tim0_m1cr_Edge_t enEdgeSel);
//timer 启动/停止
en_result_t Tim0_M1_Run(void);
en_result_t Tim0_M1_Stop(void);
//16位计数值设置/获取
en_result_t Tim0_M1_Cnt16Set(uint16_t u16Data);
uint16_t Tim0_M1_Cnt16Get(void);
//脉冲宽度测量结果数值获取
uint16_t Tim0_M1_PWC_CapValueGet(void);
//模式1初始化及相关功能操作
//timer配置及初始化
en_result_t Tim0_Mode23_Init(stc_tim0_mode23_config_t* pstcConfig);
//timer 启动/停止
en_result_t Tim0_M23_Run(void);
en_result_t Tim0_M23_Stop(void);
//PWM输出使能
en_result_t Tim0_M23_EnPWM_Output(boolean_t bEnOutput, boolean_t bEnAutoOutput);
//重载值设置
en_result_t Tim0_M23_ARRSet(uint16_t u16Data, boolean_t bArrBufEn);
//16位计数值设置/获取
en_result_t Tim0_M23_Cnt16Set(uint16_t u16Data);
uint16_t Tim0_M23_Cnt16Get(void);
//比较捕获寄存器CCR0A/CCR0B设置/读取
en_result_t Tim0_M23_CCR_Set(en_tim0_m23_ccrx_t enCCRSel, uint16_t u16Data);
uint16_t Tim0_M23_CCR_Get(en_tim0_m23_ccrx_t enCCRSel);
//PWM互补输出模式下GATE功能选择
en_result_t Tim0_M23_GateFuncSel(stc_tim0_m23_gate_config_t* pstcConfig);
//主从模式配置
en_result_t Tim0_M23_MasterSlave_Set(stc_tim0_m23_master_slave_config_t* pstcConfig);
//CH0A/CH0B比较通道控制
en_result_t Tim0_M23_PortOutput_Config(en_tim0_channel_t enTim0Chx, stc_tim0_m23_compare_config_t* pstcConfig);
//CH0A/CH0B输入控制
en_result_t Tim0_M23_PortInput_Config(en_tim0_channel_t enTim0Chx, stc_tim0_m23_input_config_t* pstcConfig);
//ERT输入控制
en_result_t Tim0_M23_ETRInput_Config(stc_tim0_m23_etr_input_config_t* pstcConfig);
//刹车BK输入控制
en_result_t Tim0_M23_BrakeInput_Config(stc_tim0_m23_bk_input_config_t* pstcConfig);
//触发ADC控制
en_result_t Tim0_M23_TrigADC_Config(stc_tim0_m23_adc_trig_config_t* pstcConfig);
//死区功能
en_result_t Tim0_M23_DT_Config(stc_tim0_m23_dt_config_t* pstcConfig);
//重复周期设置
en_result_t Tim0_M23_SetValidPeriod(uint8_t u8ValidPeriod);
//OCREF清除功能
en_result_t Tim0_M23_OCRefClr(stc_tim0_m23_OCREF_Clr_config_t* pstcConfig);
//使能DMA传输
en_result_t Tim0_M23_EnDMA(stc_tim0_m23_trig_dma_config_t* pstcConfig);
//捕获比较A软件触发
en_result_t Tim0_M23_EnSwTrigCapCmpA(en_tim0_channel_t enTim0Chx);
//捕获比较B软件触发
en_result_t Tim0_M23_EnSwTrigCapCmpB(en_tim0_channel_t enTim0Chx);
//软件更新使能
en_result_t Tim0_M23_EnSwUev(void);
//软件触发使能
en_result_t Tim0_M23_EnSwTrig(void);
//软件刹车使能
en_result_t Tim0_M23_EnSwBk(void);
//@} // Tim0Group
#ifdef __cplusplus
#endif
#endif /* __BT_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,788 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file bt.h
**
** API声明
** @link BT Timer3 Group Some description @endlink
**
** History:
** - 2018-04-29 Husj First Version
**
*****************************************************************************/
#ifndef __TIMER3_H__
#define __TIMER3_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup Tim3Group Base Timer (BT)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief Timer3
*****************************************************************************/
typedef enum en_tim3_channel
{
Tim3CH0 = 0u, ///< Timer3通道0
Tim3CH1 = 1u, ///< Timer3通道1
Tim3CH2 = 2u, ///< Timer3通道2
}en_tim3_channel_t;
/**
******************************************************************************
** \brief (MODE)(0/1/23)
*****************************************************************************/
typedef enum en_tim3_work_mode
{
Tim3WorkMode0 = 0u, ///< 定时器模式
Tim3WorkMode1 = 1u, ///< PWC模式
Tim3WorkMode2 = 2u, ///< 锯齿波模式
Tim3WorkMode3 = 3u, ///< 三角波模式
}en_tim3_work_mode_t;
/**
******************************************************************************
** \brief (GATE_P)(0)
*****************************************************************************/
typedef enum en_tim3_m0cr_gatep
{
Tim3GatePositive = 0u, ///< 高电平有效
Tim3GateOpposite = 1u, ///< 低电平有效
}en_tim3_m0cr_gatep_t;
/**
******************************************************************************
** \brief TIM3 (PRS)(0/1/23)
*****************************************************************************/
typedef enum en_tim3_cr_timclkdiv
{
Tim3PCLKDiv1 = 0u, ///< Div 1
Tim3PCLKDiv2 = 1u, ///< Div 2
Tim3PCLKDiv4 = 2u, ///< Div 4
Tim3PCLKDiv8 = 3u, ///< Div 8
Tim3PCLKDiv16 = 4u, ///< Div 16
Tim3PCLKDiv32 = 5u, ///< Div 32
Tim3PCLKDiv64 = 6u, ///< Div 64
Tim3PCLKDiv256 = 7u, ///< Div 256
}en_tim3_cr_timclkdiv_t;
/**
******************************************************************************
** \brief / (CT)(0/1/23)
*****************************************************************************/
typedef enum en_tim3_cr_ct
{
Tim3Timer = 0u, ///< 定时器功能计数时钟为内部PCLK
Tim3Counter = 1u, ///< 计数器功能计数时钟为外部ETR
}en_tim3_cr_ct_t;
/**
******************************************************************************
** \brief (MD)(0)
*****************************************************************************/
typedef enum en_tim3_m0cr_md
{
Tim332bitFreeMode = 0u, ///< 32位计数器/定时器
Tim316bitArrMode = 1u, ///< 自动重装载16位计数器/定时器
}en_tim3_m0cr_md_t;
/**
******************************************************************************
** \brief TIM3中断类型数据类型重定义(0/1/23)
*****************************************************************************/
typedef enum en_tim3_irq_type
{
Tim3UevIrq = 0u, ///< 溢出/事件更新中断
Tim3CA0Irq = 2u, ///< CH0A捕获/比较中断(仅模式1/23存在)
Tim3CA1Irq = 3u, ///< CH1A捕获/比较中断(仅模式23存在)
Tim3CA2Irq = 4u, ///< CH2A捕获/比较中断(仅模式23存在)
Tim3CB0Irq = 5u, ///< CH0B捕获/比较中断(仅模式23存在)
Tim3CB1Irq = 6u, ///< CH1B捕获/比较中断(仅模式23存在)
Tim3CB2Irq = 7u, ///< CH2B捕获/比较中断(仅模式23存在)
Tim3CA0E = 8u, ///< CH0A捕获数据丢失标志(仅模式23存在)(不是中断)
Tim3CA1E = 9u, ///< CH1A捕获数据丢失标志(仅模式23存在)(不是中断)
Tim3CA2E = 10u, ///< CH2A捕获数据丢失标志(仅模式23存在)(不是中断)
Tim3CB0E = 11u, ///< CH0B捕获数据丢失标志(仅模式23存在)(不是中断)
Tim3CB1E = 12u, ///< CH1B捕获数据丢失标志(仅模式23存在)(不是中断)
Tim3CB2E = 13u, ///< CH2B捕获数据丢失标志(仅模式23存在)(不是中断)
Tim3BkIrq = 14u, ///< 刹车中断(仅模式23存在
Tim3TrigIrq = 15u, ///< 触发中断(仅模式23存在
}en_tim3_irq_type_t;
/**
******************************************************************************
** \brief (Edg1stEdg2nd)(1)
*****************************************************************************/
typedef enum en_tim3_m1cr_Edge
{
Tim3PwcRiseToRise = 0u, ///< 上升沿到上升沿(周期)
Tim3PwcFallToRise = 1u, ///< 下降沿到上升沿(低电平)
Tim3PwcRiseToFall = 2u, ///< 上升沿到下降沿(高电平)
Tim3PwcFallToFall = 3u, ///< 下降沿到下降沿(周期)
}en_tim3_m1cr_Edge_t;
/**
******************************************************************************
** \brief PWC测量测试模式选择数据类型重定义 (Oneshot)(1)
*****************************************************************************/
typedef enum en_tim3_m1cr_oneshot
{
Tim3PwcCycleDetect = 0u, ///< PWC循环测量
Tim3PwcOneShotDetect = 1u, ///< PWC单次测量
}en_tim3_m1cr_oneshot_t;
/**
******************************************************************************
** \brief PWC IA0选择数据类型重定义 (IA0S)(1)
*****************************************************************************/
typedef enum en_tim3_m1_mscr_ia0s
{
Tim3IA0Input = 0u, ///< IAO输入
Tim3XORInput = 1u, ///< IA0 ETR GATE XOR(TIM0/1/2)/IA0 IA1 IA2 XOR(TIM3)
}en_tim3_m1_mscr_ia0s_t;
/**
******************************************************************************
** \brief PWC IB0选择数据类型重定义 (IA0S)(1)
*****************************************************************************/
typedef enum en_tim3_m1_mscr_ib0s
{
Tim3IB0Input = 0u, ///< IBO输入
Tim3TsInput = 1u, ///< 内部触发TS选择信号
}en_tim3_m1_mscr_ib0s_t;
/**
******************************************************************************
** \brief (CCPA0/CCPB0/ETP/BKP)(1/23)
*****************************************************************************/
typedef enum en_tim3_port_polarity
{
Tim3PortPositive = 0u, ///< 正常输入输出
Tim3PortOpposite = 1u, ///< 反向输入输出
}en_tim3_port_polarity_t;
/**
******************************************************************************
** \brief (FLTET/FLTA0/FLAB0)(1/23)
*****************************************************************************/
typedef enum en_tim3_flt
{
Tim3FltNone = 0u, ///< 无滤波
Tim3FltPCLKCnt3 = 4u, ///< PCLK 3个连续有效
Tim3FltPCLKDiv4Cnt3 = 5u, ///< PCLK/4 3个连续有效
Tim3FltPCLKDiv16Cnt3 = 6u, ///< PCLK/16 3个连续有效
Tim3FltPCLKDiv64Cnt3 = 7u, ///< PCLK/64 3个连续有效
}en_tim3_flt_t;
/**
******************************************************************************
** \brief (OCMA/OCMB)(23)
*****************************************************************************/
typedef enum en_tim3_m23_fltr_ocm
{
Tim3ForceLow = 0u, ///< 强制为0
Tim3ForceHigh = 1u, ///< 强制为1
Tim3CMPForceLow = 2u, ///< 比较匹配时强制为0
Tim3CMPForceHigh = 3u, ///< 比较匹配时强制为1
Tim3CMPInverse = 4u, ///< 比较匹配时翻转电平
Tim3CMPOnePrdHigh = 5u, ///< 比较匹配时输出一个计数周期的高电平
Tim3PWMMode1 = 6u, ///< 通道控制为PWM mode 1
Tim3PWMMode2 = 7u, ///< 通道控制为PWM mode 2
}en_tim3_m23_fltr_ocm_t;
/**
******************************************************************************
** \brief TS数据类型重定义 (TS)(1/23)
*****************************************************************************/
typedef enum en_tim3_mscr_ts
{
Tim3Ts0ETR = 0u, ///< ETR外部输入滤波后的相位选择信号
Tim3Ts1TIM0TRGO = 1u, ///< Timer0的TRGO输出信号
Tim3Ts2TIM1TRGO = 2u, ///< Timer1的TRGO输出信号
Tim3Ts3TIM2TRGO = 3u, ///< Timer2的TRGO输出信号
Tim3Ts4TIM3TRGO = 4u, ///< Timer3的TRGO输出信号
//Tim3Ts5IA0ED = 5u, ///< 无效
Tim3Ts6IAFP = 6u, ///< CH0A 外部输输入滤波后的相位选择信号
Tim3Ts7IBFP = 7u, ///< CH0B 外部输输入滤波后的相位选择信
}en_tim3_mscr_ts_t;
/**
******************************************************************************
** \brief PWM输出模式选择数据类型重定义 (COMP)(23)
*****************************************************************************/
typedef enum en_tim3_m23cr_comp
{
Tim3IndependentPWM = 0u, ///< 独立PWM输出
Tim3ComplementaryPWM = 1u, ///< 互补PWM输出
}en_tim3_m23cr_comp_t;
/**
******************************************************************************
** \brief (DIR)(23)
*****************************************************************************/
typedef enum en_tim3_m23cr_dir
{
Tim3CntUp = 0u, ///< 向上计数
Tim3CntDown = 1u, ///< 向下计数
}en_tim3_m23cr_dir_t;
/**
******************************************************************************
** \brief (PWM2S)(23)
*****************************************************************************/
typedef enum en_tim3_m23cr_pwm2s
{
Tim3DoublePointCmp = 0u, ///< 双点比较使能使用CCRA,CCRB比较控制OCREFA输出
Tim3SinglePointCmp = 1u, ///< 单点比较使能使用CCRA比较控制OCREFA输出
}en_tim3_m23cr_pwm2s_t;
/**
******************************************************************************
** \brief GATE在PWM互补模式下捕获或比较功能 (CSG)(23)
*****************************************************************************/
typedef enum en_tim3_m23cr_csg
{
Tim3PWMCompGateCmpOut = 0u, ///< 在PWM互补模式下Gate作为比较输出
Tim3PWMCompGateCapIn = 1u, ///< 在PWM互补模式下Gate作为捕获输入
}en_tim3_m23cr_csg_t;
/**
******************************************************************************
** \brief (CCR0A,CCR0B)(23)
*****************************************************************************/
typedef enum en_tim3_m23_ccrx
{
Tim3CCR0A = 0u, ///< CCR0A比较捕获寄存器
Tim3CCR0B = 1u, ///< CCR0B比较捕获寄存器
Tim3CCR1A = 2u, ///< CCR1A比较捕获寄存器
Tim3CCR1B = 3u, ///< CCR1B比较捕获寄存器
Tim3CCR2A = 4u, ///< CCR2A比较捕获寄存器
Tim3CCR2B = 5u, ///< CCR2B比较捕获寄存器
}en_tim3_m23_ccrx_t;
/**
******************************************************************************
** \brief OCREF清除源 (OCCS)(23)
*****************************************************************************/
typedef enum en_tim3_m23ce_occs
{
Tim3OC_Ref_Clr = 0u, ///< 来自VC的OC_Ref_Clr
Tim3ETRf = 1u, ///< 外部ETRf
}en_tim3_m23ce_occs_t;
/**
******************************************************************************
** \brief (CIS/CISB)(23)
*****************************************************************************/
typedef enum en_tim3_m23_cisa_cisb
{
Tim3CmpIntNone = 0u, ///< 无比较匹配中断
Tim3CmpIntRise = 1u, ///< 比较匹配上升沿中断
Tim3CmpIntFall = 2u, ///< 比较匹配下降沿中断
Tim3CmpIntRiseFall = 3u, ///< 比较匹配上升沿下降沿中断
}en_tim3_m23_cisa_cisb_t;
/**
******************************************************************************
** \brief TIM3端口控制 - CHx输出状态控制(BKSA/BKSB)(23)
**
** \note
******************************************************************************/
typedef enum en_tim3_m23_crchx_bks
{
Tim3CHxBksHiZ = 0u, ///< 刹车使能时CHx端口输出高阻态
Tim3CHxBksNorm = 1u, ///< 刹车使能时CHx端口正常输出
Tim3CHxBksLow = 2u, ///< 刹车使能时CHx端口输出低电平
Tim3CHxBksHigh = 3u, ///< 刹车使能时CHx端口输出高电平
}en_tim3_m23_crchx_bks_t;
/**
******************************************************************************
** \brief TIM3端口控制 - CHx上升沿下降沿捕获(CRx/CFx)(23)
**
** \note
******************************************************************************/
typedef enum en_tim3_m23_crch0_cfx_crx
{
Tim3CHxCapNone = 0u, ///< CHx通道捕获禁止
Tim3CHxCapRise = 1u, ///< CHx通道上升沿捕获使能
Tim3CHxCapFall = 2u, ///< CHx通道下降沿捕获使能
Tim3CHxCapFallRise = 3u, ///< CHx通道上升沿下降沿捕获都使能
}en_tim3_m23_crch0_cfx_crx_t;
/**
******************************************************************************
** \brief TIM3端口控制 - CHx比较捕获模式(CSA/CSB)(23)
**
** \note
******************************************************************************/
typedef enum en_tim3_m23_crch0_csa_csb
{
Tim3CHxCmpMode = 0u, ///< CHx通道设置为比较模式
Tim3CHxCapMode = 1u, ///< CHx通道设置为捕获模式
}en_tim3_m23_crch0_csa_csb_t;
/**
******************************************************************************
** \brief DMA比较触发选择 (CCDS)(23)
*****************************************************************************/
typedef enum en_tim3_m23_mscr_ccds
{
Tim3CmpTrigDMA = 0u, ///< 比较匹配触发DMA
Tim3UEVTrigDMA = 1u, ///< 事件更新代替比较匹配触发DMA
}en_tim3_m23_mscr_ccds_t;
/**
******************************************************************************
** \brief (MSM)(23)
*****************************************************************************/
typedef enum en_tim3_m23_mscr_msm
{
Tim3SlaveMode = 0u, ///< 从模式
Tim3MasterMode = 1u, ///< 主模式
}en_tim3_m23_mscr_msm_t;
/**
******************************************************************************
** \brief (MMS)(23)
*****************************************************************************/
typedef enum en_tim3_m23_mscr_mms
{
Tim3MasterUG = 0u, ///< UG(软件更新)源
Tim3MasterCTEN = 1u, ///< CTEN源
Tim3MasterUEV = 2u, ///< UEV更新源
Tim3MasterCMPSO = 3u, ///< 比较匹配选择输出源
Tim3MasterOCA0Ref = 4u, ///< OCA0_Ref源
Tim3MasterOCB0Ref = 5u, ///< OCB0_Ref源
//Tim3MasterOCB0Ref = 6u,
//Tim3MasterOCB0Ref = 7u,
}en_tim3_m23_mscr_mms_t;
/**
******************************************************************************
** \brief (SMS)(23)
*****************************************************************************/
typedef enum en_tim3_m23_mscr_sms
{
Tim3SlaveIClk = 0u, ///< 使用内部时钟
Tim3SlaveResetTIM = 1u, ///< 复位功能
Tim3SlaveTrigMode = 2u, ///< 触发模式
Tim3SlaveEClk = 3u, ///< 外部时钟模式
Tim3SlaveCodeCnt1 = 4u, ///< 正交编码计数模式1
Tim3SlaveCodeCnt2 = 5u, ///< 正交编码计数模式2
Tim3SlaveCodeCnt3 = 6u, ///< 正交编码计数模式3
Tim3SlaveGateCtrl = 7u, ///< 门控功能
}en_tim3_m23_mscr_sms_t;
/**
******************************************************************************
** \brief (CTEN)
*****************************************************************************/
typedef enum en_tim3_start
{
Tim3CTENDisable = 0u, ///< 停止
Tim3CTENEnable = 1u, ///< 运行
}en_tim3_start_t;
/**
******************************************************************************
** \brief TIM3 mode0 (0)
*****************************************************************************/
typedef struct stc_tim3_mode0_config
{
en_tim3_work_mode_t enWorkMode; ///< 工作模式设置
en_tim3_m0cr_gatep_t enGateP; ///< 门控极性控制
boolean_t bEnGate; ///< 门控使能
en_tim3_cr_timclkdiv_t enPRS; ///< 预除频配置
boolean_t bEnTog; ///< 翻转输出使能
en_tim3_cr_ct_t enCT; ///< 定时/计数功能选择
en_tim3_m0cr_md_t enCntMode; ///< 计数模式配置
func_ptr_t pfnTim3Cb; ///< Timer3中断服务回调函数[void function(void)]
}stc_tim3_mode0_config_t;
/**
******************************************************************************
** \brief TIM3 mode1 (1)
*****************************************************************************/
typedef struct stc_tim3_mode1_config
{
en_tim3_work_mode_t enWorkMode; ///< 工作模式设置
en_tim3_cr_timclkdiv_t enPRS; ///< 预除频配置
en_tim3_cr_ct_t enCT; ///< 定时/计数功能选择
en_tim3_m1cr_oneshot_t enOneShot; ///< 单次测量/循环测量选择
func_ptr_t pfnTim3Cb; ///< Timer3中断服务回调函数[void function(void)]
}stc_tim3_mode1_config_t;
/**
******************************************************************************
** \brief PWC输入配置结构体定义(1)
*****************************************************************************/
typedef struct stc_tim3_pwc_input_config
{
en_tim3_mscr_ts_t enTsSel; ///< 触发输入源选择
en_tim3_m1_mscr_ia0s_t enIA0Sel; ///< CHA0输入选择
en_tim3_m1_mscr_ib0s_t enIB0Sel; ///< CHB0输入选择
en_tim3_port_polarity_t enETRPhase; ///< ETR相位选择
en_tim3_flt_t enFltETR; ///< ETR滤波设置
en_tim3_flt_t enFltIA0; ///< CHA0滤波设置
en_tim3_flt_t enFltIB0; ///< CHB0滤波设置
}stc_tim3_pwc_input_config_t;
/**
******************************************************************************
** \brief TIM3 mode23 (23)
*****************************************************************************/
typedef struct stc_tim3_mode23_config
{
en_tim3_work_mode_t enWorkMode; ///< 工作模式设置
en_tim3_m23cr_dir_t enCntDir; ///< 计数方向
en_tim3_cr_timclkdiv_t enPRS; ///< 时钟预除频配置
en_tim3_cr_ct_t enCT; ///< 定时/计数功能选择
en_tim3_m23cr_comp_t enPWMTypeSel; ///< PWM模式选择独立/互补)
en_tim3_m23cr_pwm2s_t enPWM2sSel; ///< OCREFA双点比较功能选择
boolean_t bOneShot; ///< 单次触发模式使能/禁止
boolean_t bURSSel; ///< 更新源选择
func_ptr_t pfnTim3Cb; ///< Timer3中断服务回调函数[void function(void)]
}stc_tim3_mode23_config_t;
/**
******************************************************************************
** \brief GATE在PWM互补模式下捕获或比较功能 (23)
*****************************************************************************/
typedef struct stc_tim3_m23_gate_config
{
en_tim3_m23cr_csg_t enGateFuncSel; ///< Gate比较、捕获功能选择
boolean_t bGateRiseCap; ///< GATE作为捕获功能时上沿捕获有效控制
boolean_t bGateFallCap; ///< GATE作为捕获功能时下沿捕获有效控制
}stc_tim3_m23_gate_config_t;
/**
******************************************************************************
** \brief CHA/CHB通道比较控制 (23)
*****************************************************************************/
typedef struct stc_tim3_m23_compare_config
{
en_tim3_m23_crch0_csa_csb_t enCHxACmpCap; ///< CH0A比较/捕获功能选择
en_tim3_m23_fltr_ocm_t enCHxACmpCtrl; ///< CH0A通道比较控制
en_tim3_port_polarity_t enCHxAPolarity; ///< CH0A输出极性控制
boolean_t bCHxACmpBufEn; ///< 比较A缓存功能 使能/禁止
en_tim3_m23_cisa_cisb_t enCHxACmpIntSel; ///< CHA比较匹配中断选择
en_tim3_m23_crch0_csa_csb_t enCHxBCmpCap; ///< CH0B比较/捕获功能选择
en_tim3_m23_fltr_ocm_t enCHxBCmpCtrl; ///< CH0B通道比较控制
en_tim3_port_polarity_t enCHxBPolarity; ///< CH0B输出极性控制
boolean_t bCHxBCmpBufEn; ///< 比较B缓存功能 使能/禁止
en_tim3_m23_cisa_cisb_t enCHxBCmpIntSel; ///< CHB0比较匹配中断选择
}stc_tim3_m23_compare_config_t;
/**
******************************************************************************
** \brief CHA/CHB通道捕获控制 (23)
*****************************************************************************/
typedef struct stc_tim3_m23_input_config
{
en_tim3_m23_crch0_csa_csb_t enCHxACmpCap; ///< CH0A比较/捕获功能选择
en_tim3_m23_crch0_cfx_crx_t enCHxACapSel; ///< CH0A捕获边沿选择
en_tim3_flt_t enCHxAInFlt; ///< CH0A通道捕获滤波控制
en_tim3_port_polarity_t enCHxAPolarity; ///< CH0A输入相位
en_tim3_m23_crch0_csa_csb_t enCHxBCmpCap; ///< CH0A比较/捕获功能选择
en_tim3_m23_crch0_cfx_crx_t enCHxBCapSel; ///< CH0B捕获边沿选择
en_tim3_flt_t enCHxBInFlt; ///< CH0B通道捕获滤波控制
en_tim3_port_polarity_t enCHxBPolarity; ///< CH0B输入相位
}stc_tim3_m23_input_config_t;
/**
******************************************************************************
** \brief ETR输入相位滤波配置结构体定义(23)
*****************************************************************************/
typedef struct stc_tim3_m23_etr_input_config
{
en_tim3_port_polarity_t enETRPolarity; ///< ETR输入极性设置
en_tim3_flt_t enETRFlt; ///< ETR滤波设置
}stc_tim3_m23_etr_input_config_t;
/**
******************************************************************************
** \brief BK输入相位滤波配置结构体定义(23)
*****************************************************************************/
typedef struct stc_tim3_m23_bk_input_config
{
boolean_t bEnBrake; ///< 刹车使能
boolean_t bEnVC0Brake; ///< 使能VC0刹车
boolean_t bEnVC1Brake; ///< 使能VC1刹车
boolean_t bEnSafetyBk; ///< 使能safety刹车
boolean_t bEnBKSync; ///< TIM0/TIM1/TIM2刹车同步使能
en_tim3_m23_crchx_bks_t enBkCH0AStat; ///< 刹车时CHA端口状态设置
en_tim3_m23_crchx_bks_t enBkCH0BStat; ///< 刹车时CHB端口状态设置
en_tim3_m23_crchx_bks_t enBkCH1AStat; ///< 刹车时CHA端口状态设置
en_tim3_m23_crchx_bks_t enBkCH1BStat; ///< 刹车时CHB端口状态设置
en_tim3_m23_crchx_bks_t enBkCH2AStat; ///< 刹车时CHA端口状态设置
en_tim3_m23_crchx_bks_t enBkCH2BStat; ///< 刹车时CHB端口状态设置
en_tim3_port_polarity_t enBrakePolarity; ///< 刹车BK输入极性设置
en_tim3_flt_t enBrakeFlt; ///< 刹车BK滤波设置
}stc_tim3_m23_bk_input_config_t;
/**
******************************************************************************
** \brief (23)
*****************************************************************************/
typedef struct stc_tim3_m23_dt_config
{
boolean_t bEnDeadTime; ///< 刹车时CHA端口状态设置
uint8_t u8DeadTimeValue; ///< 刹车时CHA端口状态设置
}stc_tim3_m23_dt_config_t;
/**
******************************************************************************
** \brief ADC配置结构体定义(23)
*****************************************************************************/
typedef struct stc_tim3_m23_adc_trig_config
{
boolean_t bEnTrigADC; ///< 触发ADC全局控制
boolean_t bEnUevTrigADC; ///< 事件更新触发ADC
boolean_t bEnCH0ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH0BCmpTrigADC; ///< CH0B比较匹配触发ADC
boolean_t bEnCH1ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH1BCmpTrigADC; ///< CH0B比较匹配触发ADC
boolean_t bEnCH2ACmpTrigADC; ///< CH0A比较匹配触发ADC
boolean_t bEnCH2BCmpTrigADC; ///< CH0B比较匹配触发ADC
}stc_tim3_m23_adc_trig_config_t;
/**
******************************************************************************
** \brief DMA触发 (23)
*****************************************************************************/
typedef struct stc_tim3_m23_trig_dma_config
{
boolean_t bUevTrigDMA; ///< 更新 触发DMA使能
boolean_t bTITrigDMA; ///< Trig 触发DMA功能
boolean_t bCmpA0TrigDMA; ///< CH0A捕获比较触发DMA使能
boolean_t bCmpB0TrigDMA; ///< CH0B捕获比较触发DMA使能
boolean_t bCmpA1TrigDMA; ///< CH1A捕获比较触发DMA使能
boolean_t bCmpB1TrigDMA; ///< CH1B捕获比较触发DMA使能
boolean_t bCmpA2TrigDMA; ///< CH2A捕获比较触发DMA使能
boolean_t bCmpB2TrigDMA; ///< CH2B捕获比较触发DMA使能
en_tim3_m23_mscr_ccds_t enCmpUevTrigDMA; ///< 比较模式下DMA比较触发选择
}stc_tim3_m23_trig_dma_config_t;
/**
******************************************************************************
** \brief (23)
*****************************************************************************/
typedef struct stc_tim3_m23_master_slave_config
{
en_tim3_m23_mscr_msm_t enMasterSlaveSel; ///< 主从模式选择
en_tim3_m23_mscr_mms_t enMasterSrc; ///< 主模式触发源选择
en_tim3_m23_mscr_sms_t enSlaveModeSel; ///< 从模式选择
en_tim3_mscr_ts_t enTsSel; ///< 触发输入源选择
}stc_tim3_m23_master_slave_config_t;
/**
******************************************************************************
** \brief OCREF清除功能 (23)
*****************************************************************************/
typedef struct stc_tim3_m23_OCREF_Clr_config
{
en_tim3_m23ce_occs_t enOCRefClrSrcSel; ///< OCREF清除源选择
boolean_t bVCClrEn; ///< 是否使能来自VC的OCREF_Clr
}stc_tim3_m23_OCREF_Clr_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
//中断相关函数
//中断标志获取
boolean_t Tim3_GetIntFlag(en_tim3_irq_type_t enTim3Irq);
//中断标志清除
en_result_t Tim3_ClearIntFlag(en_tim3_irq_type_t enTim3Irq);
//所有中断标志清除
en_result_t Tim3_ClearAllIntFlag(void);
//模式0中断使能
en_result_t Tim3_Mode0_EnableIrq(void);
//模式1中断使能
en_result_t Tim3_Mode1_EnableIrq (en_tim3_irq_type_t enTim3Irq);
//模式2中断使能
en_result_t Tim3_Mode23_EnableIrq (en_tim3_irq_type_t enTim3Irq);
//模式0中断禁止
en_result_t Tim3_Mode0_DisableIrq(void);
//模式1中断禁止
en_result_t Tim3_Mode1_DisableIrq (en_tim3_irq_type_t enTim3Irq);
//模式2中断禁止
en_result_t Tim3_Mode23_DisableIrq (en_tim3_irq_type_t enTim3Irq);
//模式0初始化及相关功能操作
//timer配置及初始化
en_result_t Tim3_Mode0_Init(stc_tim3_mode0_config_t* pstcConfig);
//timer 启动/停止
en_result_t Tim3_M0_Run(void);
en_result_t Tim3_M0_Stop(void);
//重载值设置
en_result_t Tim3_M0_ARRSet(uint16_t u16Data);
//16位计数值设置/获取
en_result_t Tim3_M0_Cnt16Set(uint16_t u16Data);
uint16_t Tim3_M0_Cnt16Get(void);
//32位计数值设置/获取
en_result_t Tim3_M0_Cnt32Set(uint32_t u32Data);
uint32_t Tim3_M0_Cnt32Get(void);
//翻转输出使能/禁止设定
en_result_t Tim3_M0_EnTOG_Output(boolean_t bEnOutput);
//模式1初始化及相关功能操作
//timer配置及初始化
en_result_t Tim3_Mode1_Init(stc_tim3_mode1_config_t* pstcConfig);
//PWC 输入配置
en_result_t Tim3_M1_Input_Config(stc_tim3_pwc_input_config_t* pstcConfig);
//PWC测量边沿起始结束选择
en_result_t Tim3_M1_PWC_Edge_Sel(en_tim3_m1cr_Edge_t enEdgeSel);
//timer 启动/停止
en_result_t Tim3_M1_Run(void);
en_result_t Tim3_M1_Stop(void);
//16位计数值设置/获取
en_result_t Tim3_M1_Cnt16Set(uint16_t u16Data);
uint16_t Tim3_M1_Cnt16Get(void);
//脉冲宽度测量结果数值获取
uint16_t Tim3_M1_PWC_CapValueGet(void);
//模式1初始化及相关功能操作
//timer配置及初始化
en_result_t Tim3_Mode23_Init(stc_tim3_mode23_config_t* pstcConfig);
//timer 启动/停止
en_result_t Tim3_M23_Run(void);
en_result_t Tim3_M23_Stop(void);
//PWM输出使能
en_result_t Tim3_M23_EnPWM_Output(boolean_t bEnOutput, boolean_t bEnAutoOutput);
//重载值设置
en_result_t Tim3_M23_ARRSet(uint16_t u16Data, boolean_t bArrBufEn);
//16位计数值设置/获取
en_result_t Tim3_M23_Cnt16Set(uint16_t u16Data);
uint16_t Tim3_M23_Cnt16Get(void);
//比较捕获寄存器CCR0A/CCR0B设置/读取
en_result_t Tim3_M23_CCR_Set(en_tim3_m23_ccrx_t enCCRSel, uint16_t u16Data);
uint16_t Tim3_M23_CCR_Get(en_tim3_m23_ccrx_t enCCRSel);
//PWM互补输出模式下GATE功能选择
en_result_t Tim3_M23_GateFuncSel(stc_tim3_m23_gate_config_t* pstcConfig);
//主从模式配置
en_result_t Tim3_M23_MasterSlave_Set(stc_tim3_m23_master_slave_config_t* pstcConfig);
//CH0A/CH0B比较通道控制
en_result_t Tim3_M23_PortOutput_Config(en_tim3_channel_t enTim3Chx, stc_tim3_m23_compare_config_t* pstcConfig);
//CH0A/CH0B输入控制
en_result_t Tim3_M23_PortInput_Config(en_tim3_channel_t enTim3Chx, stc_tim3_m23_input_config_t* pstcConfig);
//ERT输入控制
en_result_t Tim3_M23_ETRInput_Config(stc_tim3_m23_etr_input_config_t* pstcConfig);
//刹车BK输入控制
en_result_t Tim3_M23_BrakeInput_Config(stc_tim3_m23_bk_input_config_t* pstcConfig);
//触发ADC控制
en_result_t Tim3_M23_TrigADC_Config(stc_tim3_m23_adc_trig_config_t* pstcConfig);
//死区功能
en_result_t Tim3_M23_DT_Config(stc_tim3_m23_dt_config_t* pstcConfig);
//重复周期设置
en_result_t Tim3_M23_SetValidPeriod(uint8_t u8ValidPeriod);
//OCREF清除功能
en_result_t Tim3_M23_OCRefClr(stc_tim3_m23_OCREF_Clr_config_t* pstcConfig);
//使能DMA传输
en_result_t Tim3_M23_EnDMA(stc_tim3_m23_trig_dma_config_t* pstcConfig);
//捕获比较A软件触发
en_result_t Tim3_M23_EnSwTrigCapCmpA(en_tim3_channel_t enTim3Chx);
//捕获比较B软件触发
en_result_t Tim3_M23_EnSwTrigCapCmpB(en_tim3_channel_t enTim3Chx);
//软件更新使能
en_result_t Tim3_M23_EnSwUev(void);
//软件触发使能
en_result_t Tim3_M23_EnSwTrig(void);
//软件刹车使能
en_result_t Tim3_M23_EnSwBk(void);
//@} // Tim3Group
#ifdef __cplusplus
#endif
#endif /* __BT_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,186 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file trim.h
**
** TRIM API声明
**
**
** History:
** - 2018-04-21 Lux V1.0
**
*****************************************************************************/
#ifndef __TRIM_H__
#define __TRIM_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup TrimGroup Clock Trimming (TRIM)
**
******************************************************************************/
//@{
/******************************************************************************
** Global pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief 使 (MON_EN)
*****************************************************************************/
typedef enum en_trim_monitor
{
TrimMonDisable = 0u, ///< 禁止
TrimMonEnable = 1u, ///< 使能
}en_trim_monitor_t;
/**
******************************************************************************
** \brief / (CALCLK_SEL)
*****************************************************************************/
typedef enum en_trim_calclksel
{
TrimCalRCH = 0u, ///< RCH
TrimCalXTH = 1u, ///< XTH
TrimCalRCL = 2u, ///< RCL
TrimCalXTL = 3u, ///< XTL
TrimCalPLL = 4u, ///< PLL
}en_trim_calclksel_t;
/**
******************************************************************************
** \brief (REFCLK_SEL)
*****************************************************************************/
typedef enum en_trim_refclksel
{
TrimRefRCH = 0u, ///< RCH
TrimRefXTH = 1u, ///< XTH
TrimRefRCL = 2u, ///< RCL
TrimRefXTL = 3u, ///< XTL
TrimRefIRC10K = 4u, ///< IRC10K
TrimRefExtClk = 5u, ///< 外部输入时钟
}en_trim_refclksel_t;
/**
******************************************************************************
** \brief
*****************************************************************************/
typedef enum en_trim_inttype
{
TrimStop = 0u, ///< 参考计数器停止标志
TrimCalCntOf = 1u, ///< 校准计数器溢出标志
TrimXTLFault = 2u, ///< XTL 失效标志
TrimXTHFault = 3u, ///< XTH 失效标志
TrimPLLFault = 4u, ///< PLL 失效标志
}en_trim_inttype_t;
/**
******************************************************************************
** \brief TRIM
*****************************************************************************/
typedef struct stc_trim_config
{
en_trim_monitor_t enMON; ///< 监测模式使能
en_trim_calclksel_t enCALCLK; ///< 校准时钟选择
uint32_t u32CalCon; ///< 校准计数器溢出值配置
en_trim_refclksel_t enREFCLK; ///< 参考时钟选择
uint32_t u32RefCon; ///< 参考计数器初值配置
func_ptr_t pfnTrimCb; ///< TRIM 中断服务回调函数[void function(void)]
}stc_trim_config_t;
/******************************************************************************
* Global variable declarations ('extern', definition in C source)
*****************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
*****************************************************************************/
///<<功能配置及操作函数
///<Trim 配置及初始化
en_result_t Trim_Init(stc_trim_config_t* pstcConfig);
///<校准/监测启动/停止
en_result_t Trim_Run(void);
en_result_t Trim_Stop(void);
///<参考计数器计数值获取
uint32_t Trim_RefCntGet(void);
///<校准计数器计数值获取
uint32_t Trim_CalCntGet(void);
///<中断操作相关函数
///中断使能/禁止
en_result_t Trim_EnableIrq(void);
en_result_t Trim_DisableIrq(void);
///<中断标志获取
boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType);
///<中断标志清除
en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType);
//@} // TrimGroup
#ifdef __cplusplus
#endif
#endif /* __TRIM_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,297 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file uart.h
**
** Headerfile for UART functions
**
**
** History:
** - 2017-05-10 Cathy First Version
**
*****************************************************************************/
#ifndef __UART_H__
#define __UART_H__
/*****************************************************************************
* Include files
*****************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup UartGroup Universal Asynchronous Receiver/Transmitter (UART)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
**\brief uart通道选择
******************************************************************************/
typedef enum en_uart_channel
{
UARTCH0 = 0u, ///<串口0
UARTCH1 = 1u, ///<串口1
}en_uart_channel_t;
/**
******************************************************************************
** \brief uart多主机模式地址帧/
******************************************************************************/
typedef enum en_uart_mmdorck
{
UartDataOrAddr = 0u, ///<多主机模式时通过读写SBUF[8]决定帧为数据帧或地址帧
UartEven = 1u, ///<非多主机模式偶校验
UartOdd = 2u, ///<非多主机模式奇校验
}en_uart_mmdorck_t;
/**
******************************************************************************
** \brief uart多主机模式配置
******************************************************************************/
typedef enum en_uart_multimode
{
UartNormal = 0u, ///<正常工作模式
UartMulti = 1u, ///<多主机工作模式
}en_uart_multimode_t;
/**
******************************************************************************
** \brief uart多主机模式及从机地址和地址掩码配置
******************************************************************************/
typedef struct stc_uart_multimode
{
en_uart_multimode_t enMulti_mode; ///<多主机模式配置
uint8_t u8SlaveAddr; ///<从机地址
uint8_t u8SaddEn; ///<从及地址掩码
}stc_uart_multimode_t;
/**
******************************************************************************
** \brief uart
******************************************************************************/
typedef enum en_uart_mode
{
UartMode0 = 0u, ///<模式0
UartMode1 = 1u, ///<模式1
UartMode2 = 2u, ///<模式2
UartMode3 = 3u, ///<模式3
} en_uart_mode_t;
/**
******************************************************************************
** \brief uart stop长度选择
******************************************************************************/
typedef enum en_uart_stop
{
Uart1bit = 0u, ///<1位停止位
Uart15bit = 1u, ///<1.5位停止位
Uart2bit = 2u, ///<2位停止位
} en_uart_stop_t;
/**
******************************************************************************
** \brief uart 使
******************************************************************************/
typedef enum en_uart_func
{
UartTx = 0u, ///<mode0模式代表TX
UartRx = 1u, ///<非mode0模式代表RX and TX ,mode0模式代表RX
UartDmaTx = 3u, ///<DMA发送使能
UartDmaRx = 4u, ///<DMA接收使能
UartCtsRts = 5u, ///<硬件流使能
}en_uart_func_t;
/**
******************************************************************************
** \brief uart中断使能控制
******************************************************************************/
typedef enum en_uart_irq_sel
{
UartTxIrq = 0u, ///<发送中断使能
UartRxIrq = 1u, ///<接收中断使能
UartFEIrq = 3u, ///<帧错误中断使能
UartCtsIrq = 4u, ///<CTS信号翻转中断使能
UartPEIrq = 5u, ///<奇偶校验中断使能
UartTxEIrq = 6u, ///<TX空中断使能
}en_uart_irq_sel_t;
/**
******************************************************************************
** \brief uart发送接收中断处理函数接口
******************************************************************************/
typedef struct stc_uart_irq_cb
{
func_ptr_t pfnTxIrqCb; ///<发送中断服务函数
func_ptr_t pfnRxFEIrqCb; ///<接收帧错误中断服务函数
func_ptr_t pfnRxIrqCb; ///<接收中断服务函数
func_ptr_t pfnCtsIrqCb; ///<CTS信号翻转中断服务函数
func_ptr_t pfnPEIrqCb; ///<奇偶校验错误中断服务函数
}stc_uart_irq_cb_t;
/**
******************************************************************************
** \brief uart
******************************************************************************/
typedef enum en_uart_status
{
UartCts = 0u, ///<CTS信号标记
UartRC = 1u, ///<接收数据完成标记
UartTC = 2u, ///<发送数据完成标记
UartPE = 3u, ///<奇偶校验错误标记
UartFE = 4u, ///<帧错误标记
UartCtsIf = 5u, ///<CTS中断标记
UartTxe = 6u, ///<TXbuff空标记
}en_uart_status_t;
/**
******************************************************************************
** \brief uart
******************************************************************************/
typedef struct stc_uart_instance_data
{
uint32_t u32Idx; ///< 通道号
M0P_UART_TypeDef *pstcInstance; ///< 通道寄存器地址
stc_uart_irq_cb_t stcUartInternIrqCb; ///< 通道中断服务函数
} stc_uart_instance_data_t;
/**
******************************************************************************
** \brief uart
******************************************************************************/
typedef enum en_uart_clkdiv
{
Uart16Or32Div = 0u,///<模式0无效模式1/3为16分频模式2为32分频
Uart8Or16Div = 1u,///<模式0无效模式1/3为8分频模式2为16分频
}en_uart_clkdiv_t;
/**
******************************************************************************
** \brief uart
******************************************************************************/
typedef struct stc_uart_baud
{
uint32_t u32Pclk; ///<pclk
en_uart_mode_t enRunMode; ///< 四种模式配置
uint32_t u32Baud; ///< 波特率
} stc_uart_baud_t;
/**
******************************************************************************
** \uart
******************************************************************************/
typedef struct stc_uart_config
{
en_uart_mode_t enRunMode; ///< 四种模式配置
en_uart_stop_t enStopBit; ///<停止位长度
stc_uart_multimode_t* pstcMultiMode; ///<多主机模式配置
stc_uart_irq_cb_t* pstcIrqCb; ///<中断服务函数
boolean_t bTouchNvic; ///<NVIC中断使能
} stc_uart_config_t;
//中断相关设置函数
en_result_t Uart_EnableIrq(uint8_t u8Idx,
en_uart_irq_sel_t enIrqSel);
en_result_t Uart_DisableIrq(uint8_t u8Idx,
en_uart_irq_sel_t enIrqSel);
//void Uart_IrqHandler(uint8_t u8Idx);
// 总初始化处理
en_result_t Uart_Init(uint8_t u8Idx,
stc_uart_config_t* pstcConfig);
en_result_t Uart_DeInit(uint8_t u8Idx, boolean_t bTouchNvic);
//UART模块工作模式设置函数
en_result_t Uart_SetMode(uint8_t u8Idx,en_uart_mode_t enMode);
//UART模块多主机模式设置函数
en_result_t Uart_SetMultiMode(uint8_t u8Idx,stc_uart_multimode_t* pstcMultiConfig);
//UART通道多主机模式发送数据/地址帧或者奇偶校验配置TB8
en_result_t Uart_SetMMDOrCk(uint8_t u8Idx,en_uart_mmdorck_t enTb8);
//从机地址配置
en_result_t Uart_SetSaddr(uint8_t u8Idx,uint8_t u8Addr);
//从机地址掩码配置
en_result_t Uart_SetSaddrEn(uint8_t u8Idx,uint8_t u8Addren);
//停止位长度设置
en_result_t Uart_SetStopBit(uint8_t u8Idx,uint8_t u8Len);
//RB8数据获取
boolean_t Uart_GetRb8(uint8_t u8Idx);
//采样分频设置
en_result_t Uart_SetClkDiv(uint8_t u8Idx,en_uart_clkdiv_t enClkDiv);
//波特率设置值计算
uint16_t Uart_CalScnt(uint8_t u8Idx,stc_uart_baud_t *pstcBaud);
//波特率设置
en_result_t Uart_SetBaud(uint8_t u8Idx,uint16_t u16Scnt);
//获取波特率
uint32_t Uart_GetBaud(uint8_t u8Idx,uint8_t u8Mode,uint32_t u32Pclk);
// 功能使能和禁止
en_result_t Uart_EnableFunc(uint8_t u8Idx, en_uart_func_t enFunc);
en_result_t Uart_DisableFunc(uint8_t u8Idx, en_uart_func_t enFunc);
//状态位的获取和清除
uint8_t Uart_GetIsr(uint8_t u8Idx);
boolean_t Uart_GetStatus(uint8_t u8Idx,en_uart_status_t enStatus);
en_result_t Uart_ClrIsr(uint8_t u8Idx);
en_result_t Uart_ClrStatus(uint8_t u8Idx,en_uart_status_t enStatus);
//数据查询方式的收发操作
//en_result_t Uart_MultiSendFirstData(uint8_t U8Addr);
en_result_t Uart_SendData(uint8_t u8Idx, uint8_t u8Data);
int Uart_ReceiveData(uint8_t u8Idx);
//@} // UartGroup
#ifdef __cplusplus
#endif
#endif /* __UART_H__ */
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,311 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file vc.h
**
** Headerfile for Voltage Comparator functions
** @link VC Group Some description @endlink
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
#ifndef __VC_H__
#define __VC_H__
/******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
/* C binding of definitions if building with C++ compiler */
#ifdef __cplusplus
extern "C"
{
#endif
/**
******************************************************************************
** \defgroup VcGroup Voltage Comparator (VC)
**
******************************************************************************/
//@{
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief VC通道
*****************************************************************************/
typedef enum en_vc_channel
{
VcChannel0 = 0u, ///< 通道0
VcChannel1 = 1u, ///< 通道1
}en_vc_channel_t;
/**
******************************************************************************
** \brief VC迟滞
*****************************************************************************/
typedef enum en_vc_cmp_delay
{
VcDelayoff = 0u, ///< 迟滞关闭
VcDelay10mv = 1u, ///< 迟滞10mv
VcDelay20mv = 2u, ///< 迟滞20mv
VcDelay30mv = 3u, ///< 迟滞30mv
}en_vc_cmp_delay_t;
/**
******************************************************************************
** \brief VC偏置电流
*****************************************************************************/
typedef enum en_vc_bias_current
{
VcBias300na = 0u, ///< 偏置电流300na
VcBias1200na = 1u, ///< 偏置电流1.2ua
VcBias10ua = 2u, ///< 偏置电流10ua
VcBias20ua = 3u, ///< 偏置电流20ua
}en_vc_bias_current_t;
/**
******************************************************************************
** \brief VC输出滤波时间
*****************************************************************************/
typedef enum en_vc_resp_filter
{
VcFilter7us = 0u, ///< 输出滤波时间7us
VcFilter14us = 1u, ///< 输出滤波时间14us
VcFilter28us = 2u, ///< 输出滤波时间28us
VcFilter112us = 3u, ///< 输出滤波时间112us
VcFilter450us = 4u, ///< 输出滤波时间450us
VcFilter1800us = 5u, ///< 输出滤波时间1.8ms
VcFilter7200us = 6u, ///< 输出滤波时间7.2ms
VcFilter28800us = 7u, ///< 输出滤波时间28.8ms
}en_vc_resp_filter_t;
/**
******************************************************************************
** \brief VC P端输入
*****************************************************************************/
typedef enum en_vc_input_p_src
{
//VC0 //VC1
VcInPCh0 = 0u, ///< 输入通道0 PC0 输入通道0 PA0
VcInPCh1 = 1u, ///< 输入通道1 PC1 输入通道0 PA1
VcInPCh2 = 2u, ///< 输入通道2 PC2 输入通道0 PA2
VcInPCh3 = 3u, ///< 输入通道3 PC3 输入通道0 PA3
VcInPCh4 = 4u, ///< 输入通道4 PA0 输入通道0 PA4
VcInPCh5 = 5u, ///< 输入通道5 PA1 输入通道0 PA5
VcInPCh6 = 6u, ///< 输入通道6 PA2 输入通道0 PB1
VcInPCh7 = 7u, ///< 输入通道7 PA3 输入通道0 PB2
VcInPCh8 = 8u, ///< 输入通道7 PA4 输入通道0 PB10
VcInPCh9 = 9u, ///< 输入通道7 PA5 输入通道0 PB12
VcInPCh10 = 10u, ///< 输入通道7 PA6 输入通道0 PB13
VcInPCh11 = 11u, ///< 输入通道7 PA7 输入通道0 PB14
VcInPCh12 = 12u, ///< 输入通道7 PB4 输入通道0 PB4
VcInPCh13 = 13u, ///< 输入通道7 PB5 输入通道0 PB5
VcInPCh14 = 14u, ///< 输入通道7 PB6 输入通道0 PB6
VcInPCh15 = 15u, ///< 输入通道7 PB7 输入通道0 PB7
}en_vc_input_p_src_t;
/**
******************************************************************************
** \brief VC N端输入
*****************************************************************************/
typedef enum en_vc_input_n_src
{
//VC0 //VC1
VcInNCh0 = 0u, ///< 输入通道0 PA0 输入通道0 PC0
VcInNCh1 = 1u, ///< 输入通道1 PA1 输入通道0 PC1
VcInNCh2 = 2u, ///< 输入通道2 PA2 输入通道0 PC2
VcInNCh3 = 3u, ///< 输入通道3 PA3 输入通道0 PC3
VcInNCh4 = 4u, ///< 输入通道4 PA4 输入通道0 PA0
VcInNCh5 = 5u, ///< 输入通道5 PA5 输入通道0 PA1
VcInNCh6 = 6u, ///< 输入通道6 PA6 输入通道0 PB0
VcInNCh7 = 7u, ///< 输入通道7 PA7 输入通道0 PB1
VcInNCh8 = 8u, ///< 输入通道8 PC4 输入通道0 PB2
VcInNCh9 = 9u, ///< 输入通道9 PC5 输入通道0 PB3
VcInNCh10 = 10u, ///< 输入通道10 PB0 输入通道0 PB4
ResDivOut = 11u, ///< Vcc分压 Vcc分压
AiTs = 12u, ///< 温度传感器 温度传感器
AiBg1p2 = 13u, ///< BGR 1.2V BGR 1.2V
AiAdcVref = 14u, ///< ADCVREF ADCVREF
AiLdo = 15u, ///< LDO LDO
}en_vc_input_n_src_t;
/**
******************************************************************************
** \brief VC中断触发方式
*****************************************************************************/
typedef enum en_vc_irq_sel
{
VcIrqNone = 0u, ///< 无中断
VcIrqRise = 1u, ///< 上升沿触发
VcIrqFall = 2u, ///< 下降沿触发
VcIrqHigh = 3u, ///< 高电平触发
}en_vc_irq_sel_t;
/**
******************************************************************************
** \brief VC状态
*****************************************************************************/
typedef enum en_vc_stat
{
VcCmpResult = 0u, ///< VC比较输出结果
VcIntrResult = 1u, ///< VC中断状态
}en_vc_stat_t;
/**
******************************************************************************
** \brief VC输出配置
*****************************************************************************/
typedef enum en_vc_output_config
{
VcOutInvTimer = 0u, ///< 结果输出负向到各Timer0,1,2,3
VcOutTIM0RCLR = 1u, ///< 结果使能输出到TIM0 REFCLR
VcOutTIM1RCLR = 2u, ///< 结果使能输出到TIM1 REFCLR
VcOutTIM2RCLR = 3u, ///< 结果使能输出到TIM2 REFCLR
VcOutTIM3RCLR = 4u, ///< 结果使能输出到TIM3 REFCLR
VcOutTIMBK = 5u, ///< 结果使能输出到Timer0,1,2,3刹车
VcOutInvTIM4 = 9u, ///< 结果输出负向到Timer4
VcOutTIM4 = 10u, ///< 结果使能输出到Timer4
VcOutInvTIM5 = 11u, ///< 结果输出负向到Timer5
VcOutTIM5 = 12u, ///< 结果使能输出到Timer5
VcOutInvTIM6 = 13u, ///< 结果输出负向到Timer6
VcOutTIM6 = 14u, ///< 结果使能输出到Timer6
VcOutBrake = 15u, ///< 结果使能输出到Advanced Timer刹车
VcOutDisable = 16u, ///< 结果输出除能
}en_vc_output_config_t;
/**
******************************************************************************
** \brief VC DIV参考电压Vref选择
*****************************************************************************/
typedef enum en_vc_div_vref
{
VcDivVrefAvcc = 0u, ///< AVCC
VcDivVrefAdc = 1u, ///< ADC_CR0 SREF选择参考电压
}en_vc_div_vref_t;
/**
******************************************************************************
** \brief VC模块配置
*****************************************************************************/
typedef struct stc_vc_dac_config
{
boolean_t bDivEn; ///< 使能/除能 6-bit VCC divider
uint8_t u8DivVal; ///< 6-bit VCC divider设置值
en_vc_div_vref_t enDivVref; ///< 6-bit VCC divider输入参考电压选择
}stc_vc_dac_config_t;
/**
******************************************************************************
** \brief VC通道配置
*****************************************************************************/
typedef struct stc_vc_channel_config
{
en_vc_channel_t enVcChannel; ///< VC通道选择
en_vc_cmp_delay_t enVcCmpDly; ///< VC迟滞
en_vc_bias_current_t enVcBiasCurrent; ///< VC偏转电流
en_vc_resp_filter_t enVcFilterTime; ///< 输出滤波时间
en_vc_input_p_src_t enVcInPin_P; ///< P端输入
en_vc_input_n_src_t enVcInPin_N; ///< N端输入
en_vc_output_config_t enVcOutConfig; ///< 输出配置
en_vc_irq_sel_t enVcIrqSel; ///< 中断触发方式
func_ptr_t pfnAnalogCmpCb; ///< 中断回调函数
}stc_vc_channel_config_t;
/******************************************************************************
* Global definitions
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Global variable definitions ('extern')
******************************************************************************/
/******************************************************************************
* Global function prototypes (definition in C source)
******************************************************************************/
//VC init/deinit
en_result_t Vc_ChannelInit(en_vc_channel_t enChannel,
stc_vc_channel_config_t *pstcChannelConfig);
en_result_t Vc_ChannelDeInit(en_vc_channel_t enChannel);
en_result_t Vc_DACInit(stc_vc_dac_config_t *pstcDacConfig);
//VC function enable/disable
en_result_t Vc_EnableChannel(en_vc_channel_t enChannel);
en_result_t Vc_DisableChannel(en_vc_channel_t enChannel);
//VC filter enable/disable
en_result_t Vc_EnableFilter(en_vc_channel_t enChannel);
en_result_t Vc_DisableFilter(en_vc_channel_t enChannel);
//get stat
boolean_t Vc_GetStat(en_vc_channel_t enChannel, en_vc_stat_t enStat);
//clear stat
void Vc_ClearIrq(en_vc_channel_t enChannel);
//irq enable/disable
en_result_t Vc_EnableIrq(en_vc_channel_t enChannel);
en_result_t Vc_DisableIrq(en_vc_channel_t enChannel);
en_result_t Vc_ConfigIrq(en_vc_channel_t enChannel, en_vc_irq_sel_t enSel);
//@} // VcGroup
#ifdef __cplusplus
}
#endif
#endif /* __VC_H__ */
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,127 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file wdt.h
**
** Headerfile for WDT functions
**
**
** History:
** - 2017-05-10 Cathy First Version
**
*****************************************************************************/
#ifndef __WDT_H__
#define __WDT_H__
#include "ddl.h"
#include "interrupts_hc32l136.h"
/**
******************************************************************************
** \defgroup WdtGroup Watchdog Timer (WDT)
**
******************************************************************************/
//@{
/******************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************
* Global type definitions
******************************************************************************/
/**
******************************************************************************
** \brief wdt溢出后复位或中断配置
*****************************************************************************/
typedef enum en_wdt_reset
{
WRESET_EN = 0,///<复位使能
WINT_EN = 1,///<中断使能
}en_wdt_reset_t;
/**
******************************************************************************
** \brief wdt当前运行状态
*****************************************************************************/
typedef enum en_wdt_status
{
Stop_Mode = 0,///<停止模块
Run_Mode = 1,///<正常运行模式
}en_wdt_status_t;
/**
******************************************************************************
** \brief wdt总体配置
*****************************************************************************/
typedef struct stc_wdt_config
{
uint8_t u8LoadValue; ///<溢出时间
en_wdt_reset_t enResetEnable; ///<中断或复位使能
func_ptr_t pfnWdtIrqCb; ///<中断服务接口函数
} stc_wdt_config_t;
//wdt初始化
en_result_t Wdt_Init(stc_wdt_config_t* pstcConfig);
void Wdt_DeInit(void);
//wdt开始和停止
en_result_t Wdt_Start(void);
//wdt溢出时间设置及当前计数时间、状态读取
void Wdt_WriteWdtLoad(uint8_t u8LoadValue);
uint8_t Wdt_ReadWdtValue(void);
uint8_t Wdt_ReadwdtStatus(void);
//喂狗处理
void Wdt_Feed(void);
//@} // WdtGroup
#ifdef __cplusplus
#endif
#endif /* __WDT_H__ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,176 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file crc.c
**
** Common API of crc.
** @link crcGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "aes.h"
/**
*******************************************************************************
** \addtogroup CrcGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
* \brief
* ADC初始化
*
* \param [in] pu32Data
* \param [in] pu32Key KEY
* \param [out] pu32Cipher
*
* \retval en_result_t Ok:
* \retval en_result_t ErrorInvalidParameter:
*/
en_result_t AES_Encrypt(uint32_t* pu32Data, uint32_t *pu32Key, uint32_t *pu32Cipher)
{
if ((NULL == pu32Data)||(NULL == pu32Key)||(NULL == pu32Cipher))
{
return ErrorInvalidParameter;
}
//Key config
M0P_AES->KEY0 = pu32Key[0];
M0P_AES->KEY1 = pu32Key[1];
M0P_AES->KEY2 = pu32Key[2];
M0P_AES->KEY3 = pu32Key[3];
//Data config
M0P_AES->DATA0 = pu32Data[0];
M0P_AES->DATA1 = pu32Data[1];
M0P_AES->DATA2 = pu32Data[2];
M0P_AES->DATA3 = pu32Data[3];
M0P_AES->CR_f.MODE = 0;//Encry
M0P_AES->CR_f.START = 1;
while(M0P_AES->CR_f.START == 1)
{
;
}
pu32Cipher[0] = M0P_AES->DATA0;
pu32Cipher[1] = M0P_AES->DATA1;
pu32Cipher[2] = M0P_AES->DATA2;
pu32Cipher[3] = M0P_AES->DATA3;
return Ok;
}
/**
* \brief
* ADC初始化
*
* \param [in] pu32Cipher
* \param [in] pu32Key KEY
* \param [out] pu32Data
*
* \retval en_result_t Ok:
* \retval en_result_t ErrorInvalidParameter:
*/
en_result_t AES_Decrypt(uint32_t *pu32Cipher,uint32_t *pu32Key, uint32_t* pu32Plaintext)
{
if ((NULL == pu32Plaintext)||(NULL == pu32Key)||(NULL == pu32Cipher))
{
return ErrorInvalidParameter;
}
//Key config
M0P_AES->KEY0 = pu32Key[0];
M0P_AES->KEY1 = pu32Key[1];
M0P_AES->KEY2 = pu32Key[2];
M0P_AES->KEY3 = pu32Key[3];
//Data config
M0P_AES->DATA0 = pu32Cipher[0];
M0P_AES->DATA1 = pu32Cipher[1];
M0P_AES->DATA2 = pu32Cipher[2];
M0P_AES->DATA3 = pu32Cipher[3];
M0P_AES->CR_f.MODE = 1;//UnEncry
M0P_AES->CR_f.START = 1;
while(M0P_AES->CR_f.START == 1)
{
;
}
pu32Plaintext[0] = M0P_AES->DATA0;
pu32Plaintext[1] = M0P_AES->DATA1;
pu32Plaintext[2] = M0P_AES->DATA2;
pu32Plaintext[3] = M0P_AES->DATA3;
return Ok;
}
//@} // CrcGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,155 @@
/******************************************************************************
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file bgr.c
**
** Common API of bgr.
** @link flashGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "bgr.h"
/**
*******************************************************************************
** \addtogroup FlashGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief BGR 使
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Bgr_BgrEnable(void)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralAdcBgr, TRUE);
M0P_BGR->CR_f.BGR_EN = TRUE;
delay10us(2);
return Ok;
}
/**
*****************************************************************************
** \brief BGR
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Bgr_BgrDisable(void)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralAdcBgr, TRUE);
M0P_BGR->CR_f.BGR_EN = FALSE;
return Ok;
}
/**
*****************************************************************************
** \brief BGR 使
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Bgr_TempSensorEnable(void)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralAdcBgr, TRUE);
M0P_BGR->CR_f.TS_EN = TRUE;
delay10us(2);
return Ok;
}
/**
*****************************************************************************
** \brief BGR
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Bgr_TempSensorDisable(void)
{
Sysctrl_SetPeripheralGate(SysctrlPeripheralAdcBgr, TRUE);
M0P_BGR->CR_f.TS_EN = FALSE;
return Ok;
}
//@} // BgrGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,438 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file crc.c
**
** Common API of crc.
** @link crcGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "crc.h"
/**
*******************************************************************************
** \addtogroup CrcGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16编码.
**
** \param [in] pu8Data
** \param [in] u32Len
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint16_t CRC16_Get8(uint8_t* pu8Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 0;
M0P_CRC->RESULT = 0xFFFF;
for(u32Index = 0;u32Index<u32Len;u32Index++)
{
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16编码.
**
** \param [in] pu16Data
** \param [in] u32Len
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint16_t CRC16_Get16(uint16_t* pu16Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16编码.
**
** \param [in] pu32Data
** \param [in] u32Len
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint16_t CRC16_Get32(uint32_t* pu32Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
M0P_CRC->DATA_f.DATA = pu32Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16值进行校验.
**
** \param [in] pu8Data
** \param [in] u32Len
** \param [in] u16CRC CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC16_Check8(uint8_t* pu8Data, uint32_t u32Len, uint16_t u16CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
}
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((((uint32_t)u16CRC)>>0)&0xFF);
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)(((uint32_t)u16CRC>>8)&0xFF);
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16值进行校验.
**
** \param [in] pu16Data
** \param [in] u32Len
** \param [in] u16CRC CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC16_Check16(uint16_t* pu16Data, uint32_t u32Len, uint16_t u16CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFF;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
}
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = u16CRC;
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16值进行校验.
**
** \param [in] pu32Data
** \param [in] u32Len
** \param [in] u16CRC CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC16_Check32(uint32_t* pu32Data, uint32_t u32Len, uint16_t u16CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 0;
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = pu32Data[u32Index];
}
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = ((uint16_t)u16CRC);
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16编码.
**
** \param [in] pu8Data
** \param [in] u32Len
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint32_t CRC32_Get8(uint8_t* pu8Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 1;
M0P_CRC->RESULT = 0xFFFFFFFFu;
for(u32Index = 0;u32Index<u32Len;u32Index++)
{
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16编码.
**
** \param [in] pu16Data
** \param [in] u32Len
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint32_t CRC32_Get16(uint16_t* pu16Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 1;
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16编码.
**
** \param [in] pu32Data
** \param [in] u32Len
**
** \retval CRC16 CRC16编码值.
*****************************************************************************/
uint32_t CRC32_Get32(uint32_t* pu32Data, uint32_t u32Len)
{
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 1;
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
M0P_CRC->DATA_f.DATA = pu32Data[u32Index];
}
return (M0P_CRC->RESULT_f.RESULT);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16值进行校验.
**
** \param [in] pu8Data
** \param [in] u32Len
** \param [in] u16CRC CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC32_Check8(uint8_t* pu8Data, uint32_t u32Len, uint32_t u32CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 1;
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = pu8Data[u32Index];
}
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>0)&0xFF);
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>8)&0xFF);
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>16)&0xFF);
*((volatile uint8_t*)(&(M0P_CRC->DATA))) = (uint8_t)((u32CRC>>24)&0xFF);
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16值进行校验.
**
** \param [in] pu16Data
** \param [in] u32Len
** \param [in] u16CRC CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC32_Check16(uint16_t* pu16Data, uint32_t u32Len, uint32_t u32CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 1;
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = pu16Data[u32Index];
}
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = (uint16_t)((u32CRC>>0)&0xFFFF);
*((volatile uint16_t*)(&(M0P_CRC->DATA))) = (uint16_t)((u32CRC>>16)&0xFFFF);
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
return (enResult);
}
/**
*****************************************************************************
** \brief CRC16 ()
**
** CRC16值进行校验.
**
** \param [in] pu32Data
** \param [in] u32Len
** \param [in] u16CRC CRC16值
**
** \retval Ok CRC校验正确
** \retval Error CRC校验错误
*****************************************************************************/
en_result_t CRC32_Check32(uint32_t* pu32Data, uint32_t u32Len, uint32_t u32CRC)
{
en_result_t enResult = Ok;
uint32_t u32Index = 0;
M0P_CRC->CR_f.CR = 1;
M0P_CRC->RESULT_f.RESULT = 0xFFFFFFFFu;
for (u32Index=0; u32Index<u32Len; u32Index++)
{
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = pu32Data[u32Index];
}
*((volatile uint32_t*)(&(M0P_CRC->DATA))) = u32CRC;
enResult = M0P_CRC->CR_f.FLAG ? Ok : Error;
return (enResult);
}
//@} // CrcGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,345 @@
/*******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file ddl.c
**
** Common API of DDL.
** @link ddlGroup Some description @endlink
**
** - 2018-04-15
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "ddl.h"
/**
******************************************************************************
** \addtogroup DDL Common Functions
******************************************************************************/
//@{
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
/******************************************************************************/
/* Global variable definitions (declared in header file with 'extern') */
/******************************************************************************/
/******************************************************************************/
/* Local type definitions ('typedef') */
/******************************************************************************/
/******************************************************************************/
/* Local variable definitions ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Function implementation - global ('extern') and local ('static') */
/******************************************************************************/
#ifndef __DEBUG
#define __DEBUG
//#define __CC_ARM
#endif
uint32_t Log2(uint32_t u32Val)
{
uint32_t u32V1 = 0;
if(0u == u32Val)
{
return 0;
}
while(u32Val > 1u)
{
u32V1++;
u32Val /=2;
}
return u32V1;
}
/**
*******************************************************************************
** \brief Memory clear function for DDL_ZERO_STRUCT()
******************************************************************************/
void ddl_memclr(void *pu8Address, uint32_t u32Count)
{
uint8_t *pu8Addr = (uint8_t *)pu8Address;
if(NULL == pu8Addr)
{
return;
}
while (u32Count--)
{
*pu8Addr++ = 0;
}
}
/**
*****************************************************************************
** \brief Hook function, which is called in polling loops
*****************************************************************************/
void DDL_WAIT_LOOP_HOOK(void)
{
// Place code for triggering Watchdog counters here, if needed
}
/**
*****************************************************************************
** \brief debug printf function.
*****************************************************************************/
void Debug_UartInit(void)
{
#ifdef __DEBUG
//uint32_t u32Pclk1 = 0;
//volatile uint32_t u32ReloadVal = 0;
//
//// UART0_TXD/P35, 19200bps
//M0P_GPIO->P3ADS_f.P35 = 0;
//M0P_GPIO->P35_SEL_f.SEL = 3;
//M0P_GPIO->P3DIR_f.P35 = 0;
//
//u32Pclk1 = Sysctrl_GetPClkFreq();
//u32ReloadVal = 65536 - u32Pclk1 * 2 / 19200 / 32;
//
//M0P_BT0->CR_f.CT = 0;
//M0P_BT0->CR_f.MD = 1;
//M0P_BT0->CR_f.TOG_EN = 1;
//M0P_BT0->ARR = u32ReloadVal;
//M0P_BT0->CNT = u32ReloadVal;
//M0P_BT0->CR_f.TR = 1;
//
//M0P_UART0->SCON_f.DBAUD = 1;
//M0P_UART0->SCON_f.SM01 = 1;
#endif
}
void Debug_Output(uint8_t u8Data)
{
//M0P_UART0->SCON_f.REN = 0;
//M0P_UART0->SBUF = u8Data;
//
//while (TRUE != M0P_UART0->ISR_f.TI)
//{
// ;
//}
//M0P_UART0->ICR_f.TICLR = 0;
}
//#ifdef __DEBUG
///**
// ******************************************************************************
// ** \brief Re-target putchar function
// ******************************************************************************/
//int fputc(int ch, FILE *f)
//{
// if (((uint8_t)ch) == '\n')
// {
// Debug_Output('\r');
// }
// Debug_Output(ch);
// return ch;
//}
//#endif
extern void Debug_UartInit(void);
extern void Debug_Output(uint8_t u8Data);
#if defined (__CC_ARM) //KEIL
#pragma import(__use_no_semihosting)
void _sys_exit(int x)
{
x = x;
}
struct __FILE
{
int handle;
/* Whatever you require here. If the only file you are using is */
/* standard output using printf() for debugging, no file handling */
/* is required. */
};
/* FILE is typedef?d in stdio.h. */
FILE __stdout;
#endif
#ifdef __DEBUG
/**
******************************************************************************
** \brief Re-target putchar function
******************************************************************************/
int fputc(int ch, FILE *f)
{
if (((uint8_t)ch) == '\n')
{
Debug_Output('\r');
}
Debug_Output(ch);
return ch;
}
#endif
void _ttywrch(int c)
{
}
int __backspace(void)
{
return 0;
}
/**
* \brief delay1ms
* delay approximately 1ms.
* \param [in] u32Cnt
* \retval void
*/
void delay1ms(uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/1000;
while(SysTick->VAL > u32end)
{
;
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
/**
* \brief delay100us
* delay approximately 100us.
* \param [in] u32Cnt
* \retval void
*/
void delay100us(uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/10000;
while(SysTick->VAL > u32end)
{
;
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
/**
* \brief delay10us
* delay approximately 10us.
* \param [in] u32Cnt
* \retval void
*/
void delay10us(uint32_t u32Cnt)
{
uint32_t u32end;
SysTick->LOAD = 0xFFFFFF;
SysTick->VAL = 0;
SysTick->CTRL = SysTick_CTRL_ENABLE_Msk | SysTick_CTRL_CLKSOURCE_Msk;
while(u32Cnt-- > 0)
{
SysTick->VAL = 0;
u32end = 0x1000000 - SystemCoreClock/100000;
while(SysTick->VAL > u32end)
{
;
}
}
SysTick->CTRL = (SysTick->CTRL & (~SysTick_CTRL_ENABLE_Msk));
}
//@} // DDL Functions
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,119 @@
/******************************************************************************
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file debug.c
**
** Common API of debug.
** @link flashGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "debug.h"
/**
*******************************************************************************
** \addtogroup FlashGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief 使
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Debug_ActiveEnable(en_debug_module_active_t enModule)
{
M0P_DEBUG_ACTIVE->DEBUG_ACTIVE &= ~enModule;
return Ok;
}
/**
*****************************************************************************
** \brief
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Debug_ActiveDisable(en_debug_module_active_t enModule)
{
M0P_DEBUG_ACTIVE->DEBUG_ACTIVE |= enModule;
return Ok;
}
//@} // BgrGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,688 @@
/******************************************************************************
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file flash.c
**
** Common API of flash.
** @link flashGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "flash.h"
/**
*******************************************************************************
** \addtogroup FlashGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define FLASH_END_ADDR (0x0000FFFFu)
#define FLASH_BYPASS() M0P_FLASH->BYPASS_f.BYSEQ = 0x5A5A;\
M0P_FLASH->BYPASS_f.BYSEQ = 0xA5A5;
#define FLASH_IE_TRUE (0x03)
#define FLASH_IE_FALSE (0x00)
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/**
******************************************************************************
** \brief FLASH OP
**
** Flash
******************************************************************************/
typedef enum en_flash_op
{
Read = 0u, ///<读配置值
Program = 1u, ///<编程配置值
SectorErase = 2u, ///<扇区擦除配置值
ChipErase = 3u, ///<全片擦除配置值
} en_flash_op_t;
/**
******************************************************************************
** \brief FLASH LOCK
**
** Flash
******************************************************************************/
typedef enum en_flash_lock
{
LockAll = 0x00000000u, ///<全片加锁
UnlockAll = (int)0xFFFFFFFFu, ///<全片解锁
} en_flash_lock_t;
/**
******************************************************************************
** \brief FLASH
**
** FLASH编程时间参数配置数据类型重定义 (4MHz)
******************************************************************************/
typedef enum en_flash_prgtimer
{
Tnvs = 0x20u,
Tpgs = 0x17u,
Tprog = 0x1Bu,
Tserase = 0x4650u,
Tmerase = 0x222E0u,
Tprcv = 0x18u,
Tsrcv = 0xF0u,
Tmrcv = 0x3E8u,
} en_flash_prgtimer_t;
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
static func_ptr_t pfnFlashCallback = NULL;
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Flash中断服务函数
**
**
** \param [in] u8Param == 0
**
*****************************************************************************/
void EfRam_IRQHandler(uint8_t u8Param)
{
if(NULL != pfnFlashCallback)
{
pfnFlashCallback();
}
}
/**
*****************************************************************************
** \brief Flash中断标志获取
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Flash_GetIntFlag(en_flash_int_type_t enFlashIntType)
{
boolean_t bRetVal = FALSE;
switch (enFlashIntType)
{
case FlashPCInt:
bRetVal = M0P_FLASH->IFR_f.IF0 ? TRUE : FALSE;
break;
case FlashSlockInt:
bRetVal = M0P_FLASH->IFR_f.IF1 ? TRUE : FALSE;
break;
default:
bRetVal = FALSE;
break;
}
return bRetVal;
}
/**
*****************************************************************************
** \brief Flash中断标志清除
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Flash_ClearIntFlag(en_flash_int_type_t enFlashIntType)
{
en_result_t enResult = Error;
switch (enFlashIntType)
{
case FlashPCInt:
FLASH_BYPASS();
M0P_FLASH->ICLR_f.ICLR0 = FALSE;
enResult = Ok;
break;
case FlashSlockInt:
FLASH_BYPASS();
M0P_FLASH->ICLR_f.ICLR1 = FALSE;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Flash中断使能
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Flash_EnableIrq (en_flash_int_type_t enFlashIntType)
{
en_result_t enResult = Error;
switch (enFlashIntType)
{
case FlashPCInt:
FLASH_BYPASS();
M0P_FLASH->CR_f.IE |= 0x01;
enResult = Ok;
break;
case FlashSlockInt:
FLASH_BYPASS();
M0P_FLASH->CR_f.IE |= 0x02;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Flash中断禁止
**
**
** \param [in] enFlashIntType Flash中断类型
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Flash_DisableIrq(en_flash_int_type_t enFlashIntType)
{
en_result_t enResult = Error;
switch (enFlashIntType)
{
case FlashSlockInt:
FLASH_BYPASS();
M0P_FLASH->CR_f.IE &= ~0x02u;
enResult = Ok;
break;
case FlashPCInt:
FLASH_BYPASS();
M0P_FLASH->CR_f.IE &= ~0x01u;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief FLASH
**
** FLASH编程时间相关寄存器.
**
** \param [in] pfnFlashCb Flash中断服务回调函数[void function(void)]
** \param [in] u8FreqCfg FLASH编程时钟频率配置(HCLK的频率选择配置值)
** 1 - (0,4]MHz;
** 2 - (4,8]MHz;
** 4 - (8,16]MHz;
** 6 - (16,24]MHz;
** 8 - (24,32]MHz1FLASH等待周期;
** 12 - (32,48]MHz1FLASH等待周期;
** other -
** \param [in] bDpstbEn TRUE - DeepSleep模式FLASH进入低功耗模式;
** FALSE - DeepSleep模式FLASH不进入低功耗模式;
**
** \retval Ok .
** \retval ErrorInvalidParameter .
**
*****************************************************************************/
en_result_t Flash_Init(func_ptr_t pfnFlashCb, uint8_t u8FreqCfg, boolean_t bDpstbEn)
{
en_result_t enResult = Ok;
if ((1 != u8FreqCfg) &&
(2 != u8FreqCfg) &&
(4 != u8FreqCfg) &&
(6 != u8FreqCfg) &&
(8 != u8FreqCfg) &&
(12 != u8FreqCfg))
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//当系统进入DeepSleep模式时FLASH模式配置
FLASH_BYPASS();
M0P_FLASH->CR_f.DPSTB_EN = bDpstbEn;
//flash时间参数寄存器配置
FLASH_BYPASS();
M0P_FLASH->TNVS_f.TNVS = Tnvs * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TPGS_f.TPGS = Tpgs * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TPROG_f.TPROG = Tprog * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TSERASE_f.TSERASE = Tserase * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TMERASE_f.TMERASE = Tmerase * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TPRCV_f.TPRCV = Tprcv * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TSRCV_f.TSRCV = Tsrcv * u8FreqCfg;
FLASH_BYPASS();
M0P_FLASH->TMRCV_f.TMRCV = Tmrcv * u8FreqCfg;
//开启读FLASH等待周期
if (8 == u8FreqCfg)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.WAIT = 0x01;
}
else if(12 == u8FreqCfg)
{
FLASH_BYPASS();
M0P_FLASH->CR_f.WAIT = 0x01;
}
else
{
FLASH_BYPASS();
M0P_FLASH->CR_f.WAIT = 0x00;
}
pfnFlashCallback = pfnFlashCb;
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH
**
** FLASH写入1字节数据.
**
** \param [in] u32Addr Flash地址
** \param [in] u8Data 1
**
** \retval Ok .
** \retval ErrorInvalidParameter FLASH地址无效
*****************************************************************************/
en_result_t Flash_WriteByte(uint32_t u32Addr, uint8_t u8Data)
{
en_result_t enResult = Ok;
if (FLASH_END_ADDR < u32Addr)
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//unlock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)UnlockAll;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//set OP
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = Program;
//write data
*((volatile uint8_t*)u32Addr) = u8Data;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//lock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)LockAll;
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH
**
** FLASH写入半字2.
**
** \param [in] u32Addr Flash地址
** \param [in] u16Data 2
**
** \retval Ok .
** \retval ErrorInvalidParameter FLASH地址无效
*****************************************************************************/
en_result_t Flash_WriteHalfWord(uint32_t u32Addr, uint16_t u16Data)
{
en_result_t enResult = Ok;
if ((FLASH_END_ADDR < u32Addr) || (u32Addr % 2))
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//unlock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)UnlockAll;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//set OP
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = Program;
//write data
*((volatile uint16_t*)u32Addr) = u16Data;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//lock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)LockAll;
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH
**
** FLASH写入1个字的数据.
**
** \param [in] u32Addr Flash地址
** \param [in] u32Data 1
**
** \retval Ok .
** \retval ErrorInvalidParameter FLASH地址无效
*****************************************************************************/
en_result_t Flash_WriteWord(uint32_t u32Addr, uint32_t u32Data)
{
en_result_t enResult = Ok;
if ((FLASH_END_ADDR < u32Addr) || (u32Addr % 4))
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//unlock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)UnlockAll;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//set OP
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = Program;
//write data
*((volatile uint32_t*)u32Addr) = u32Data;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//lock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = LockAll;
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH
**
** FLASH .
**
** \param [in] u32SectorAddr
**
** \retval Ok .
** \retval ErrorInvalidParameter FLASH地址无效
*****************************************************************************/
en_result_t Flash_SectorErase(uint32_t u32SectorAddr)
{
en_result_t enResult = Ok;
if (FLASH_END_ADDR < u32SectorAddr)
{
enResult = ErrorInvalidParameter;
return (enResult);
}
//unlock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)UnlockAll;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//set OP
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = SectorErase;
//write data
*((volatile uint8_t*)u32SectorAddr) = 0;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//lock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = LockAll;
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH
**
** FLASH .
**
**
** \retval Ok .
**
*****************************************************************************/
en_result_t Flash_ChipErase(void)
{
en_result_t enResult = Ok;
//unlock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = (uint32_t)UnlockAll;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//set OP
FLASH_BYPASS();
M0P_FLASH->CR_f.OP = ChipErase;
//write data
*((volatile uint8_t*)0) = 0;
//busy?
while (TRUE == M0P_FLASH->CR_f.BUSY)
{
;
}
//lock flash
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK = LockAll;
return (enResult);
}
/**
*****************************************************************************
** \brief FLASH
**
** \param [in] enFlashSector
**
** \retval Ok
** \retval ErrorInvalidParameter
*****************************************************************************/
en_result_t Flash_Lock(en_flash_sector_lock_t enFlashSector)
{
en_result_t enResult = Ok;
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK |= (uint32_t)enFlashSector;
return enResult;
}
/**
*****************************************************************************
** \brief FLASH
**
** \param [in] enFlashSector
**
** \retval Ok
** \retval ErrorInvalidParameter
*****************************************************************************/
en_result_t Flash_Unlock(en_flash_sector_lock_t enFlashSector)
{
en_result_t enResult = Ok;
FLASH_BYPASS();
M0P_FLASH->SLOCK_f.SLOCK &= ~(uint32_t)enFlashSector;
return enResult;
}
/**
*****************************************************************************
** \brief FLASH
**
** \param [in] enWaitCycle FLASH读等待周期数枚举类型
**
** \retval Ok
** \retval ErrorInvalidParameter
*****************************************************************************/
en_result_t Flash_WaitCycle(en_flash_waitcycle_t enWaitCycle)
{
en_result_t enResult = Ok;
//插入FLASH读等待周期
M0P_SYSCTRL->PERI_CLKEN_f.FLASH = 1;
M0P_FLASH->BYPASS_f.BYSEQ = 0x5A5A;
M0P_FLASH->BYPASS_f.BYSEQ = 0xA5A5;
if (0 == enWaitCycle)
{
M0P_FLASH->CR_f.WAIT = 0;
}
else if(1 == enWaitCycle)
{
M0P_FLASH->CR_f.WAIT = 1;
}
else
{
M0P_FLASH->CR_f.WAIT = 2;
}
return enResult;
}
//@} // FlashGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,613 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file Gpio.c
**
** GPIO driver API.
** @link Driver Group Some description @endlink
**
** - 2018-04-22 1.0 Lux First version
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "gpio.h"
/**
*******************************************************************************
** \addtogroup GpioGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_PIN(port,pin) ( )
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern') *
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief GPIO
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] pstcGpioCfg IO
**
** \retval Ok
**
******************************************************************************/
en_result_t Gpio_Init(en_gpio_port_t enPort, en_gpio_pin_t enPin, stc_gpio_config_t *pstcGpioCfg)
{
//配置为默认值,GPIO功能
*((uint32_t*)(((uint32_t)(&(M0P_GPIO->PA00_SEL)) + enPort) + (((uint32_t)enPin)<<2))) = GpioAf0;
//方向配置
if(GpioDirIn == pstcGpioCfg->enDir)
{
setBit(((uint32_t)&M0P_GPIO->PADIR + enPort), enPin, TRUE);
}
else
{
setBit(((uint32_t)&M0P_GPIO->PADIR + enPort), enPin, FALSE);
}
//驱动能力配置
if(GpioDrvH == pstcGpioCfg->enDrv)
{
setBit(((uint32_t)&M0P_GPIO->PADR + enPort), enPin, FALSE);
}
else
{
setBit(((uint32_t)&M0P_GPIO->PADR + enPort), enPin, TRUE);
}
//上拉下拉配置
if(GpioPu == pstcGpioCfg->enPuPd)
{
setBit(((uint32_t)&M0P_GPIO->PAPU + enPort), enPin, TRUE);
setBit(((uint32_t)&M0P_GPIO->PAPD + enPort), enPin, FALSE);
}
else if(GpioPd == pstcGpioCfg->enPuPd)
{
setBit(((uint32_t)&M0P_GPIO->PAPU + enPort), enPin, FALSE);
setBit(((uint32_t)&M0P_GPIO->PAPD + enPort), enPin, TRUE);
}
else
{
setBit(((uint32_t)&M0P_GPIO->PAPU + enPort), enPin, FALSE);
setBit(((uint32_t)&M0P_GPIO->PAPD + enPort), enPin, FALSE);
}
//开漏输出功能
if(GpioOdDisable == pstcGpioCfg->enOD)
{
setBit(((uint32_t)&M0P_GPIO->PAOD + enPort), enPin, FALSE);
}
else
{
setBit(((uint32_t)&M0P_GPIO->PAOD + enPort), enPin, TRUE);
}
M0P_GPIO->CTRL2_f.AHB_SEL = pstcGpioCfg->enCtrlMode;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO输入值获取
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval boolean_t IO电平高低
******************************************************************************/
boolean_t Gpio_GetInputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
return getBit(((uint32_t)&M0P_GPIO->PAIN + enPort), enPin);
}
/**
*******************************************************************************
** \brief GPIO IO Port输入数据获取
**
** \param [in] enPort IO Port
**
** \retval boolean_t IO Port数据
******************************************************************************/
uint16_t Gpio_GetInputData(en_gpio_port_t enPort)
{
return (uint16_t)(*((uint32_t *)((uint32_t)&M0P_GPIO->PAIN + enPort)));
}
/**
*******************************************************************************
** \brief GPIO IO输出值写入
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [out] bVal
**
** \retval en_result_t Ok
**
******************************************************************************/
en_result_t Gpio_WriteOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin, boolean_t bVal)
{
setBit(((uint32_t)&M0P_GPIO->PAOUT + enPort), enPin, bVal);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO输出值获取
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval boolean_t IO电平高低
******************************************************************************/
boolean_t Gpio_ReadOutputIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
return getBit(((uint32_t)&M0P_GPIO->PAOUT + enPort), enPin);
}
/**
*******************************************************************************
** \brief GPIO IO Port设置Port中的多个PIN
**
** \param [in] enPort IO Port
** \param [in] u16ValMsk Port的16个PIN掩码值,PIN对应的bit写1有效
**
** \retval boolean_t IO Port数据
******************************************************************************/
en_result_t Gpio_SetPort(en_gpio_port_t enPort, uint16_t u16ValMsk)
{
*((uint16_t*)(((uint32_t)&(M0P_GPIO->PABSET)) + enPort)) = u16ValMsk;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO设置
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval en_result_t Ok
**
******************************************************************************/
en_result_t Gpio_SetIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
setBit(((uint32_t)&M0P_GPIO->PABSET + enPort), enPin, TRUE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO Port清零Port中的多个PIN
**
** \param [in] enPort IO Port
** \param [in] u16ValMsk Port的16个PIN掩码值,PIN对应的bit写1有效
**
** \retval boolean_t IO Port数据
******************************************************************************/
en_result_t Gpio_ClrPort(en_gpio_port_t enPort, uint16_t u16ValMsk)
{
*((uint16_t*)(((uint32_t)&(M0P_GPIO->PABCLR)) + enPort)) = u16ValMsk;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO清零
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval en_result_t Ok
**
******************************************************************************/
en_result_t Gpio_ClrIO(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
setBit(((uint32_t)&M0P_GPIO->PABCLR + enPort), enPin, TRUE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO Port置位//Port中的多个PIN
**
** \param [in] enPort IO Port
** \param [in] u32ValMsk 16bits表示该Port的16个PIN置位掩码值,
** 16bits表示该Port的16个PIN清零掩码值,
** PIN对应的bit写1,PIN的掩码同时为1,PIN清零
**
** \retval en_result_t Ok
**
******************************************************************************/
en_result_t Gpio_SetClrPort(en_gpio_port_t enPort, uint32_t u32ValMsk)
{
*((uint32_t*)(((uint32_t)&(M0P_GPIO->PABSETCLR)) + enPort)) = u32ValMsk;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO配置为模拟功能模式
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
**
** \retval Ok
**
******************************************************************************/
en_result_t Gpio_SetAnalogMode(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
setBit((uint32_t)&M0P_GPIO->PAADS + enPort, enPin, TRUE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO复用功能设置
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] enAf
** \retval Ok
**
******************************************************************************/
en_result_t Gpio_SetAfMode(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_af_t enAf)
{
*((uint32_t*)(((uint32_t)(&(M0P_GPIO->PA00_SEL)) + enPort) + (((uint32_t)enPin)<<2))) = enAf;
return Ok;
}
static en_result_t _GpioEnableIrq(en_gpio_port_t enPort,
en_gpio_pin_t enPin,
en_gpio_irqtype_t enType,
boolean_t bEnable)
{
//high level
if (enType & GpioIrqHigh)
{
setBit((uint32_t)&M0P_GPIO->PAHIE + enPort, enPin, bEnable);
}
//low level
if (enType & GpioIrqLow)
{
setBit((uint32_t)&M0P_GPIO->PALIE + enPort, enPin, bEnable);
}
//rising
if (enType & GpioIrqRising)
{
setBit((uint32_t)&M0P_GPIO->PARIE + enPort, enPin, bEnable);
}
//falling
if (enType & GpioIrqFalling)
{
setBit((uint32_t)&M0P_GPIO->PAFIE + enPort, enPin, bEnable);
}
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO中断使能
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] enType 使
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_EnableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType)
{
_GpioEnableIrq(enPort, enPin, enType, TRUE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO中断关闭
**
** \param [in] enPort IO Port口
** \param [in] enPin IO Pin脚
** \param [in] enType 使
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_DisableIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin, en_gpio_irqtype_t enType)
{
_GpioEnableIrq(enPort, enPin, enType, FALSE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IO中断状态
**
** \param [in] u8Port IO Port口
** \param [in] u8Pin IO Pin脚
**
** \retval IO中断状态开关
******************************************************************************/
boolean_t Gpio_GetIrqStatus(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
return getBit((uint32_t)&M0P_GPIO->PA_STAT + enPort, enPin);
}
/**
*******************************************************************************
** \brief GPIO IO中断状态
**
** \param [in] u8Port IO Port口
** \param [in] u8Pin IO Pin脚
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_ClearIrq(en_gpio_port_t enPort, en_gpio_pin_t enPin)
{
setBit((uint32_t)&M0P_GPIO->PA_ICLR + enPort, enPin, FALSE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO
**
** \param [in] enIrqMode
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfIrqModeConfig(en_gpio_sf_irqmode_t enIrqMode)
{
M0P_GPIO->CTRL0_f.IESEL = enIrqMode;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO IR输出极性配置
**
** \param [in] enIrPolMode IR输出极性配置枚举
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfIrPolConfig(en_gpio_sf_irpol_t enIrPolMode)
{
M0P_GPIO->CTRL1_f.IR_POL = enIrPolMode;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO HCLK输出配置
**
** \param [in] enGate HCLK输出使能
** \param [in] enDiv
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfHClkOutputConfig(en_gpio_sf_hclkout_g_t enGate, en_gpio_sf_hclkout_div_t enDiv)
{
M0P_GPIO->CTRL1_f.HCLK_EN = enGate;
M0P_GPIO->CTRL1_f.HCLK_SEL = enDiv;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO PCLK输出配置
**
** \param [in] enGate PCLK输出使能
** \param [in] enDiv
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfPClkOutputConfig(en_gpio_sf_pclkout_g_t enGate, en_gpio_sf_pclkout_div_t enDiv)
{
M0P_GPIO->CTRL1_f.PCLK_EN = enGate;
M0P_GPIO->CTRL1_f.PCLK_SEL = enDiv;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO
**
** \param [in] enExtClk
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfExtClkConfig(en_gpio_sf_ssn_extclk_t enExtClk)
{
M0P_GPIO->CTRL1_f.EXT_CLK_SEL = enExtClk;
return Ok;
}
/**
*******************************************************************************
** \brief GPIO SSN
**
** \param [in] enSpi SSN SPI通道选择枚举
** \param [in] enSsn SSN
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfSsnConfig(en_gpio_sf_ssnspi_t enSpi, en_gpio_sf_ssn_extclk_t enSsn)
{
//SPI0
if(enSpi == GpioSpi0)
{
M0P_GPIO->CTRL1_f.SSN0_SEL = enSsn;
}
//SPI1
if(enSpi == GpioSpi1)
{
M0P_GPIO->CTRL2_f.SSN1_SEL = enSsn;
}
return Ok;
}
/**
*******************************************************************************
** \brief GPIO Timer
**
** \param [in] enTimG Timer类型选择枚举
** \param [in] enSf Timer互联功能选择枚举
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfTimGConfig(en_gpio_sf_tim_g_t enTimG, en_gpio_sf_t enSf)
{
M0P_GPIO->TIMGS &= (uint32_t)(~(0x07U<<enTimG));
M0P_GPIO->TIMGS |= (uint32_t)(enSf<<enTimG);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO Timer ETR选择配置
**
** \param [in] enTimE Timer类型选择枚举
** \param [in] enSf Timer互联功能选择枚举
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfTimEConfig(en_gpio_sf_tim_e_t enTimE, en_gpio_sf_t enSf)
{
M0P_GPIO->TIMES &= (uint32_t)(~(0x07U<<enTimE));
M0P_GPIO->TIMES |= (uint32_t)(enSf<<enTimE);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO Timer
**
** \param [in] enTimC Timer类型选择枚举
** \param [in] enSf Timer互联功能选择枚举
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfTimCConfig(en_gpio_sf_tim_c_t enTimC, en_gpio_sf_t enSf)
{
M0P_GPIO->TIMCPS &= (uint32_t)(~(0x07u<<enTimC));
M0P_GPIO->TIMCPS |= (uint32_t)(enSf<<enTimC);
return Ok;
}
/**
*******************************************************************************
** \brief GPIO PCA
**
** \param [in] enPca PCA类型选择枚举
** \param [in] enSf PCA互联功能选择枚举
**
** \retval Ok
******************************************************************************/
en_result_t Gpio_SfPcaConfig(en_gpio_sf_pca_t enPca, en_gpio_sf_t enSf)
{
if(GpioSfPcaCH0 == enPca)
{
M0P_GPIO->PCAS_f.PCA_CH0 = enSf;
}
if(GpioSfPcaECI == enPca)
{
M0P_GPIO->PCAS_f.PCA_ECI = enSf;
}
return Ok;
}
//@} // GpioGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,176 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file crc.c
**
** Common API of crc.
** @link crcGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "hdiv.h"
/**
*******************************************************************************
** \addtogroup CrcGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
* \brief
* HDIV
*
* \param [in] Dividend
* \param [in] Dividsor
* \param [out] stcDivResult
*
* \retval en_result_t Ok:
* \retval en_result_t ErrorInvalidParameter:
*/
en_result_t Hdiv_Unsigned(uint32_t Dividend,uint16_t Divisor,stc_div_unsigned_result_t* stcDivResult)
{
M0P_HDIV->SIGN_f.SIGN = 0;
if(NULL == stcDivResult)
{
return ErrorInvalidParameter;
}
(M0P_HDIV ->DIVIDEND) = Dividend;
(M0P_HDIV ->DIVISOR) = Divisor;
if(Hdiv_GetZeroState() == TRUE)
{
return ErrorInvalidParameter;
}
while(Hdiv_GetEndState() != TRUE)
{
;
}
stcDivResult->Quotient = M0P_HDIV->QUOTIENT_f.QUOTIENT;
stcDivResult->Remainder = M0P_HDIV ->REMAINDER_f.REMAINDER;
return Ok;
}
/**
* \brief
* HDIV
*
* \param [in] Dividend
* \param [in] Dividsor
* \param [out] stcDivResult
*
* \retval en_result_t Ok:
* \retval en_result_t ErrorInvalidParameter:
*/
en_result_t Hdiv_Signed(int32_t Dividend,int16_t Divisor,stc_div_signed_result_t* stcDivResult)
{
__IO uint32_t * pDivdend = &(M0P_HDIV ->DIVIDEND);
__IO uint32_t * pDivsor = &(M0P_HDIV ->DIVISOR);
if(NULL == stcDivResult)
{
return ErrorInvalidParameter;
}
M0P_HDIV->SIGN_f.SIGN = 1;
*(__IO int32_t *)pDivdend = Dividend;
*(__IO int16_t *)pDivsor = Divisor;
if(Hdiv_GetZeroState() == TRUE)
{
return ErrorInvalidParameter;
}
while(Hdiv_GetEndState() != TRUE)
{
;
}
stcDivResult->Quotient = M0P_HDIV->QUOTIENT_f.QUOTIENT;
stcDivResult->Remainder = M0P_HDIV ->REMAINDER_f.REMAINDER;
return Ok;
}
boolean_t Hdiv_GetEndState(void)
{
return M0P_HDIV->STAT_f.END;
}
boolean_t Hdiv_GetZeroState(void)
{
return M0P_HDIV->STAT_f.ZERO;
}
//@} // CrcGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,666 @@
/*************************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file I2C.c
**
** WDT function driver API.
** @link SampleGroup Some description @endlink
**
** - 2018-03-13 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "i2c.h"
/**
*******************************************************************************
** \addtogroup I2cGroup
******************************************************************************/
//@{
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
static func_ptr_t pfnI2c0tCallback = NULL;
static func_ptr_t pfnI2c1tCallback = NULL;
/**
******************************************************************************
** \brief I2C设置波特率配置寄存器
**
** \param [in] u8Tm
**
** \retval enRet
**
******************************************************************************/
en_result_t I2C_SetBaud(en_i2c_channel_t enCh,uint8_t u8Tm)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
M0P_I2C0->TM = u8Tm;
}
else
{
M0P_I2C1->TM = u8Tm;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C功能设置相关函数
**
** \param [in] enFunc功能参数
**
** \retval enRet
**
******************************************************************************/
en_result_t I2C_SetFunc(en_i2c_channel_t enCh,en_i2c_func_t enFunc)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
switch(enFunc)
{
case I2cMode_En:
M0P_I2C0->CR_f.ENS = 1;
break;
case I2cStart_En:
M0P_I2C0->CR_f.STA = 1;
break;
case I2cStop_En:
M0P_I2C0->CR_f.STO = 1;
break;
case I2cAck_En:
M0P_I2C0->CR_f.AA = 1;
break;
case I2cHlm_En:
M0P_I2C0->CR_f.H1M = 1;
break;
case I2cBaud_En:
M0P_I2C0->TMRUN = 0x01;
break;
default:
return ErrorInvalidParameter;
}
}
else
{
switch(enFunc)
{
case I2cMode_En:
M0P_I2C1->CR_f.ENS = 1;
break;
case I2cStart_En:
M0P_I2C1->CR_f.STA = 1;
break;
case I2cStop_En:
M0P_I2C1->CR_f.STO = 1;
break;
case I2cAck_En:
M0P_I2C1->CR_f.AA = 1;
break;
case I2cHlm_En:
M0P_I2C1->CR_f.H1M = 1;
break;
case I2cBaud_En:
M0P_I2C1->TMRUN = 0x01;
break;
default:
return ErrorInvalidParameter;
}
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C功能清除相关函数
**
** \param [in] enFunc功能参数
**
** \retval enRet
**
******************************************************************************/
en_result_t I2C_ClearFunc(en_i2c_channel_t enCh,en_i2c_func_t enFunc)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
switch(enFunc)
{
case I2cMode_En:
M0P_I2C0->CR_f.ENS = 0;
break;
case I2cStart_En:
M0P_I2C0->CR_f.STA = 0;
break;
case I2cStop_En:
M0P_I2C0->CR_f.STO = 0;
break;
case I2cAck_En:
M0P_I2C0->CR_f.AA = 0;
break;
case I2cHlm_En:
M0P_I2C0->CR_f.H1M = 0;
break;
case I2cBaud_En:
M0P_I2C0->TMRUN = 0x00;
break;
default:
return ErrorInvalidParameter;
}
}
else
{
switch(enFunc)
{
case I2cMode_En:
M0P_I2C1->CR_f.ENS = 0;
break;
case I2cStart_En:
M0P_I2C1->CR_f.STA = 0;
break;
case I2cStop_En:
M0P_I2C1->CR_f.STO = 0;
break;
case I2cAck_En:
M0P_I2C1->CR_f.AA = 0;
break;
case I2cHlm_En:
M0P_I2C1->CR_f.H1M = 0;
break;
case I2cBaud_En:
M0P_I2C1->TMRUN = 0x00;
break;
default:
return ErrorInvalidParameter;
}
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C获取中断标记函数
**
** \param
**
** \retval bIrq中断标记
**
******************************************************************************/
boolean_t I2C_GetIrq(en_i2c_channel_t enCh)
{
boolean_t bIrq = FALSE;
if(I2C0 == enCh)
{
bIrq = M0P_I2C0->CR_f.SI;
}
else
{
bIrq = M0P_I2C1->CR_f.SI;
}
return bIrq;
}
/**
******************************************************************************
** \brief I2C清除中断标记函数
**
** \param
**
** \retval bIrq中断标记
**
******************************************************************************/
en_result_t I2C_ClearIrq(en_i2c_channel_t enCh)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
M0P_I2C0->CR_f.SI = 0;
}
else
{
M0P_I2C1->CR_f.SI = 0;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C获取相关状态
**
** \param
**
** \retval I2C状态
**
******************************************************************************/
uint8_t I2C_GetState(en_i2c_channel_t enCh)
{
uint8_t u8State = 0;
if(I2C0 == enCh)
{
u8State = M0P_I2C0->STAT;
}
else
{
u8State = M0P_I2C1->STAT;
}
return u8State;
}
/**
******************************************************************************
** \brief I2C写从机地址函数
**
** \param u8SlaveAddr从机地址
**
** \retval I2C写成功与否状态
**
******************************************************************************/
en_result_t I2C_WriteSlaveAddr(en_i2c_channel_t enCh,stc_i2c_addr_t *pstcSlaveAddr)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
M0P_I2C0->ADDR_f.ADR = pstcSlaveAddr->Addr;
M0P_I2C0->ADDR_f.GC = pstcSlaveAddr->Gc;
}
else
{
M0P_I2C1->ADDR_f.ADR = pstcSlaveAddr->Addr;
M0P_I2C1->ADDR_f.GC = pstcSlaveAddr->Gc;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief
**
** \param u8Data写数据
**
** \retval
**
******************************************************************************/
en_result_t I2C_WriteByte(en_i2c_channel_t enCh,uint8_t u8Data)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
M0P_I2C0->DATA = u8Data;
}
else
{
M0P_I2C1->DATA = u8Data;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief
**
** \param
**
** \retval
**
******************************************************************************/
uint8_t I2C_ReadByte(en_i2c_channel_t enCh)
{
uint8_t u8Data = 0;
if(I2C0 == enCh)
{
u8Data = M0P_I2C0->DATA;
}
else
{
u8Data = M0P_I2C1->DATA;
}
return u8Data;
}
/**
******************************************************************************
** \brief
**
** \param u8Addr从机内存地址pu8Data写数据u32Len写数据长度
**
** \retval
**
******************************************************************************/
en_result_t I2C_MasterWriteData(en_i2c_channel_t enCh,uint8_t u8DevAddr,uint8_t u8Addr,uint8_t *pu8Data,uint32_t u32Len)
{
en_result_t enRet = Error;
uint8_t u8i=0,u8State;
I2C_SetFunc(enCh,I2cStart_En);
while(1)
{
while(0 == I2C_GetIrq(enCh))
{}
u8State = I2C_GetState(enCh);
switch(u8State)
{
case 0x08:
I2C_ClearFunc(enCh,I2cStart_En);
I2C_WriteByte(enCh,u8DevAddr);//从设备地址发送
break;
case 0x18:
I2C_WriteByte(enCh,u8Addr);//从设备内存地址发送
break;
case 0x28:
I2C_WriteByte(enCh,pu8Data[u8i++]);
break;
case 0x20:
case 0x38:
I2C_SetFunc(enCh,I2cStart_En);
break;
case 0x30:
I2C_SetFunc(enCh,I2cStop_En);
break;
default:
break;
}
if(u8i>u32Len)
{
I2C_SetFunc(enCh,I2cStop_En);//此顺序不能调换,出停止条件
I2C_ClearIrq(enCh);
break;
}
I2C_ClearIrq(enCh);
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief
**
** \param pu8Data发送数据缓存u32Len发送数据长度
**
** \retval
**
******************************************************************************/
en_result_t I2C_SlaveWriteData(en_i2c_channel_t enCh,uint8_t *pu8Data,uint32_t *u32Len)
{
uint8_t u8i=0,u8State;
//
while(1)
{
while(0 == I2C_GetIrq(enCh))
{}
u8State = I2C_GetState(enCh);
switch(u8State)
{
case 0xA8:
case 0xB0:
I2C_WriteByte(enCh,pu8Data[u8i++]);
break;
case 0xB8:
case 0xC8:
I2C_WriteByte(enCh,pu8Data[u8i++]);
break;
case 0xF8:
*u32Len = u8i;
break;
default:
return ErrorInvalidParameter;
}
I2C_ClearIrq(enCh);
}
}
/**
******************************************************************************
** \brief
**
** \param pu8Data接收数据存放缓存u32Len接收数据指针
**
** \retval
**
******************************************************************************/
en_result_t I2C_SlaveReadData(en_i2c_channel_t enCh,uint8_t *pu8Data,uint32_t *pu32Len)
{
uint8_t u8i=0,u8State;
while(0 == I2C_GetIrq(enCh))
{}
while(1)
{
while(0 == I2C_GetIrq(enCh))
{}
u8State = I2C_GetState(enCh);
switch(u8State)
{
case 0x60:
case 0x68:
case 0x70:
case 0x78:
break;
case 0x80:
case 0x90:
pu8Data[u8i++] = I2C_ReadByte(enCh);
break;
case 0xA0:
*pu32Len = u8i;
break;
default:
return ErrorInvalidParameter;
}
I2C_ClearIrq(enCh);
if(0xA0 == u8State)
{
return Ok;
}
}
}
/**
******************************************************************************
** \brief
**
** \param u8Addr从机内存地址pu8Data读数据存放缓存u32Len读数据长度
**
** \retval
**
******************************************************************************/
en_result_t I2C_MasterReadData(en_i2c_channel_t enCh,uint8_t u8DevAddr,uint8_t *pu8Data,uint8_t u8Addr,uint32_t u32Len)
{
en_result_t enRet = Error;
uint8_t u8i=0,u8State;
I2C_SetFunc(enCh,I2cStart_En);
while(1)
{
while(0 == I2C_GetIrq(enCh))
{}
u8State = I2C_GetState(enCh);
switch(u8State)
{
case 0x08:
I2C_ClearFunc(enCh,I2cStart_En);
I2C_WriteByte(enCh,u8DevAddr);
break;
case 0x18:
I2C_WriteByte(enCh,u8Addr);
break;
case 0x28:
I2C_SetFunc(enCh,I2cStart_En);
break;
case 0x10:
I2C_ClearFunc(enCh,I2cStart_En);
I2C_WriteByte(enCh,u8DevAddr|0x01);//从机地址发送OK
break;
case 0x40:
if(u32Len>1)
{
I2C_SetFunc(enCh,I2cAck_En);
}
break;
case 0x50:
pu8Data[u8i++] = I2C_ReadByte(enCh);
if(u8i==u32Len-1)
{
I2C_ClearFunc(enCh,I2cAck_En);
}
break;
case 0x58:
pu8Data[u8i++] = I2C_ReadByte(enCh);
I2C_SetFunc(enCh,I2cStop_En);
break;
case 0x38:
I2C_SetFunc(enCh,I2cStart_En);
break;
case 0x48:
I2C_SetFunc(enCh,I2cStop_En);
I2C_SetFunc(enCh,I2cStart_En);
break;
default:
I2C_SetFunc(enCh,I2cStart_En);//其他错误状态,重新发送起始条件
break;
}
I2C_ClearIrq(enCh);
if(u8i==u32Len)
{
break;
}
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C模块初始化
**
** \param pstcI2CCfg初始化配置结构体
**
** \retval
**
******************************************************************************/
en_result_t I2C_Init(en_i2c_channel_t enCh,stc_i2c_config_t *pstcI2CCfg)
{
en_result_t enRet = Error;
enRet = I2C_SetFunc(enCh,pstcI2CCfg->enFunc);
enRet = I2C_SetBaud(enCh,pstcI2CCfg->u8Tm);
enRet = I2C_WriteSlaveAddr(enCh,&pstcI2CCfg->stcSlaveAddr);
if(pstcI2CCfg->u8Tm<9)
{
I2C_SetFunc(enCh,I2cHlm_En);
}
if(NULL!=pstcI2CCfg->pfnI2c0Cb)
{
pfnI2c0tCallback = pstcI2CCfg->pfnI2c0Cb;
}
if(NULL!=pstcI2CCfg->pfnI2c1Cb)
{
pfnI2c1tCallback = pstcI2CCfg->pfnI2c1Cb;
}
if(TRUE == pstcI2CCfg->bTouchNvic)
{
if(I2C0 == enCh)
{
EnableNvic(I2C0_IRQn,IrqLevel3,TRUE);
}
else
{
EnableNvic(I2C1_IRQn,IrqLevel3,TRUE);
}
}
return enRet;
}
/**
******************************************************************************
** \brief I2C模块关闭初始化
**
** \param
**
** \retval
**
******************************************************************************/
en_result_t I2C_DeInit(en_i2c_channel_t enCh)
{
en_result_t enRet = Error;
if(I2C0 == enCh)
{
M0P_I2C0->CR = 0x00;
}
else
{
M0P_I2C1->CR = 0x00;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief I2C模块中断处理函数
**
** \param u8Param
**
** \retval
**
******************************************************************************/
void I2c_IRQHandler(uint8_t u8Param)
{
if(I2C0 == u8Param)
{
if(NULL != pfnI2c0tCallback)
{
pfnI2c0tCallback();
}
}
else
{
if(NULL != pfnI2c1tCallback)
{
pfnI2c1tCallback();
}
}
}
//@} // I2cGroup

View File

@ -0,0 +1,477 @@
/******************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file interrupts_hc32l136.c
**
** Interrupt management
** @link Driver Group Some description @endlink
**
** - 2018-04-15 1.0 Lux First version.
**
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "ddl.h"
#include "interrupts_hc32l136.h"
__WEAKDEF void Gpio_IRQHandler(uint8_t u8Param);
__WEAKDEF void Dma_IRQHandler(uint8_t u8Param);
__WEAKDEF void Uart_IRQHandler(uint8_t u8Param);
__WEAKDEF void LpUart_IRQHandler(uint8_t u8Param);
__WEAKDEF void Spi_IRQHandler(uint8_t u8Param);
__WEAKDEF void I2c_IRQHandler(uint8_t u8Param);
__WEAKDEF void Tim_IRQHandler(uint8_t u8Param);
__WEAKDEF void Tim3_IRQHandler(uint8_t u8Param);
__WEAKDEF void Adt_IRQHandler(uint8_t u8Param);
__WEAKDEF void LpTim_IRQHandler(uint8_t u8Param);
__WEAKDEF void Pca_IRQHandler(uint8_t u8Param);
__WEAKDEF void Wdt_IRQHandler(uint8_t u8Param);
__WEAKDEF void Vc_IRQHandler(uint8_t u8Param);
__WEAKDEF void Rtc_IRQHandler(uint8_t u8Param);
__WEAKDEF void Adc_IRQHandler(uint8_t u8Param);
__WEAKDEF void Pcnt_IRQHandler(uint8_t u8Param);
__WEAKDEF void Lvd_IRQHandler(uint8_t u8Param);
__WEAKDEF void Lcd_IRQHandler(uint8_t u8Param);
__WEAKDEF void EfRam_IRQHandler(uint8_t u8Param);
__WEAKDEF void ClkTrim_IRQHandler(uint8_t u8Param);
/**
*******************************************************************************
** \brief NVIC 使
**
** \param [in] enIrq
** \param [in] enLevel
** \param [in] bEn
** \retval Ok
**
******************************************************************************/
void EnableNvic(IRQn_Type enIrq, en_irq_level_t enLevel, boolean_t bEn)
{
NVIC_ClearPendingIRQ(enIrq);
NVIC_SetPriority(enIrq, enLevel);
if (TRUE == bEn)
{
NVIC_EnableIRQ(enIrq);
}
else
{
NVIC_DisableIRQ(enIrq);
}
}
/**
*******************************************************************************
** \brief NVIC hardware fault
**
**
** \retval
******************************************************************************/
void HardFault_Handler(void)
{
volatile int a = 0;
while( 0 == a)
{
;
}
}
/**
*******************************************************************************
** \brief GPIO PortA
**
** \retval
******************************************************************************/
void PORTA_IRQHandler(void)
{
Gpio_IRQHandler(0);
}
/**
*******************************************************************************
** \brief GPIO PortB
**
** \retval
******************************************************************************/
void PORTB_IRQHandler(void)
{
Gpio_IRQHandler(1);
}
/**
*******************************************************************************
** \brief GPIO PortC
**
** \retval
******************************************************************************/
void PORTC_IRQHandler(void)
{
Gpio_IRQHandler(2);
}
/**
*******************************************************************************
** \brief GPIO PortD
**
** \retval
******************************************************************************/
void PORTD_IRQHandler(void)
{
Gpio_IRQHandler(3);
}
/**
*******************************************************************************
** \brief DMAC
**
** \retval
******************************************************************************/
void DMAC_IRQHandler(void)
{
Dma_IRQHandler(0);
}
/**
*******************************************************************************
** \brief UART0 0
**
** \retval
******************************************************************************/
void UART0_IRQHandler(void)
{
Uart_IRQHandler(0);
}
/**
*******************************************************************************
** \brief UART1 1
**
** \retval
******************************************************************************/
void UART1_IRQHandler(void)
{
Uart_IRQHandler(1);
}
/**
*******************************************************************************
** \brief LPUART0 0
**
** \retval
******************************************************************************/
void LPUART0_IRQHandler(void)
{
LpUart_IRQHandler(0);
}
/**
*******************************************************************************
** \brief LPUART1 1
**
** \retval
******************************************************************************/
void LPUART1_IRQHandler(void)
{
LpUart_IRQHandler(1);
}
/**
*******************************************************************************
** \brief SPI0
**
** \retval
******************************************************************************/
void SPI0_IRQHandler(void)
{
Spi_IRQHandler(0);
}
/**
*******************************************************************************
** \brief SPI1
**
** \retval
******************************************************************************/
void SPI1_IRQHandler(void)
{
Spi_IRQHandler(1);
}
/**
*******************************************************************************
** \brief I2C0
**
** \retval
******************************************************************************/
void I2C0_IRQHandler(void)
{
I2c_IRQHandler(0);
}
/**
*******************************************************************************
** \brief I2C1
**
** \retval
******************************************************************************/
void I2C1_IRQHandler(void)
{
I2c_IRQHandler(1);
}
/**
*******************************************************************************
** \brief TIM0 0
**
** \retval
******************************************************************************/
void TIM0_IRQHandler(void)
{
Tim_IRQHandler(0);
}
/**
*******************************************************************************
** \brief TIM1 1
**
** \retval
******************************************************************************/
void TIM1_IRQHandler(void)
{
Tim_IRQHandler(1);
}
/**
*******************************************************************************
** \brief TIM2 2
**
** \retval
******************************************************************************/
void TIM2_IRQHandler(void)
{
Tim_IRQHandler(2);
}
/**
*******************************************************************************
** \brief TIM3 3
**
** \retval
******************************************************************************/
void TIM3_IRQHandler(void)
{
Tim3_IRQHandler(0);
}
/**
*******************************************************************************
** \brief LPTIM
**
** \retval
******************************************************************************/
void LPTIM_IRQHandler(void)
{
LpTim_IRQHandler(0);
}
/**
*******************************************************************************
** \brief TIM4 4
**
** \retval
******************************************************************************/
void TIM4_IRQHandler(void)
{
Adt_IRQHandler(4);
}
/**
*******************************************************************************
** \brief TIM5 5
**
** \retval
******************************************************************************/
void TIM5_IRQHandler(void)
{
Adt_IRQHandler(5);
}
/**
*******************************************************************************
** \brief TIM6 6
**
** \retval
******************************************************************************/
void TIM6_IRQHandler(void)
{
Adt_IRQHandler(6);
}
/**
*******************************************************************************
** \brief PCA
**
** \retval
******************************************************************************/
void PCA_IRQHandler(void)
{
Pca_IRQHandler(0);
}
/**
*******************************************************************************
** \brief WDT
**
** \retval
******************************************************************************/
void WDT_IRQHandler(void)
{
Wdt_IRQHandler(0);
}
/**
*******************************************************************************
** \brief RTC
**
** \retval
******************************************************************************/
void RTC_IRQHandler(void)
{
Rtc_IRQHandler(0);
}
/**
*******************************************************************************
** \brief ADC
**
** \retval
******************************************************************************/
void ADC_IRQHandler(void)
{
Adc_IRQHandler(0);
}
/**
*******************************************************************************
** \brief PCNT
**
** \retval
******************************************************************************/
void PCNT_IRQHandler(void)
{
Pcnt_IRQHandler(0);
}
/**
*******************************************************************************
** \brief 0
**
** \retval
******************************************************************************/
void VC0_IRQHandler(void)
{
Vc_IRQHandler(0);
}
/**
*******************************************************************************
** \brief 1
**
** \retval
******************************************************************************/
void VC1_IRQHandler(void)
{
Vc_IRQHandler(1);
}
/**
*******************************************************************************
** \brief
**
** \retval
******************************************************************************/
void LVD_IRQHandler(void)
{
Lvd_IRQHandler(0);
}
/**
*******************************************************************************
** \brief LCD
**
** \retval
******************************************************************************/
void LCD_IRQHandler(void)
{
Lcd_IRQHandler(0);
}
/**
*******************************************************************************
** \brief RAM
**
** \retval
******************************************************************************/
void EF_RAM_IRQHandler(void)
{
EfRam_IRQHandler(0);
}
/**
*******************************************************************************
** \brief
**
** \retval
******************************************************************************/
void CLKTRIM_IRQHandler(void)
{
ClkTrim_IRQHandler(0);
}
/******************************************************************************/
/* EOF (not truncated) */
/******************************************************************************/

View File

@ -0,0 +1,579 @@
/*************************************************************************************
* Copyright (C) 2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file lcd.c
**
** WDT function driver API.
** @link SampleGroup Some description @endlink
**
** - 2018-5-3 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "lcd.h"
/**
*******************************************************************************
** \addtogroup I2cGroup
******************************************************************************/
//@{
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
en_result_t LCD_SetClkSrc(en_lcd_clk_t enLcdClk)
{
en_result_t enRet = Error;
M0P_LCD->CR1_f.CLKSRC = enLcdClk;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD Bias源选择函数
**
** \param [in] enBiasSrc偏置源选择
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SelBiasSrc(en_lcd_biassrc_t enBiasSrc)
{
en_result_t enRet = Error;
switch(enBiasSrc)
{
case LcdInRes_High:
case LcdInRes_Low:
case LcdInRes_Mid:
case LcdExtCap:
case LcdExtRes:
M0P_LCD->CR0_f.BSEL = enBiasSrc;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD
**
** \param [in] enDuty占空比
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SetDuty(en_lcd_duty_t enDuty)
{
en_result_t enRet = Error;
switch(enDuty)
{
case LcdStatic:
case LcdDuty2:
case LcdDuty3:
case LcdDuty4:
case LcdDuty6:
case LcdDuty8:
M0P_LCD->CR0_f.DUTY = enDuty;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD bias设置函数
**
** \param [in] enBias 
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SetBias(en_lcd_bias_t enBias)
{
en_result_t enRet = Error;
switch(enBias)
{
case LcdBias3:
case LcdBias2:
M0P_LCD->CR0_f.BIAS = enBias;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD
**
** \param [in] enCpClk
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SelCpClk(en_lcd_cpclk_t enCpClk)
{
en_result_t enRet = Error;
switch(enCpClk)
{
case LcdClk2k:
case LcdClk4k:
case LcdClk8k:
case LcdClk16k:
M0P_LCD->CR0_f.CPCLK = enCpClk;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD
**
** \param [in] enScanClk
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SelScanClk(en_lcd_scanclk_t enScanClk)
{
en_result_t enRet = Error;
switch(enScanClk)
{
case LcdClk64hz:
case LcdClk128hz:
case LcdClk256hz:
case LcdClk512hz:
M0P_LCD->CR0_f.LCDCLK = enScanClk;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD 使使
**
** \param [in] enFunc功能bFlag使能或禁止
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_EnFunc(en_lcd_func_t enFunc,boolean_t bFlag)
{
en_result_t enRet = Error;
switch(enFunc)
{
case LcdEn:
M0P_LCD->CR0_f.EN = bFlag;
break;
case LcdBlinkEn:
M0P_LCD->CR1_f.BLINKEN = bFlag;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD 0/1
**
** \param [in] enDispMode模式
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SetDispMode(en_lcd_dispmode_t enDispMode)
{
en_result_t enRet = Error;
switch(enDispMode)
{
case LcdMode0:
case LcdMode1:
M0P_LCD->CR1_f.MODE = enDispMode;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD
**
** \param [in] u8Contrast对比度
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SetContrast(uint8_t u8Contrast)
{
en_result_t enRet = Error;
M0P_LCD->CR0_f.CONTRAST = u8Contrast;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD
**
** \param [in] u8BlinkCnt计数器
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SetBlinkCnt(uint8_t u8BlinkCnt)
{
en_result_t enRet = Error;
M0P_LCD->CR1_f.BLINKCNT = u8BlinkCnt;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD
**
** \param [in]
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_ClrIntState(void)
{
en_result_t enRet = Error;
M0P_LCD->INTCLR_f.INTF = 0;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD显示模式获取端口配置
**
** \param [in]enLcdRunMode stcSegCom获取端口参数
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_GetSegCom(stc_lcd_segcompara_t *pstcSegComPara,stc_lcd_segcom_t *pstcSegCom)
{
en_result_t enRet = Error;
if(pstcSegComPara->u8MaxSeg>40)
{
return ErrorInvalidParameter;
}
switch(pstcSegComPara->enBiasSrc)//seg32_35
{
case LcdInRes_High:
case LcdInRes_Low:
case LcdInRes_Mid:
pstcSegCom->bMux = 1;
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom = 0xff;
break;
case LcdExtCap:
case LcdExtRes:
//VLCD模拟端口配置
if(pstcSegComPara->u8MaxSeg>36)
{
return ErrorInvalidParameter;
}
pstcSegCom->bMux = 0;
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom = 0x0f;//seg32_35置0
break;
default:
return ErrorInvalidParameter;
}
switch(pstcSegComPara->enDuty)//COM0_7
{
case LcdStatic:
pstcSegCom->u8Com0_3 = 0xfe;
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
break;
case LcdDuty2:
pstcSegCom->u8Com0_3 = 0xfc;//COM口配置默认按顺序进行配置com0/com1
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
break;
case LcdDuty3:
pstcSegCom->u8Com0_3 = 0xf8;//只取低4bit
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
break;
case LcdDuty4:
pstcSegCom->u8Com0_3 = 0xf0;//只取低4bit
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xff;
break;
case LcdDuty6:
if(pstcSegComPara->u8MaxSeg>38)
{
return ErrorInvalidParameter;
}
pstcSegCom->u8Com0_3 = 0xf0;//只取低4bit
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xfc;
break;
case LcdDuty8:
if(pstcSegComPara->u8MaxSeg>36)
{
return ErrorInvalidParameter;
}
pstcSegCom->u8Com0_3 = 0xf0;//只取低4bit
pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom &= 0xf0;
break;
default:
return ErrorInvalidParameter;
}
return enRet;
}
/**
******************************************************************************
** \brief LCD COMSEG端口配置
**
** \param [in] pstcSegCom端口配置结构体
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_SetSegCom(stc_lcd_segcom_t *pstcSegCom)
{
en_result_t enRet = Error;
M0P_LCD->POEN0 = pstcSegCom->u32Seg0_31;
M0P_LCD->POEN1 = (uint32_t)(pstcSegCom->Seg32_39VLcdCom7_4_t.SegVLcdCom);
M0P_LCD->POEN1_f.MUX = pstcSegCom->bMux;
M0P_LCD->POEN1_f.C0 = pstcSegCom->u8Com0_3&0x01;
M0P_LCD->POEN1_f.C1 = pstcSegCom->u8Com0_3&0x02;
M0P_LCD->POEN1_f.C2 = pstcSegCom->u8Com0_3&0x04;
M0P_LCD->POEN1_f.C3 = pstcSegCom->u8Com0_3&0x08;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief
**
** \param [in]
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_FullDisp(void)
{
en_result_t enRet=Error;
uint8_t i;
uint32_t volatile *p = NULL;
p = &M0P_LCD->RAM0;
for(i=0;i<8;i++)
{
*p = 0xffffffffu;
p++;
}
for(i=0;i<8;i++)
{
*p = 0xffu;
p++;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief
**
** \param [in]
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_ClearDisp(void)
{
en_result_t enRet=Error;
uint8_t i;
uint32_t volatile *p = NULL;
p = &M0P_LCD->RAM0;
for(i=0;i<16;i++)
{
*p = 0x00;
p++;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD RAM bit设置函数
**
** \param [in] u16Row RAM地址索引u32List bit位索引bData写入0或1
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_WriteRam(uint16_t u16Row, uint32_t u32List, boolean_t bData)
{
en_result_t enRet = Error;
uint8_t RamListSize = 0;
volatile uint32_t *ptemp = NULL;
ptemp = (volatile uint32_t*)&M0P_LCD->RAM0;
if(u16Row>=8)
{
RamListSize = LCDRAM8_FSIZE;
}
else
{
RamListSize = LCDRAM0_7SIZE;
}
if ((u16Row > LCDRAMSIZE) || (u32List > RamListSize))
{
enRet = ErrorInvalidParameter;
return enRet;
}
ptemp += u16Row;
if (bData == TRUE)
{
*ptemp |= (uint32_t)(1 << u32List);
}
else
{
*ptemp &= (uint32_t)(0 << u32List);
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD RAM 0-7
**
** \param [in] u8Row RAM地址索引u32Data写入寄存器数值
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_WriteRam0_7Int32(uint8_t u8Row,uint32_t u32Data)
{
en_result_t enRet = Error;
volatile uint32_t *ptemp = NULL;
ptemp = (volatile uint32_t*)&M0P_LCD->RAM0;
if (u8Row > LCDRAMSIZE)
{
enRet = ErrorInvalidParameter;
return enRet;
}
ptemp += u8Row;
*ptemp = u32Data;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD RAM 8-f寄存器设置函数
**
** \param [in] u8Row RAM地址索引u8Data写入寄存器数值
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_WriteRam8_FInt8(uint8_t u8Row,uint8_t u8Data)
{
en_result_t enRet = Error;
volatile uint32_t *ptemp = NULL;
ptemp = (volatile uint32_t*)&M0P_LCD->RAM0;
if (u8Row > LCDRAMSIZE)
{
enRet = ErrorInvalidParameter;
return enRet;
}
ptemp += u8Row;
*ptemp = u8Data;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LCD模块初始化函数
**
** \param [in] stcLcdCfg配置结构体
**
** \retval enRet
**
******************************************************************************/
en_result_t LCD_Init(stc_lcd_config_t *pstcLcdCfg)
{
en_result_t enRet = Error;
enRet = LCD_SelBiasSrc(pstcLcdCfg->enBiasSrc);
enRet = LCD_SetDuty(pstcLcdCfg->enDuty);
enRet = LCD_SetBias(pstcLcdCfg->enBias);
enRet = LCD_SelCpClk(pstcLcdCfg->enCpClk);
enRet = LCD_SelScanClk(pstcLcdCfg->enScanClk);
enRet = LCD_SetDispMode(pstcLcdCfg->enDispMode);
enRet = LCD_SetClkSrc(pstcLcdCfg->enClk);
if(Ok!=enRet)
{
return ErrorInvalidParameter;
}
if(pstcLcdCfg->bTouchNvic)
{
M0P_LCD->CR1_f.IE = 1;
EnableNvic(LCD_IRQn,IrqLevel3,TRUE);
}
else
{
EnableNvic(LCD_IRQn,IrqLevel3,FALSE);
}
return Ok;
}
//@} // LCDGroup

View File

@ -0,0 +1,134 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file lpm.c
**
** Common API of lpm.
** @link LpmGroup Some description @endlink
**
** - 2017-06-06
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "lpm.h"
/**
*******************************************************************************
** \addtogroup LpmGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
#define IS_VALID_SEVONPEND(x) (SevPndDisable == (x) ||\
SevPndEnable == (x))
#define IS_VALID_SLEEPDEEP(x) (SlpDpDisable == (x) ||\
SlpDpEnable == (x))
#define IS_VALID_SLEEPONEXIT(x) (SlpExtDisable == (x) ||\
SlpExtEnable == (x))
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief
**
**
** \param [in] pstcConfig
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpm_Config(stc_lpm_config_t* pstcConfig)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_SEVONPEND(pstcConfig->enSEVONPEND));
ASSERT(IS_VALID_SLEEPDEEP(pstcConfig->enSLEEPDEEP));
ASSERT(IS_VALID_SLEEPONEXIT(pstcConfig->enSLEEPONEXIT));
SCB->SCR = pstcConfig->enSEVONPEND ? (SCB->SCR | SCB_SCR_SEVONPEND_Msk) : (SCB->SCR & ~SCB_SCR_SEVONPEND_Msk);
SCB->SCR = pstcConfig->enSLEEPDEEP ? (SCB->SCR | SCB_SCR_SLEEPDEEP_Msk) : (SCB->SCR & ~SCB_SCR_SLEEPDEEP_Msk);
SCB->SCR = pstcConfig->enSLEEPONEXIT ? (SCB->SCR | SCB_SCR_SLEEPONEXIT_Msk) : (SCB->SCR & ~SCB_SCR_SLEEPONEXIT_Msk);
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief
**
**
**
** \retval NULL
*****************************************************************************/
void Lpm_GotoLpmMode(void)
{
__WFI();
}
//@} // LpmGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,289 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file lpt.c
**
** Common API of Low Power timer.
** @link lptGroup Some description @endlink
**
** - 2018-04-16 Husj First version
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "lpt.h"
/**
*******************************************************************************
** \addtogroup LptGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
static func_ptr_t pfnLpTimCallback = NULL;
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Low Power Timer
**
**
**
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Lpt_GetIntFlag(void)
{
boolean_t bRetVal = FALSE;
bRetVal = M0P_LPTIMER->IFR_f.TF ? TRUE : FALSE;
return bRetVal;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_ClearIntFlag(void)
{
en_result_t enResult = Error;
M0P_LPTIMER->ICLR_f.TFC = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
** \param [in] u8Param == 0
**
*****************************************************************************/
void LpTim_IRQHandler(uint8_t u8Param)
{
if(NULL != pfnLpTimCallback)
{
pfnLpTimCallback();
}
}
/**
*****************************************************************************
** \brief Low Power Timer 使
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_EnableIrq (void)
{
en_result_t enResult = Error;
M0P_LPTIMER->CR_f.IE = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_DisableIrq(void)
{
en_result_t enResult = Error;
M0P_LPTIMER->CR_f.IE = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
** \param [in] pstcConfig
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_Init(stc_lpt_config_t* pstcConfig)
{
en_result_t enResult = Error;
M0P_LPTIMER->CR_f.GATE_P = pstcConfig->enGateP;
M0P_LPTIMER->CR_f.GATE = pstcConfig->enGate;
M0P_LPTIMER->CR_f.TCK_SEL = pstcConfig->enTckSel;
M0P_LPTIMER->CR_f.TOG_EN = pstcConfig->enTog;
M0P_LPTIMER->CR_f.CT = pstcConfig->enCT;
M0P_LPTIMER->CR_f.MD = pstcConfig->enMD;
pfnLpTimCallback = pstcConfig->pfnLpTimCb;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_Run(void)
{
en_result_t enResult = Error;
M0P_LPTIMER->CR_f.TR = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_Stop(void)
{
en_result_t enResult = Error;
M0P_LPTIMER->CR_f.TR = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer
**
**
** \param [in] u16Data 16bits重载值
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Lpt_ARRSet(uint16_t u16Data)
{
en_result_t enResult = Error;
boolean_t bRetVal = FALSE;
bRetVal = M0P_LPTIMER->CR_f.WT_FLAG ? TRUE : FALSE;
if(TRUE == bRetVal)
{
M0P_LPTIMER->ARR_f.ARR = u16Data;
enResult = Ok;
}
else
{
enResult = Error;
}
return enResult;
}
/**
*****************************************************************************
** \brief Low Power Timer 16
**
**
**
** \retval 16bits计数值
*****************************************************************************/
uint16_t Lpt_Cnt16Get(void)
{
uint16_t u16CntData = 0;
u16CntData = M0P_LPTIMER->CNT_f.CNT;
return u16CntData;
}
//@} // LptGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,966 @@
/*************************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file lpuart.c
**
** LPUART function driver API.
** @link SampleGroup Some description @endlink
**
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "lpuart.h"
/**
******************************************************************************
** \addtogroup LPUartGroup
******************************************************************************/
//@{
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define IS_VALID_CH(x) ((LPUART0 == (x)) ||\
(LPUART1 == (x)))
#define IS_VALID_CLK(x) ((LPUart_Pclk==(x))||\
(LPUart_Pclk_1==(x))||\
(LPUart_Xtl==(x))||\
(LPUart_Rcl==(x)))
#define IS_VALID_IRQSEL(x) ((LPUartTxIrq == (x)) ||\
(LPUartRxIrq == (x)) ||\
(LPUartFEIrq == (x)) ||\
(LPUartCtsIrq == (x))||\
(LPUartPEIrq == (x)) ||\
(LPUartTxEIrq == (x)))
#define IS_VALID_MODE(x) ((LPUartMode0==(x))||\
(LPUartMode1==(x))||\
(LPUartMode2==(x))||\
(LPUartMode3==(x)))
#define IS_VALID_STATUS(x) ((LPUartCts == (x))||\
(LPUartRC == (x))||\
(LPUartTC == (x))||\
(LPUartPE == (x))||\
(LPUartCtsIf == (x))||\
(LPUartTxe == (x))||\
(LPUartFE == (x)))
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
static stc_lpuart_instance_data_t* LPUartGetInternDataPtr(uint8_t u8Idx);
static void LPUartInitNvic(uint8_t u8Idx);
static void LPUartDeInitNvic(uint8_t u8Idx);
/******************************************************************************/
/* Local variable definitions ('static') */
/******************************************************************************/
static stc_lpuart_instance_data_t m_astcLPUartInstanceDataLut[] =
{
{
LPUART0,
M0P_LPUART0, /* pstcInstance */
{NULL,NULL,NULL,NULL,NULL},
},
{
LPUART1,
M0P_LPUART1, /* pstcInstance */
{NULL,NULL,NULL,NULL,NULL},
},
};
/**
******************************************************************************
** \brief LPUART0/1
**
** \param [in] u8Idx通道号
**
** \retval
**
******************************************************************************/
static stc_lpuart_instance_data_t* LPUartGetInternDataPtr(uint8_t u8Idx)
{
stc_lpuart_instance_data_t* pstcData = NULL;
uint8_t u8i = 0;
for (u8i = 0; u8i < ARRAY_SZ(m_astcLPUartInstanceDataLut); u8i++)
{
if (u8Idx == m_astcLPUartInstanceDataLut[u8i].u32Idx)
{
pstcData = &m_astcLPUartInstanceDataLut[u8i];
break;
}
}
return (pstcData);
}
/**
******************************************************************************
** \brief LPUART通信中断使能函数设置
**
** \param [in] u8Idx通道号enIrqSel发送or接收中断使能
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_EnableIrq(uint8_t u8Idx,
en_lpuart_irq_sel_t enIrqSel)
{
stc_lpuart_instance_data_t* pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
ASSERT(IS_VALID_IRQSEL(enIrqSel));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
switch(enIrqSel)
{
case LPUartTxIrq:
pstcData->pstcInstance->SCON_f.TCIE = 1u;
break;
case LPUartRxIrq:
pstcData->pstcInstance->SCON_f.RCIE = 1u;
break;
case LPUartFEIrq:
pstcData->pstcInstance->SCON_f.FEIE = 1u;
break;
case LPUartCtsIrq:
pstcData->pstcInstance->SCON_f.CTSIE = 1u;
break;
case LPUartPEIrq:
pstcData->pstcInstance->SCON_f.PEIE = 1u;
break;
case LPUartTxEIrq:
pstcData->pstcInstance->SCON_f.TXEIE = 1u;
break;
default:
return (ErrorInvalidParameter);
}
return Ok;
}
/**
******************************************************************************
** \brief LPUART通信中断禁止函数设置
**
** \param [in] u8Idx通道号enIrqSel发送or接收中断禁止
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_DisableIrq(uint8_t u8Idx,
en_lpuart_irq_sel_t enIrqSel)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
ASSERT(IS_VALID_IRQSEL(enIrqSel));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
switch(enIrqSel)
{
case LPUartTxIrq:
pstcData->pstcInstance->SCON_f.TCIE = 0u;
break;
case LPUartRxIrq:
pstcData->pstcInstance->SCON_f.RCIE = 0u;
break;
case LPUartFEIrq:
pstcData->pstcInstance->SCON_f.FEIE = 0u;
break;
case LPUartCtsIrq:
pstcData->pstcInstance->SCON_f.CTSIE = 0u;
break;
case LPUartPEIrq:
pstcData->pstcInstance->SCON_f.PEIE = 0u;
break;
case LPUartTxEIrq:
pstcData->pstcInstance->SCON_f.TXEIE = 0u;
break;
default:
return (ErrorInvalidParameter);
}
return Ok;
}
/**
******************************************************************************
** \brief lpuart通信时钟源选择
**
** \param [in] u8Idx通道号enClk
**
** \retval Ok
**\retval ErrorInvalidParameter设置失败
******************************************************************************/
en_result_t LPUart_SelSclk(uint8_t u8Idx,en_lpuart_sclksel_t enClk)
{
stc_lpuart_instance_data_t *pstcData = NULL;
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
ASSERT(IS_VALID_CH(u8Idx));
ASSERT(IS_VALID_CLK(enClk));
switch(enClk)
{
case LPUart_Pclk:
case LPUart_Pclk_1:
case LPUart_Xtl:
case LPUart_Rcl:
pstcData->pstcInstance->SCON_f.SCLKSEL = enClk;
break;
default:
return (ErrorInvalidParameter);
}
return Ok;
}
/**
******************************************************************************
** \brief lpuart通信时钟源选择
**
** \param [in] u8Idx通道号
**
** \retval Ok
**\retval
******************************************************************************/
uint32_t LPUart_GetSclk(uint8_t u8Idx)
{
stc_lpuart_instance_data_t *pstcData = NULL;
uint8_t u8Sclksrc;
uint32_t u32Sclk;
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
ASSERT(IS_VALID_CH(u8Idx));
u8Sclksrc = pstcData->pstcInstance->SCON_f.SCLKSEL;
switch(u8Sclksrc)
{
case 0x00:
case 0x01:
u32Sclk = Sysctrl_GetPClkFreq();
break;
case 0x02:
u32Sclk = 32768;
break;
case 0x03:
u32Sclk = 38400;//此处必须使能内部38.4k
break;
default:
return 0;
}
return u32Sclk;
}
/**
******************************************************************************
** \brief LPUART通道4种模式配置
**
** \param [in] u8Idx通道号mode哪种模式
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_SetMode(uint8_t u8Idx,en_lpuart_mode_t enMode)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
ASSERT(IS_VALID_MODE(enMode));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
pstcData->pstcInstance->SCON_f.SM = enMode;
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道多主机模式配置
**
** \param [in] u8Idx通道号stcMultiConfig多主机模式结构
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_SetMultiMode(uint8_t u8Idx,stc_lpuart_multimode_t* pstcMultiConfig)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
if(NULL != pstcMultiConfig)
{
pstcData->pstcInstance->SCON_f.ADRDET = pstcMultiConfig->enMulti_mode;
if(pstcMultiConfig->enMulti_mode == LPUartMulti)
{
pstcData->pstcInstance->SADDR = pstcMultiConfig->u8SlaveAddr;
pstcData->pstcInstance->SADEN = pstcMultiConfig->u8SaddEn;
}
}
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道多主机模式发送数据/TB8
**
** \param [in] u8Idx通道号tb8数据or地址帧或者奇偶校验
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_SetMMDOrCk(uint8_t u8Idx,en_lpuart_mmdorck_t enTb8)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
pstcData->pstcInstance->SCON_f.B8CONT = enTb8;
return Ok;
}
/**
******************************************************************************
** \brief RB8数值
**
** \param [in] u8Idx通道号
**
** \retval RB8
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
boolean_t LPUart_GetRb8(uint8_t u8Idx)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
return ((pstcData->pstcInstance->SBUF>>8)&0x01);
}
/**
******************************************************************************
** \brief LPUART通道多主机模式从机地址配置函数
**
** \param [in] u8Idx通道号addr地址
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_SetSaddr(uint8_t u8Idx,uint8_t u8Addr)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
pstcData->pstcInstance->SADDR = u8Addr;
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道多主机模式从机掩码配置函数
**
** \param [in] u8Idx通道号addren地址掩码
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_SetSaddrEn(uint8_t u8Idx,uint8_t u8Addren)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
pstcData->pstcInstance->SADEN = u8Addren;
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道停止位长度设置
**
** \param [in] u8Idx通道号u8Len停止位长度
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_SetStopBit(uint8_t u8Idx,uint8_t u8Len)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
switch(u8Len)
{
case LPUart1bit:
case LPUart15bit:
case LPUart2bit:
pstcData->pstcInstance->SCON_f.STOPBIT = u8Len;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief LPUART采样频率配置
**
** \param [in] u8Idx通道号u8Div采样频率
**
** \retval OK配置成功
******************************************************************************/
en_result_t LPUart_SetClkDiv(uint8_t u8Idx,en_lpuart_clkdiv_t enClkDiv)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
pstcData->pstcInstance->SCON_f.OVER = enClkDiv;
return Ok;
}
/**
******************************************************************************
** \brief LPUART波特率计算值
**
** \param [in] u8Idx通道号stcBaud计算波特率值参数
**
** \retval SCNT计算值
******************************************************************************/
uint16_t LPUart_CalScnt(uint8_t u8Idx,stc_lpuart_baud_t *pstcBaud)
{
stc_lpuart_instance_data_t *pstcData = NULL;
uint16_t u16Scnt = 0;
uint8_t u8Over = 0;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
u8Over = pstcData->pstcInstance->SCON_f.OVER;
if(u8Over == 3)
{
return 0;//test
}
if(LPUartMode0 == pstcBaud->enRunMode)
{
return 0;//test
}
if((LPUartMode1 == pstcBaud->enRunMode)||(LPUartMode3 == pstcBaud->enRunMode))
{
u8Over = 1<<(4-u8Over);
u16Scnt = pstcBaud->u32Sclk/(pstcBaud->u32Baud*u8Over);
}
else
{
u8Over = 1<<(5-u8Over);
u16Scnt = pstcBaud->u32Sclk/u8Over;
}
return u16Scnt;
}
/**
******************************************************************************
** \brief LPUART通道波特率配置
**
** \param [in] u8Idx通道号u32pclk时钟源stcBaud波特率配置结构
**
** \retval
** \retval 0,
******************************************************************************/
en_result_t LPUart_SetBaud(uint8_t u8Idx,uint16_t u16Scnt)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
pstcData->pstcInstance->SCNT = u16Scnt;
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道波特率获取
**
** \param [in] u8Idx通道号,u8Mode工作模式
**
** \retval
******************************************************************************/
uint32_t LPUart_GetBaud(uint8_t u8Idx,uint8_t u8Mode,uint32_t u32Pclk)
{
stc_lpuart_instance_data_t *pstcData = NULL;
uint32_t u32Baud = 0;
uint8_t u8Over = 0;
uint16_t u16Scnt = 0;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
u8Over = pstcData->pstcInstance->SCON_f.OVER;
switch(u8Mode)
{
case LPUartMode0:
u32Baud = u32Pclk/12;
break;
case LPUartMode1:
case LPUartMode3:
u16Scnt = pstcData->pstcInstance->SCNT;
u8Over = 1<<(4-u8Over);
u32Baud = u32Pclk/(u8Over*u16Scnt);
break;
case LPUartMode2:
u8Over = 1<<(5-u8Over);
u32Baud = u32Pclk/u8Over;
break;
default:
return 0;//test
}
return u32Baud;
}
/**
******************************************************************************
** \brief LPUART通道发送或接收等功能使能设置
**
** \param [in] u8Idx通道号enFunc功能
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_EnableFunc(uint8_t u8Idx, en_lpuart_func_t enFunc)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
switch(enFunc)
{
case LPUartTx:
case LPUartRx:
pstcData->pstcInstance->SCON_f.REN = 1u;
break;
case LPUartDmaTx:
pstcData->pstcInstance->SCON_f.DMATXEN = 1u;
break;
case LPUartDmaRx:
pstcData->pstcInstance->SCON_f.DMARXEN = 1u;
break;
case LPUartCtsRts:
pstcData->pstcInstance->SCON_f.CTSEN = 1u;
pstcData->pstcInstance->SCON_f.RTSEN = 1u;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道发送或接收等功能禁止设置
**
** \param [in] u8Idx通道号enFunc功能
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_DisableFunc(uint8_t u8Idx, en_lpuart_func_t enFunc)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
switch(enFunc)
{
case LPUartTx:
case LPUartRx:
pstcData->pstcInstance->SCON_f.REN = 0u;
break;
case LPUartDmaTx:
pstcData->pstcInstance->SCON_f.DMATXEN = 0u;
break;
case LPUartDmaRx:
pstcData->pstcInstance->SCON_f.DMARXEN = 0u;
break;
case LPUartCtsRts:
pstcData->pstcInstance->SCON_f.CTSEN = 0u;
pstcData->pstcInstance->SCON_f.RTSEN = 0u;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道通信状态获取
**
** \param [in] u8Idx通道号
**
** \retval isr
******************************************************************************/
uint8_t LPUart_GetIsr(uint8_t u8Idx)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
return(pstcData->pstcInstance->ISR);
}
/**
******************************************************************************
** \brief LPUART通道通信状态全部清除
**
** \param [in] u8Idx通道号
**
**\retval Ok
******************************************************************************/
en_result_t LPUart_ClrIsr(uint8_t u8Idx)
{
en_result_t enRet = Error;
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
pstcData->pstcInstance->ICR = 0;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief LPUART通道通信状态获取
**
** \param [in] u8Idx通道号enStatus获取哪个状态
**
** \retval
**\retval ErrorInvalidParameter获取失败
******************************************************************************/
boolean_t LPUart_GetStatus(uint8_t u8Idx,en_lpuart_status_t enStatus)
{
boolean_t bStatus=FALSE;
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
ASSERT(IS_VALID_STATUS(enStatus));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;//4用户只需判断0或1
}
switch(enStatus)
{
case LPUartCts:
bStatus = (pstcData->pstcInstance->ISR_f.CTS == 1) ? TRUE : FALSE;
break;
case LPUartRC:
bStatus = (pstcData->pstcInstance->ISR_f.RC == 1) ? TRUE : FALSE;
break;
case LPUartTC:
bStatus = (pstcData->pstcInstance->ISR_f.TC == 1) ? TRUE : FALSE;
break;
case LPUartPE:
bStatus = (pstcData->pstcInstance->ISR_f.PE == 1) ? TRUE : FALSE;
break;
case LPUartFE:
bStatus = (pstcData->pstcInstance->ISR_f.FE == 1) ? TRUE : FALSE;
break;
case LPUartCtsIf:
bStatus = (pstcData->pstcInstance->ISR_f.CTSIF == 1) ? TRUE : FALSE;
break;
case LPUartTxe:
bStatus = (pstcData->pstcInstance->ISR_f.TXE == 1) ? TRUE : FALSE;
break;
default:
break;
}
return bStatus;
}
/**
******************************************************************************
** \brief LPUART通道通信状态清除
**
** \param [in] u8Idx通道号enStatus清除哪个状态
**
** \retval
**\retval ErrorInvalidParameter清除失败
******************************************************************************/
en_result_t LPUart_ClrStatus(uint8_t u8Idx,en_lpuart_status_t enStatus)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
ASSERT(IS_VALID_STATUS(enStatus));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
switch(enStatus)
{
case LPUartCts:
pstcData->pstcInstance->ICR_f.CTSIFCF = 0;
break;
case LPUartRC:
pstcData->pstcInstance->ICR_f.RCCF = 0;
break;
case LPUartTC:
pstcData->pstcInstance->ICR_f.TCCF = 0;
break;
case LPUartPE:
pstcData->pstcInstance->ICR_f.PECF = 0;
break;
case LPUartFE:
pstcData->pstcInstance->ICR_f.FECF = 0;
break;
default:
break;
}
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道发送数据函数,
**
** \param [in] u8Idx通道号Data发送数据
**
** \retval Ok发送成功
**\retval ErrorInvalidParameter发送失败
******************************************************************************/
en_result_t LPUart_SendData(uint8_t u8Idx, uint8_t u8Data)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
LPUart_ClrStatus(u8Idx,LPUartTC);
pstcData->pstcInstance->SBUF_f.DATA = u8Data;
while(FALSE == LPUart_GetStatus(u8Idx,LPUartTC))
{}
LPUart_ClrStatus(u8Idx,LPUartTC);
return Ok;
}
/**
******************************************************************************
** \brief LPUART通道接收数据函数
**
** \param [in] u8Idx通道号
**
** \retval
**\retval ErrorInvalidParameter接收失败
******************************************************************************/
uint8_t LPUart_ReceiveData(uint8_t u8Idx)
{
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
return (pstcData->pstcInstance->SBUF_f.DATA);
}
/**
******************************************************************************
** \brief LPUART通道中断处理函数
**
** \param [in] u8Param通道号
**
** \retval
**
******************************************************************************/
void LpUart_IRQHandler(uint8_t u8Param)
{
stc_lpuart_instance_data_t *pstcData = NULL;
pstcData = LPUartGetInternDataPtr(u8Param);
if (NULL == pstcData)
{
return;
}
if(1 == pstcData->pstcInstance->ISR_f.FE)
{
LPUart_ClrStatus(u8Param,LPUartFE);
if(NULL != pstcData->stcLPUartInternIrqCb.pfnRxFEIrqCb)
{
pstcData->stcLPUartInternIrqCb.pfnRxFEIrqCb();
}
return;//帧出错则不进行后续数据处理
}
if(1 == pstcData->pstcInstance->ISR_f.PE)
{
LPUart_ClrStatus(u8Param,LPUartPE);
if(NULL != pstcData->stcLPUartInternIrqCb.pfnPEIrqCb)
{
pstcData->stcLPUartInternIrqCb.pfnPEIrqCb();
}
return;//若奇偶校验出错则不进行后续数据处理
}
if(1 == pstcData->pstcInstance->ISR_f.CTSIF)
{
LPUart_ClrStatus(u8Param,LPUartCts);
if(NULL != pstcData->stcLPUartInternIrqCb.pfnCtsIrqCb)
{
pstcData->stcLPUartInternIrqCb.pfnCtsIrqCb();
}
}
if(1 == pstcData->pstcInstance->ISR_f.RC)
{
LPUart_ClrStatus(u8Param,LPUartRC);
if(NULL != pstcData->stcLPUartInternIrqCb.pfnRxIrqCb)
{
pstcData->stcLPUartInternIrqCb.pfnRxIrqCb();
}
}
if(1 == pstcData->pstcInstance->ISR_f.TC)
{
LPUart_ClrStatus(u8Param,LPUartTC);
if(NULL != pstcData->stcLPUartInternIrqCb.pfnTxIrqCb)
{
pstcData->stcLPUartInternIrqCb.pfnTxIrqCb();
}
}
}
/**
******************************************************************************
** \brief LPUART通道使能内核NVIC中断
**
** \param [in] u8Idx通道号
**
** \retval
**
******************************************************************************/
static void LPUartInitNvic(uint8_t u8Idx)
{
IRQn_Type enIrqIndex;
ASSERT(IS_VALID_CH(u8Idx));;
enIrqIndex = (IRQn_Type)(LPUART0_IRQn + u8Idx);
NVIC_ClearPendingIRQ(enIrqIndex);
NVIC_SetPriority(enIrqIndex,IrqLevel3);
NVIC_EnableIRQ(enIrqIndex);
}
/**
******************************************************************************
** \brief LPUART通道禁止内核NVIC中断
**
** \param [in] u8Idx通道号
**
** \retval
**
******************************************************************************/
static void LPUartDeInitNvic(uint8_t u8Idx)
{
IRQn_Type enIrqIndex;
ASSERT(IS_VALID_CH(u8Idx));
enIrqIndex = (IRQn_Type)(LPUART0_IRQn + u8Idx);
NVIC_ClearPendingIRQ(enIrqIndex);
NVIC_SetPriority(enIrqIndex,IrqLevel3);
NVIC_DisableIRQ(enIrqIndex);
}
/**
******************************************************************************
** \brief LPUART通道初始化函数
**
** \param [in] u8Idx通道号pstcConfig初始化结构体
**
** \retval OK配置成功
**\retval ErrorInvalidParameter配置失败
******************************************************************************/
en_result_t LPUart_Init(uint8_t u8Idx,stc_lpuart_config_t* pstcConfig)
{
en_result_t enRet = Error;
stc_lpuart_instance_data_t *pstcData = NULL;
ASSERT(IS_VALID_CH(u8Idx));
pstcData = LPUartGetInternDataPtr(u8Idx);
if (NULL == pstcData)
{
return ErrorInvalidParameter;
}
if(NULL == pstcConfig)
{
return ErrorInvalidParameter;
}
if(NULL != pstcConfig->pstcLpuart_clk)
{
LPUart_SelSclk(u8Idx,pstcConfig->pstcLpuart_clk->enSclk_sel);
LPUart_SetClkDiv(u8Idx,pstcConfig->pstcLpuart_clk->enSclk_Prs);
}
enRet = LPUart_SetMode(u8Idx,pstcConfig->enRunMode);
enRet = LPUart_SetStopBit(u8Idx,pstcConfig->enStopBit);
if(NULL != pstcConfig->pstcMultiMode)
{
enRet = LPUart_SetMultiMode(u8Idx,pstcConfig->pstcMultiMode);
}
if(NULL != pstcConfig->pstcIrqCb)
{
pstcData->stcLPUartInternIrqCb.pfnRxFEIrqCb = pstcConfig->pstcIrqCb->pfnRxFEIrqCb;
pstcData->stcLPUartInternIrqCb.pfnRxIrqCb = pstcConfig->pstcIrqCb->pfnRxIrqCb;
pstcData->stcLPUartInternIrqCb.pfnTxIrqCb = pstcConfig->pstcIrqCb->pfnTxIrqCb;
pstcData->stcLPUartInternIrqCb.pfnCtsIrqCb = pstcConfig->pstcIrqCb->pfnCtsIrqCb;
pstcData->stcLPUartInternIrqCb.pfnPEIrqCb = pstcConfig->pstcIrqCb->pfnPEIrqCb;
}
if(pstcConfig->bTouchNvic == TRUE)
{
LPUartInitNvic(u8Idx);
}
else
{
LPUartDeInitNvic(u8Idx);
}
enRet = Ok;
return enRet;
}
//@} // LPUartGroup

View File

@ -0,0 +1,327 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file lvd.c
**
** Low Voltage Detect driver API.
** @link Lvd Group Some description @endlink
**
** - 2017-06-28 Alex First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "lvd.h"
/**
******************************************************************************
** \addtogroup LvdGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_INPUT(x) ( (x) <= LvdInputPB07 )
#define IS_VALID_THRESHOLD(x) ( (x) <= LvdTH3p3V )
#define IS_VALID_FILTER(x) ( (x) <= LvdFilter29ms )
#define IS_VALID_IRQTYPE(x) ( (x) <= LvdIrqFall )
/******************************************************************************
* Global variable definitions (declared in header file with 'extern') *
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
// static void LvdEnableNvic(void);
// static void LvdDisableNvic(void);
// static en_result_t LvdEnable(en_lvd_type_t enType, boolean_t bFlag);
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
static func_ptr_t pfnLvdIrqCbk = NULL;
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
*****************************************************************************/
/**
* \brief
* LVD中断服务程序
*
* \param [in] u8Param 使
*
* \retval
*/
void Lvd_IRQHandler(uint8_t u8Param)
{
M0P_LVD->IFR_f.INTF = 0u;
if (NULL != pfnLvdIrqCbk)
{
pfnLvdIrqCbk();
}
}
/**
* \brief
* 使NVIC中LVD中断
*
* \param
*
* \retval
*/
static void LvdEnableNvic(void)
{
NVIC_ClearPendingIRQ(LVD_IRQn);
NVIC_SetPriority(LVD_IRQn, IrqLevel3);
NVIC_EnableIRQ(LVD_IRQn);
}
/**
* \brief
* NVIC中LVD中断
*
* \param
*
* \retval
*/
static void LvdDisableNvic(void)
{
NVIC_ClearPendingIRQ(LVD_IRQn);
NVIC_DisableIRQ(LVD_IRQn);
NVIC_SetPriority(LVD_IRQn, IrqLevel3);
}
/**
* \brief
* 使LVD中断
*
* \param [in] enType LVD中断类型
*
* \retval en_result_t Ok:
* \retval en_result_t ErrorInvalidParameter:
*/
en_result_t Lvd_EnableIrq(en_lvd_irq_type_t enType)
{
en_result_t enRet = Ok;
if (enType > LvdIrqFall)
{
return ErrorInvalidParameter;
}
else
{ switch (enType)
{
case LvdIrqHigh:
M0P_LVD->CR_f.HTEN = 1u;
M0P_LVD->CR_f.RTEN = 0u;
M0P_LVD->CR_f.FTEN = 0u;
break;
case LvdIrqRise:
M0P_LVD->CR_f.HTEN = 0u;
M0P_LVD->CR_f.RTEN = 1u;
M0P_LVD->CR_f.FTEN = 0u;
break;
case LvdIrqFall:
M0P_LVD->CR_f.HTEN = 0u;
M0P_LVD->CR_f.RTEN = 0u;
M0P_LVD->CR_f.FTEN = 1u;
break;
default:
break;
}
M0P_LVD->CR_f.IE = 1u;
LvdEnableNvic();
}
return enRet;
}
/**
* \brief
* LVD中断
*
* \param
*
* \retval
*/
void Lvd_DisableIrq(void)
{
LvdDisableNvic();
M0P_LVD->CR_f.IE = 0u;
M0P_LVD->CR_f.HTEN = 0u;
M0P_LVD->CR_f.RTEN = 0u;
M0P_LVD->CR_f.FTEN = 0u;
}
/**
* \brief
* LVD初始化
*
* \param [in] pstcConfig LVD配置指针
*
* \retval
*/
void Lvd_Init(stc_lvd_config_t *pstcConfig)
{
ASSERT(pstcConfig);
ASSERT(IS_VALID_INPUT(pstcConfig->enInput));
ASSERT(IS_VALID_THRESHOLD(pstcConfig->enThreshold));
ASSERT(IS_VALID_FILTER(pstcConfig->enFilterTime));
ASSERT(IS_VALID_IRQTYPE(pstcConfig->enIrqType));
//NEED to DISABLE first.
Lvd_Disable();
Lvd_DisableIrq();
LvdDisableNvic();
M0P_LVD->CR_f.DEBOUNCE_TIME = pstcConfig->enFilterTime;
M0P_LVD->CR_f.FLTEN = pstcConfig->bFilter;
M0P_LVD->CR_f.VTDS = pstcConfig->enThreshold;
M0P_LVD->CR_f.SOURCE_SEL = pstcConfig->enInput;
M0P_LVD->CR_f.ACT = pstcConfig->bLvdReset;
pfnLvdIrqCbk = pstcConfig->pfnIrqCbk;
}
/**
* \brief
* LVD deinit
*
* \param
*
* \retval
*/
void Lvd_DeInit(void)
{
Lvd_DisableIrq();
LvdDisableNvic();
pfnLvdIrqCbk = NULL;
Lvd_Disable();
}
/**
* \brief
* 使LVD
*
* \param
*
* \retval
*
*/
void Lvd_Enable(void)
{
M0P_LVD->CR_f.LVDEN = 1u;
}
/**
* \brief
* LVD
*
* \param
*
* \retval
*/
void Lvd_Disable(void)
{
M0P_LVD->CR_f.LVDEN = 0u;
}
/**
* \brief
* LVD中断标志
*
* \param
*
* \retval boolean_t
*/
boolean_t Lvd_GetIrqStat(void)
{
return M0P_LVD->IFR_f.INTF;
}
/**
* \brief
* LVD中断标志
*
* \param
*
* \retval
*/
void Lvd_ClearIrq(void)
{
M0P_LVD->IFR_f.INTF = 0u;
}
/**
* \brief
* Filter结果
*
* \param
*
* \retval boolean_t Fliter结果
*/
boolean_t Lvd_GetFilterResult(void)
{
return (boolean_t)M0P_LVD->IFR_f.FILTER;
}
//@} // LvdGroup
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,438 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file opa.c
**
** opa driver API.
** @link opa Group Some description @endlink
**
** - 2018-04-15 Devi First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "opa.h"
/**
******************************************************************************
** \addtogroup OPAGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_pagagain(x) ( (x) <= 7 )
#define IS_VALID_channel(x) ( (OPA0 == (x)) ||\
(OPA1 == (x)) ||\
(OPA2 == (x)) )
#define IS_VALID_Mode(x) ( (OpaUintMode == (x)) ||\
(OpaForWardMode == (x)) ||\
(OpaOppositeMode == (x)) ||\
(OpaThreeOppMode == (x)) ||\
(OpaThreeForMode == (x)) ||\
(OpaDiffMode == (x)) ||\
(OpaMeterMode == (x)) ||\
(OpaGpMode == (x)) )
#define IS_VALID_metergain(x) ( (OpaMeterGain3 == (x)) ||\
(OpaMeterGain1_3 == (x)) ||\
(OpaMeterGain1 == (x)) )
#define IS_VALID_calsel(x) ( (OpaSoftMode == (x)) ||\
(OpaSoftTriggerMode == (x)) ||\
(OpaADCTriggerMode == (x)) )
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
*****************************************************************************/
/**
* \brief
* OPA
*
* \param
* \param
*
* \retval
* \retval
*/
en_result_t OPA_Init(void)
{
uint16_t i;
M0P_SYSCTRL->PERI_CLKEN_f.ADC = 1;
M0P_BGR->CR_f.BGR_EN = 1;
for(i=0;i<2000;i++)
{
;
}
M0P_OPA->CR0 = 0x120;
M0P_OPA->CR1 = 0x120;
M0P_OPA->CR2 = 0x120;
M0P_OPA->CR = 0x00;
return Ok;
}
/**
* \brief
* OPA
*
* \param
* \param
*
* \retval
* \retval
*/
en_result_t OPA_DeInit(void)
{
M0P_OPA->CR0 = 0x120;
M0P_OPA->CR1 = 0x120;
M0P_OPA->CR2 = 0x120;
M0P_OPA->CR = 0x00;
M0P_BGR->CR_f.BGR_EN = 0;
M0P_SYSCTRL->PERI_CLKEN_f.ADC = 0;
return Ok;
}
/**
* \brief
* OPA
*
* \param [in] en_opa_channel_t 使OPA
* \param [in] en_opa_modesel_t OPA模式选择
* \param [in] stc_opa_gain_config_t OPA增益选择
*
* \retval
*/
en_result_t OPA_Operate(en_opa_channel_t enchannel ,en_opa_modesel_t enMode,stc_opa_gain_config_t *pstrGain)
{
stc_opa_cr0_field_t *stcOpacr;
ASSERT( IS_VALID_Mode(enMode) );
ASSERT( IS_VALID_channel(enchannel) );
if (OPA0 == enchannel)
{
stcOpacr = (stc_opa_cr0_field_t*)&M0P_OPA->CR0_f;
}
if (OPA1 == enchannel)
{
stcOpacr = (stc_opa_cr0_field_t*)&M0P_OPA->CR1_f;
}
if (OPA2 == enchannel)
{
stcOpacr = (stc_opa_cr0_field_t*)&M0P_OPA->CR2_f;
}
if(enMode == OpaUintMode)
{
stcOpacr->NEGSEL = 0;
stcOpacr->POSSEL = 3;
stcOpacr->UBUFSEL = 1;
stcOpacr->POEN = 1;
}
else if(enMode == OpaForWardMode)
{
stcOpacr->NEGSEL = 1;
stcOpacr->POEN = 1;
stcOpacr->PGAGAIN = pstrGain->enNoInGain;
stcOpacr->POSSEL = 3;
stcOpacr->RESINMUX = 0;
stcOpacr->RESSEL = 1;
}
else if(enMode == OpaOppositeMode)
{
stcOpacr->NEGSEL = 1;
stcOpacr->POEN = 1;
stcOpacr->PGAGAIN = pstrGain->enInGain;
stcOpacr->POSSEL = 3;
stcOpacr->RESINMUX = 2;
stcOpacr->RESSEL = 1;
}
else if(enMode == OpaDiffMode)
{
M0P_OPA->CR0_f.POSSEL = 3;
M0P_OPA->CR1_f.POSSEL = 3;
M0P_OPA->CR2_f.POSSEL = 0;
M0P_OPA->CR0_f.NEGSEL = 0;
M0P_OPA->CR1_f.NEGSEL = 1;
M0P_OPA->CR2_f.NEGSEL = 1;
M0P_OPA->CR0_f.RESINMUX = 0;
M0P_OPA->CR1_f.RESINMUX = 1;
M0P_OPA->CR2_f.RESINMUX = 0;
M0P_OPA->CR0_f.UBUFSEL = 1;
M0P_OPA->CR1_f.UBUFSEL = 0;
M0P_OPA->CR2_f.UBUFSEL = 0;
M0P_OPA->CR0_f.RESSEL = 0;
M0P_OPA->CR1_f.RESSEL = 1;
M0P_OPA->CR2_f.RESSEL = 0;
M0P_OPA->CR0_f.POEN = 0;
M0P_OPA->CR1_f.POEN = 1;
M0P_OPA->CR2_f.POEN = 0;
M0P_OPA->CR0_f.PGAGAIN = 0;
M0P_OPA->CR1_f.PGAGAIN = pstrGain->enNoInGain;
M0P_OPA->CR2_f.PGAGAIN = 0;
}
else if(enMode == OpaGpMode)
{
stcOpacr->BIASSEL = 1;
stcOpacr->MODE = 1;
stcOpacr->NEGSEL = 3;
stcOpacr->POEN = 0;
stcOpacr->PGAGAIN = 5;
stcOpacr->POSSEL = 3;
stcOpacr->RESINMUX = 0;
stcOpacr->RESSEL = 0;
stcOpacr->UBUFSEL = 0;
}
else
{
return ErrorInvalidParameter;
}
M0P_OPA->CR0_f.EN = 1;
M0P_OPA->CR1_f.EN = 1;
M0P_OPA->CR2_f.EN = 1;
return Ok;
}
/**
* \brief
* OPA ()
* \param [in] en_opa_modesel_t OPA模式选择
* \param [in] stc_opa_gain_config_t OPA增益选择
*
* \retval
*/
en_result_t OPA_ThreeOperate(en_opa_modesel_t enMode,stc_opa_gain_config_t *pstrGain0,stc_opa_gain_config_t *pstrGain1,stc_opa_gain_config_t *pstrGain2)
{
ASSERT( IS_VALID_Mode(enMode) );
if(enMode == OpaThreeOppMode)
{
M0P_OPA->CR0_f.POSSEL = 3;
M0P_OPA->CR1_f.POSSEL = 3;
M0P_OPA->CR2_f.POSSEL = 3;
M0P_OPA->CR0_f.NEGSEL = 1;
M0P_OPA->CR1_f.NEGSEL = 1;
M0P_OPA->CR2_f.NEGSEL = 1;
M0P_OPA->CR0_f.RESINMUX = 2;
M0P_OPA->CR1_f.RESINMUX = 1;
M0P_OPA->CR2_f.RESINMUX = 1;
M0P_OPA->CR0_f.RESSEL = 1;
M0P_OPA->CR1_f.RESSEL = 1;
M0P_OPA->CR2_f.RESSEL = 1;
M0P_OPA->CR0_f.POEN = 0;
M0P_OPA->CR1_f.POEN = 0;
M0P_OPA->CR2_f.POEN = 1;
M0P_OPA->CR0_f.PGAGAIN = pstrGain0->enInGain;
M0P_OPA->CR1_f.PGAGAIN = pstrGain1->enInGain;
M0P_OPA->CR2_f.PGAGAIN = pstrGain2->enInGain;
}
else if(enMode == OpaThreeForMode)
{
M0P_OPA->CR0_f.POSSEL = 3;
M0P_OPA->CR1_f.POSSEL = 2;
M0P_OPA->CR2_f.POSSEL = 2;
M0P_OPA->CR0_f.NEGSEL = 1;
M0P_OPA->CR1_f.NEGSEL = 1;
M0P_OPA->CR2_f.NEGSEL = 1;
M0P_OPA->CR0_f.RESINMUX = 0;
M0P_OPA->CR1_f.RESINMUX = 0;
M0P_OPA->CR2_f.RESINMUX = 0;
M0P_OPA->CR0_f.UBUFSEL = 0;
M0P_OPA->CR1_f.UBUFSEL = 0;
M0P_OPA->CR2_f.UBUFSEL = 0;
M0P_OPA->CR0_f.RESSEL = 1;
M0P_OPA->CR1_f.RESSEL = 1;
M0P_OPA->CR2_f.RESSEL = 1;
M0P_OPA->CR0_f.POEN = 0;
M0P_OPA->CR1_f.POEN = 0;
M0P_OPA->CR2_f.POEN = 1;
M0P_OPA->CR0_f.PGAGAIN = pstrGain0->enNoInGain;
M0P_OPA->CR1_f.PGAGAIN = pstrGain1->enNoInGain;
M0P_OPA->CR2_f.PGAGAIN = pstrGain2->enNoInGain;
}
else
{
return ErrorInvalidParameter;
}
M0P_OPA->CR0_f.EN = 1;
M0P_OPA->CR1_f.EN = 1;
M0P_OPA->CR2_f.EN = 1;
return Ok;
}
/**
* \brief
* OPA
* \param [in] en_opa_metergain_t OPA增益选择
*
* \retval
*/
en_result_t OPA_MeterOperate(en_opa_metergain_t enGainMode)
{
ASSERT( IS_VALID_metergain(enGainMode) );
M0P_OPA->CR0_f.POSSEL = 3;
M0P_OPA->CR1_f.POSSEL = 3;
M0P_OPA->CR2_f.POSSEL = 1;
M0P_OPA->CR0_f.NEGSEL = 0;
M0P_OPA->CR1_f.NEGSEL = 0;
M0P_OPA->CR2_f.NEGSEL = 1;
M0P_OPA->CR0_f.RESINMUX = 0;
M0P_OPA->CR1_f.RESINMUX = 0;
M0P_OPA->CR2_f.RESINMUX = 1;
M0P_OPA->CR0_f.UBUFSEL = 1;
M0P_OPA->CR1_f.UBUFSEL = 1;
M0P_OPA->CR2_f.UBUFSEL = 0;
M0P_OPA->CR0_f.RESSEL = 1;
M0P_OPA->CR1_f.RESSEL = 0;
M0P_OPA->CR2_f.RESSEL = 1;
M0P_OPA->CR0_f.POEN = 0;
M0P_OPA->CR1_f.POEN = 0;
M0P_OPA->CR2_f.POEN = 1;
if(enGainMode == OpaMeterGain3)
{
M0P_OPA->CR0_f.PGAGAIN = 6;
M0P_OPA->CR2_f.PGAGAIN = 3;
}
if(enGainMode == OpaMeterGain1_3)
{
M0P_OPA->CR0_f.PGAGAIN = 3;
M0P_OPA->CR2_f.PGAGAIN = 6;
}
if(enGainMode == OpaMeterGain1)
{
M0P_OPA->CR0_f.PGAGAIN = 5;
M0P_OPA->CR2_f.PGAGAIN = 5;
}
M0P_OPA->CR0_f.EN = 1;
M0P_OPA->CR1_f.EN = 1;
M0P_OPA->CR2_f.EN = 1;
return Ok;
}
/**
* \brief
* OPA
* \param [in] en_opa_calsel_t OPA校正模式选择
*
* \retval
*/
en_result_t OPA_Cal(en_opa_calsel_t enCalMode)
{
ASSERT( IS_VALID_calsel(enCalMode) );
if(enCalMode == OpaSoftMode)
{
}
if(enCalMode == OpaSoftTriggerMode)
{
}
if (enCalMode == OpaADCTriggerMode)
{
}
M0P_OPA->CR0_f.EN = 1;
M0P_OPA->CR1_f.EN = 1;
M0P_OPA->CR2_f.EN = 1;
return Ok;
}
//@} // OPAGroup
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,834 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file pca.c
**
** Common API of PCA.
** @link pcaGroup Some description @endlink
**
** - 2018-04-16 Husj First version
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "pca.h"
/**
*******************************************************************************
** \addtogroup PcaGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_MODULE(x) (Module0 == (x) ||\
Module1 == (x) ||\
Module2 == (x) ||\
Module3 == (x) ||\
Module4 == (x))
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
static func_ptr_t pfnPcaCallback = NULL;
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief PCA中断标志获取
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Pca_GetIntFlag(en_pca_module_t enModule)
{
boolean_t bRetVal = FALSE;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
bRetVal = M0P_PCA->CCON_f.CCF0 ? TRUE : FALSE;
break;
case Module1:
bRetVal = M0P_PCA->CCON_f.CCF1 ? TRUE : FALSE;
break;
case Module2:
bRetVal = M0P_PCA->CCON_f.CCF2 ? TRUE : FALSE;
break;
case Module3:
bRetVal = M0P_PCA->CCON_f.CCF3 ? TRUE : FALSE;
break;
case Module4:
bRetVal = M0P_PCA->CCON_f.CCF4 ? TRUE : FALSE;
break;
default:
bRetVal = FALSE;
break;
}
return bRetVal;
}
/**
*****************************************************************************
** \brief PCA计数中断标志获取
**
**
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Pca_GetCntIntFlag(void)
{
boolean_t bRetVal = FALSE;
bRetVal = M0P_PCA->CCON_f.CF ? TRUE : FALSE;
return bRetVal;
}
/**
*****************************************************************************
** \brief PCA中断标志清除
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_ClearIntFlag(en_pca_module_t enModule)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
M0P_PCA->ICLR_f.CCF0 = FALSE;
enResult = Ok;
break;
case Module1:
M0P_PCA->ICLR_f.CCF1 = FALSE;
enResult = Ok;
break;
case Module2:
M0P_PCA->ICLR_f.CCF2 = FALSE;
enResult = Ok;
break;
case Module3:
M0P_PCA->ICLR_f.CCF3 = FALSE;
enResult = Ok;
break;
case Module4:
M0P_PCA->ICLR_f.CCF4 = FALSE;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA计数中断标志清除
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_ClearCntIntFlag(void)
{
en_result_t enResult = Error;
M0P_PCA->ICLR_f.CF = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA中断服务程序
**
**
** \param [in] u8Param == 0
**
*****************************************************************************/
void Pca_IRQHandler(uint8_t u8Param)
{
if(NULL != pfnPcaCallback)
{
pfnPcaCallback();
}
}
/**
*****************************************************************************
** \brief PCA中断使能
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_EnableIrq(en_pca_module_t enModule)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
M0P_PCA->CCAPM0_f.CCIE = TRUE;
enResult = Ok;
break;
case Module1:
M0P_PCA->CCAPM1_f.CCIE = TRUE;
enResult = Ok;
break;
case Module2:
M0P_PCA->CCAPM2_f.CCIE = TRUE;
enResult = Ok;
break;
case Module3:
M0P_PCA->CCAPM3_f.CCIE = TRUE;
enResult = Ok;
break;
case Module4:
M0P_PCA->CCAPM4_f.CCIE = TRUE;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA计数中断使能
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_EnableCntIrq (void)
{
en_result_t enResult = Error;
M0P_PCA->CMOD_f.CFIE = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA中断禁止
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_DisableIrq(en_pca_module_t enModule)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
M0P_PCA->CCAPM0_f.CCIE = FALSE;
enResult = Ok;
break;
case Module1:
M0P_PCA->CCAPM1_f.CCIE = FALSE;
enResult = Ok;
break;
case Module2:
M0P_PCA->CCAPM2_f.CCIE = FALSE;
enResult = Ok;
break;
case Module3:
M0P_PCA->CCAPM3_f.CCIE = FALSE;
enResult = Ok;
break;
case Module4:
M0P_PCA->CCAPM4_f.CCIE = FALSE;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA计数中断禁止
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_DisableCntIrq(void)
{
en_result_t enResult = Error;
M0P_PCA->CMOD_f.CFIE = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA初始化配置
**
**
** \param [in] pstcConfig PCA模块配置结构体指针
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_Init(stc_pca_config_t* pstcConfig)
{
en_result_t enResult = Error;
M0P_PCA->CMOD_f.CIDL = pstcConfig->enCIDL;
M0P_PCA->CMOD_f.WDTE = pstcConfig->enWDTE;
M0P_PCA->CMOD_f.CPS = pstcConfig->enCPS;
pfnPcaCallback = pstcConfig->pfnPcaCb;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA模式配置
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
** \param [in] pstcCapMod PCA模式配置结构体指针
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_CapModConfig(en_pca_module_t enModule, stc_pca_capmodconfig_t* pstcCapMod)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
{
M0P_PCA->CCAPM0_f.ECOM = pstcCapMod->enECOM;
M0P_PCA->CCAPM0_f.CAPP = pstcCapMod->enCAPP;
M0P_PCA->CCAPM0_f.CAPN = pstcCapMod->enCAPN;
M0P_PCA->CCAPM0_f.MAT = pstcCapMod->enMAT;
M0P_PCA->CCAPM0_f.TOG = pstcCapMod->enTOG;
M0P_PCA->CCAPM0_f.PWM = pstcCapMod->en8bitPWM;
enResult = Ok;
}
break;
case Module1:
{
M0P_PCA->CCAPM1_f.ECOM = pstcCapMod->enECOM;
M0P_PCA->CCAPM1_f.CAPP = pstcCapMod->enCAPP;
M0P_PCA->CCAPM1_f.CAPN = pstcCapMod->enCAPN;
M0P_PCA->CCAPM1_f.MAT = pstcCapMod->enMAT;
M0P_PCA->CCAPM1_f.TOG = pstcCapMod->enTOG;
M0P_PCA->CCAPM1_f.PWM = pstcCapMod->en8bitPWM;
enResult = Ok;
}
break;
case Module2:
{
M0P_PCA->CCAPM2_f.ECOM = pstcCapMod->enECOM;
M0P_PCA->CCAPM2_f.CAPP = pstcCapMod->enCAPP;
M0P_PCA->CCAPM2_f.CAPN = pstcCapMod->enCAPN;
M0P_PCA->CCAPM2_f.MAT = pstcCapMod->enMAT;
M0P_PCA->CCAPM2_f.TOG = pstcCapMod->enTOG;
M0P_PCA->CCAPM2_f.PWM = pstcCapMod->en8bitPWM;
enResult = Ok;
}
break;
case Module3:
{
M0P_PCA->CCAPM3_f.ECOM = pstcCapMod->enECOM;
M0P_PCA->CCAPM3_f.CAPP = pstcCapMod->enCAPP;
M0P_PCA->CCAPM3_f.CAPN = pstcCapMod->enCAPN;
M0P_PCA->CCAPM3_f.MAT = pstcCapMod->enMAT;
M0P_PCA->CCAPM3_f.TOG = pstcCapMod->enTOG;
M0P_PCA->CCAPM3_f.PWM = pstcCapMod->en8bitPWM;
enResult = Ok;
}
break;
case Module4:
{
M0P_PCA->CCAPM4_f.ECOM = pstcCapMod->enECOM;
M0P_PCA->CCAPM4_f.CAPP = pstcCapMod->enCAPP;
M0P_PCA->CCAPM4_f.CAPN = pstcCapMod->enCAPN;
M0P_PCA->CCAPM4_f.MAT = pstcCapMod->enMAT;
M0P_PCA->CCAPM4_f.TOG = pstcCapMod->enTOG;
M0P_PCA->CCAPM4_f.PWM = pstcCapMod->en8bitPWM;
enResult = Ok;
}
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA启动运行
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_Run(void)
{
en_result_t enResult = Error;
M0P_PCA->CCON_f.CR = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA停止运行
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_Stop(void)
{
en_result_t enResult = Error;
M0P_PCA->CCON_f.CR = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA16位比较数据设置
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
** \param [in] u16Data PCA捕获数据
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_CmpData16Set(en_pca_module_t enModule, uint16_t u16Data)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
M0P_PCA->CCAP0_f.CCAP0 = u16Data;
enResult = Ok;
break;
case Module1:
M0P_PCA->CCAP1_f.CCAP1 = u16Data;
enResult = Ok;
break;
case Module2:
M0P_PCA->CCAP2_f.CCAP2 = u16Data;
enResult = Ok;
break;
case Module3:
M0P_PCA->CCAP3_f.CCAP3 = u16Data;
enResult = Ok;
break;
case Module4:
M0P_PCA->CCAP4_f.CCAP4 = u16Data;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA16位捕获数据获取
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
**
** \retval u16Data
*****************************************************************************/
uint16_t Pca_CapData16Get(en_pca_module_t enModule)
{
uint16_t u16Data = 0;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
u16Data = M0P_PCA->CCAP0_f.CCAP0;
break;
case Module1:
u16Data = M0P_PCA->CCAP1_f.CCAP1;
break;
case Module2:
u16Data = M0P_PCA->CCAP2_f.CCAP2;
break;
case Module3:
u16Data = M0P_PCA->CCAP3_f.CCAP3;
break;
case Module4:
u16Data = M0P_PCA->CCAP4_f.CCAP4;
break;
default:
u16Data = 0;
break;
}
return u16Data;
}
/**
*****************************************************************************
** \brief PCA高8位比较数据设置
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
** \param [in] u8Data PCA高8位捕获数据
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_CmpDataHSet(en_pca_module_t enModule, uint8_t u8Data)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
M0P_PCA->CCAP0H_f.CCAP0 = u8Data;
enResult = Ok;
break;
case Module1:
M0P_PCA->CCAP1H_f.CCAP1 = u8Data;
enResult = Ok;
break;
case Module2:
M0P_PCA->CCAP2H_f.CCAP2 = u8Data;
enResult = Ok;
break;
case Module3:
M0P_PCA->CCAP3H_f.CCAP3 = u8Data;
enResult = Ok;
break;
case Module4:
M0P_PCA->CCAP4H_f.CCAP4 = u8Data;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA低8位比较数据设置
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
** \param [in] u8Data PCA低8位捕获数据
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_CmpDataLSet(en_pca_module_t enModule, uint8_t u8Data)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
M0P_PCA->CCAP0L_f.CCAP0 = u8Data;
enResult = Ok;
break;
case Module1:
M0P_PCA->CCAP1L_f.CCAP1 = u8Data;
enResult = Ok;
break;
case Module2:
M0P_PCA->CCAP2L_f.CCAP2 = u8Data;
enResult = Ok;
break;
case Module3:
M0P_PCA->CCAP3L_f.CCAP3 = u8Data;
enResult = Ok;
break;
case Module4:
M0P_PCA->CCAP4L_f.CCAP4 = u8Data;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief PCA计数器初值设置
**
**
**
** \param [in] u16Data PCA计数器初值
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_Cnt16Set(uint16_t u16Data)
{
en_result_t enResult = Error;
M0P_PCA->CNT_f.CNT = u16Data;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA16位计数器值获取
**
**
**
** \retval 16
*****************************************************************************/
uint16_t Pca_Cnt16Get(void)
{
uint16_t u16CntData = 0;
u16CntData = M0P_PCA->CNT_f.CNT;
return u16CntData;
}
/**
*****************************************************************************
** \brief PCA周期重载值设置
**
**
**
** \param [in] u16Data PCA周期重载值
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_CARRSet(uint16_t u16Data)
{
en_result_t enResult = Error;
M0P_PCA->CARR_f.CARR = u16Data;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA周期重载值获取
**
**
**
** \retval PCA周期重载值
*****************************************************************************/
uint16_t Pca_CARRGet(void)
{
uint16_t u16CntData = 0;
u16CntData = M0P_PCA->CARR_f.CARR;
return u16CntData;
}
/**
*****************************************************************************
** \brief PCA增强PWM 使
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_Enable16bitPWM(void)
{
en_result_t enResult = Error;
M0P_PCA->EPWM_f.EPWM = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA增强PWM
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Pca_Disable16bitPWM(void)
{
en_result_t enResult = Error;
M0P_PCA->EPWM_f.EPWM = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief PCA比较高速输出标志获取
**
**
** \param [in] enModule PCA模块选择Module0Module1Module2Module3Module4
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Pca_GetCmpHighFlag(en_pca_module_t enModule)
{
boolean_t bRetVal = FALSE;
ASSERT(IS_VALID_MODULE(enModule));
switch (enModule)
{
case Module0:
bRetVal = M0P_PCA->CCAPO_f.CCAPO0 ? TRUE : FALSE;
break;
case Module1:
bRetVal = M0P_PCA->CCAPO_f.CCAPO1 ? TRUE : FALSE;
break;
case Module2:
bRetVal = M0P_PCA->CCAPO_f.CCAPO2 ? TRUE : FALSE;
break;
case Module3:
bRetVal = M0P_PCA->CCAPO_f.CCAPO3 ? TRUE : FALSE;
break;
case Module4:
bRetVal = M0P_PCA->CCAPO_f.CCAPO4 ? TRUE : FALSE;
break;
default:
bRetVal = FALSE;
break;
}
return bRetVal;
}
//@} // PcaGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,417 @@
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file pcnt.c
**
** pcnt driver API.
** @link pcnt Group Some description @endlink
**
** - 2018-04-15 Devi First Version
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "pcnt.h"
/**
******************************************************************************
** \addtogroup PCNTGroup
******************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define IS_VALID_pagagain(x) ( (x) <= 7 )
#define IS_VALID_channel(x) ( (OPA0 == (x)) ||\
(OPA1 == (x)) ||\
(OPA2 == (x)) )
#define IS_VALID_STAT(x) ( (PCNT_S1E == (x)) ||\
(PCNT_S0E == (x)) ||\
(PCNT_BB == (x)) ||\
(PCNT_FE == (x)) ||\
(PCNT_DIR == (x)) ||\
(PCNT_TO == (x)) ||\
(PCNT_OV == (x)) ||\
(PCNT_UF == (x)) )
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
static func_ptr_t pfnPcntCallback = NULL; ///< callback function pointer for PCNT Irq
/******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
*****************************************************************************/
void Pcnt_IRQHandler(void)
{
if(NULL != pfnPcntCallback)
{
pfnPcntCallback();
}
}
/**
* \brief
* PCNT
*
* \param
* \param
*
* \retval
* \retval
*/
en_result_t PCNT_Init(stc_pcnt_config_t* pstcPcntConfig)
{
M0P_SYSCTRL->PERI_CLKEN_f.PCNT = 1;
M0P_PCNT->CR_f.S1P = pstcPcntConfig->bS1Sel;
M0P_PCNT->CR_f.S0P = pstcPcntConfig->bS0Sel;
M0P_PCNT->CR_f.DIR = pstcPcntConfig->u8Direc; //计数方式
M0P_PCNT->CR_f.CLKSEL = pstcPcntConfig->u8Clk;
M0P_PCNT->CR_f.MODE = pstcPcntConfig->u8Mode;
M0P_PCNT->FLT_f.CLKDIV = pstcPcntConfig->u8FLTClk;
if(pstcPcntConfig->bFLTEn)
{
if(pstcPcntConfig->u8FLTDep == 0)
{
M0P_PCNT->FLT_f.DEBTOP = 2;
}
else
{
M0P_PCNT->FLT_f.DEBTOP = pstcPcntConfig->u8FLTDep;
}
}
M0P_PCNT->FLT_f.EN = pstcPcntConfig->bFLTEn;
M0P_PCNT->TOCR_f.TH = pstcPcntConfig->u16TODep;
M0P_PCNT->TOCR_f.EN = pstcPcntConfig->bTOEn;
if (TRUE == pstcPcntConfig->bIrqEn)
{
M0P_PCNT->IEN = pstcPcntConfig->u8IrqStatus;
EnableNvic(PCNT_IRQn,IrqLevel3,TRUE);
}
else
{
M0P_PCNT->IEN = 0x00;
EnableNvic(PCNT_IRQn,IrqLevel3,FALSE);
}
if(NULL != pstcPcntConfig->pfnIrqCb)
{
pfnPcntCallback = pstcPcntConfig->pfnIrqCb;
}
return Ok;
}
/**
* \brief
* PCNT
*
* \param
* \param
*
* \retval
* \retval
*/
void PCNT_DeInit(void)
{
M0P_PCNT->CR = 0;
M0P_PCNT->RUN = 0;
M0P_SYSCTRL->PERI_CLKEN_f.PCNT = 0;
}
/**
* \brief
* PCNT
*
* \param [in] start
* \param [in] end
*
* \retval
*/
en_result_t PCNT_Parameter(uint8_t start,uint8_t end)
{
uint32_t u32TimeOut;
u32TimeOut = 1000;
M0P_PCNT->BUF = end; //加载结束溢出值
M0P_PCNT->CMD_f.B2T = 1;
while(u32TimeOut--)
{
if(FALSE == M0P_PCNT->SR2_f.B2T)
{
break;
}
}
if(u32TimeOut == 0)
{
return ErrorTimeout;
}
u32TimeOut = 1000;
M0P_PCNT->BUF = start; //加载初始值
M0P_PCNT->CMD_f.B2C = 1;
while(u32TimeOut--)
{
if(FALSE == M0P_PCNT->SR2_f.B2C)
{
break;
}
}
if(u32TimeOut == 0)
{
return ErrorTimeout;
}
return Ok;
}
/**
* \brief
* PCNT计数方向
* \param [in]
*
* \retval
*/
en_pcnt_direcsel_t PCNT_Direction(void)
{
return (en_pcnt_direcsel_t)M0P_PCNT->SR1_f.DIR;
}
/**
* \brief
* PCNT计数值
* \param [in]
*
* \retval
*/
uint16_t PCNT_Count(void)
{
return M0P_PCNT->CNT;
}
/**
* \brief
* PCNT溢出值
* \param [in]
*
* \retval
*/
uint16_t PCNT_TopCount(void)
{
return M0P_PCNT->TOP;
}
/**
* \brief
* PCNT使能
* \param [in]
*
* \retval
*/
void PCNT_Run(boolean_t work)
{
M0P_PCNT->RUN_f.RUN = work;
}
/**
* \brief
* PCNT
* \param [in] en_pcnt_status_t PCNT状态
*
* \retval
*/
boolean_t PCNT_GetStatus(en_pcnt_status_t enStatus)
{
boolean_t bFlag = FALSE;
ASSERT(IS_VALID_STAT(enStatus));
switch (enStatus)
{
case PCNT_S1E:
bFlag = M0P_PCNT->IFR_f.S1E;
break;
case PCNT_S0E:
bFlag = M0P_PCNT->IFR_f.S0E;
break;
case PCNT_BB:
bFlag = M0P_PCNT->IFR_f.BB;
break;
case PCNT_FE:
bFlag = M0P_PCNT->IFR_f.FE;
break;
case PCNT_DIR:
bFlag = M0P_PCNT->IFR_f.DIR;
break;
case PCNT_TO:
bFlag = M0P_PCNT->IFR_f.TO;
break;
case PCNT_OV:
bFlag = M0P_PCNT->IFR_f.OV;
break;
case PCNT_UF:
bFlag = M0P_PCNT->IFR_f.UF;
break;
default:
break;
}
return bFlag;
}
/**
* \brief
* PCNT
* \param [in] en_pcnt_status_t PCNT状态
*
* \retval
*/
void PCNT_ClrStatus(en_pcnt_status_t enStatus)
{
ASSERT(IS_VALID_STAT(enStatus));
switch (enStatus)
{
case PCNT_S1E:
M0P_PCNT->ICR_f.S1E = 0;
break;
case PCNT_S0E:
M0P_PCNT->ICR_f.S0E = 0;
break;
case PCNT_BB:
M0P_PCNT->ICR_f.BB = 0;
break;
case PCNT_FE:
M0P_PCNT->ICR_f.FE = 0;
break;
case PCNT_DIR:
M0P_PCNT->ICR_f.DIR = 0;
break;
case PCNT_TO:
M0P_PCNT->ICR_f.TO = 0;
break;
case PCNT_OV:
M0P_PCNT->ICR_f.OV = 0;
break;
case PCNT_UF:
M0P_PCNT->ICR_f.UF = 0;
break;
default:
break;
}
}
/**
* \brief
* PCNT
* \param [in] en_pcnt_status_t PCNT状态
*
* \retval
*/
void PCNT_SetIrqStatus(en_pcnt_status_t enStatus)
{
ASSERT(IS_VALID_STAT(enStatus));
switch (enStatus)
{
case PCNT_S1E:
M0P_PCNT->IEN_f.S1E = 1;
break;
case PCNT_S0E:
M0P_PCNT->IEN_f.S0E = 1;
break;
case PCNT_BB:
M0P_PCNT->IEN_f.BB = 1;
break;
case PCNT_FE:
M0P_PCNT->IEN_f.FE = 1;
break;
case PCNT_DIR:
M0P_PCNT->IEN_f.DIR = 1;
break;
case PCNT_TO:
M0P_PCNT->IEN_f.TO = 1;
break;
case PCNT_OV:
M0P_PCNT->IEN_f.OV = 1;
break;
case PCNT_UF:
M0P_PCNT->IEN_f.UF = 1;
break;
default:
break;
}
}
//@} // OPAGroup
/******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,163 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file reset.c
**
** Common API of reset.
** @link resetGroup Some description @endlink
**
** - 2017-05-04
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "reset.h"
/**
*******************************************************************************
** \addtogroup ResetGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief .
**
** \param [out] pstcOut
**
** \retval Ok
**
******************************************************************************/
en_result_t Reset_GetCause(stc_reset_cause_t *pstcOut)
{
uint8_t u8val = 0;
if (NULL == pstcOut)
{
return ErrorInvalidParameter;
}
u8val = M0P_RESET->RESET_FLAG;
*pstcOut = *((stc_reset_cause_t*)&u8val);
return Ok;
}
/**
*******************************************************************************
** \brief .
**
** \param [in] stcval ,01
**
** \retval Ok
**
******************************************************************************/
en_result_t Reset_Clear(stc_reset_cause_t stcval)
{
uint8_t u8val = *((uint8_t*)&stcval);
M0P_RESET->RESET_FLAG = u8val;
return Ok;
}
/**
*******************************************************************************
** \brief .
**
** \param [in] enPeri
** \param [in] bFlag
**
** \retval Ok
**
******************************************************************************/
en_result_t Reset_SetPeripheralReset(en_reset_peripheral_t enPeri, boolean_t bFlag)
{
bFlag = !!bFlag;
if(TRUE == bFlag)
{
M0P_RESET->PREI_RESET |= (uint32_t)enPeri;
}
else
{
M0P_RESET->PREI_RESET &= ~(uint32_t)enPeri;
}
return Ok;
}
//@} // ResetGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,191 @@
/******************************************************************************
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file rng.c
**
** Common API of rng.
** @link flashGroup Some description @endlink
**
** - 2018-05-08
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "rng.h"
/**
*******************************************************************************
** \addtogroup FlashGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief (
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Rng_Init(void)
{
//==>>生成64bits随机数上电第一次
M0P_RNG->CR_f.RNGCIR_EN = 1;
//模式配置0
M0P_RNG->MODE_f.LOAD = 1;
M0P_RNG->MODE_f.FDBK = 1;
M0P_RNG->MODE_f.CNT = 6;
//生成随机数0
M0P_RNG->CR_f.RNG_RUN = 1;
while(M0P_RNG->CR_f.RNG_RUN)
{
;
}
//模式配置1
M0P_RNG->MODE_f.LOAD = 0;
M0P_RNG->MODE_f.FDBK = 0;
M0P_RNG->MODE_f.CNT = 4;
//生成随机数1
M0P_RNG->CR_f.RNG_RUN = 1;
while(M0P_RNG->CR_f.RNG_RUN)
{
;
}
//关闭随机源电路,节省功耗
M0P_RNG->CR_f.RNGCIR_EN = 0;
return Ok;
}
/**
*****************************************************************************
** \brief
**
**
** \retval TRUE or FALSE
*****************************************************************************/
en_result_t Rng_Generate(void)
{
//==>>生成64bits随机数非上电第一次生成
M0P_RNG->CR_f.RNGCIR_EN = 1;
//模式配置0
M0P_RNG->MODE_f.LOAD = 0;
M0P_RNG->MODE_f.FDBK = 1;
M0P_RNG->MODE_f.CNT = 6;
//生成随机数0
M0P_RNG->CR_f.RNG_RUN = 1;
while(M0P_RNG->CR_f.RNG_RUN)
{
;
}
//模式配置1
M0P_RNG->MODE_f.FDBK = 0;
M0P_RNG->MODE_f.CNT = 4;
M0P_RNG->MODE_f.CNT = 4;
//生成随机数1
M0P_RNG->CR_f.RNG_RUN = 1;
while(M0P_RNG->CR_f.RNG_RUN)
{
;
}
//关闭随机源电路,节省功耗
M0P_RNG->CR_f.RNGCIR_EN = 0;
return Ok;
}
/**
*****************************************************************************
** \brief
**
** \retval data0
*****************************************************************************/
uint32_t Rng_GetData0(void)
{
return M0P_RNG->DATA0;
}
/**
*****************************************************************************
** \brief
**
** \retval data1
*****************************************************************************/
uint32_t Rng_GetData1(void)
{
return M0P_RNG->DATA1;
}
//@} // RngGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

View File

@ -0,0 +1,875 @@
/*************************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file rtc.c
**
** RTC function driver API.
** @link SampleGroup Some description @endlink
**
** - 2017-05-17 1.0 CJ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************/
/* Include files */
/******************************************************************************/
#include "rtc.h"
/**
******************************************************************************
** \addtogroup RtcGroup
******************************************************************************/
//@{
/******************************************************************************/
/* Local pre-processor symbols/macros ('#define') */
/******************************************************************************/
#define IS_VALID_CLK(x) (RtcClk32768 == (x)||\
RtcClk32768_1== (x)||\
RtcClk32 == (x)||\
RtcClk32_1 == (x)||\
RtcClkHxt128 == (x)||\
RtcClkHxt256 == (x)||\
RtcClkHxt512 == (x)||\
RtcClkHxt1024 == (x))
#define IS_VALID_CYCSEL(x) (RtcPrads == (x)||\
RtcPradx==(x))
#define IS_VALID_PRDS(x) (Rtc_None == (x)||\
Rtc_05S == (x)||\
Rtc_1S == (x)||\
Rtc_1Min == (x)||\
Rtc_1H == (x)||\
Rtc_1Day == (x)||\
Rtc_1Mon == (x)||\
Rtc_1Mon_1 == (x))
#define IS_VALID_IRQ_SEL(x) (RtcPrdf == (x) ||\
RtcAlmf == (x))
#define IS_VALID_FUNC(x) ((RtcCount==(x))||\
(RtcAlarmEn==(x))||\
(Rtc_ComenEn==(x))||\
(Rtc1HzOutEn==(x)))
#define CkDateTime 0x7F
#define CkDate 0x78
#define CkTime 0x07
//#define DecToBcd(x) ((((x)/10)<<4) + ((x)%10))
//#define BcdToDec(x) ((((x)>>4)*10) + ((x)&0x0F))
#define RTC_TIMEOUT 1000//test 1s
/******************************************************************************/
/* Local function prototypes ('const') */
/******************************************************************************/
const uint8_t Leap_Month_Base[] = {3,6,0,3,5,1,3,6,2,4,0,2};
const uint8_t NonLeap_Month_Base[] = {4,0,0,3,5,1,3,6,2,4,0,2};
const uint8_t Cnst_Month_Tbl[12]={0x31,0x28,0x31,0x30,0x31,0x30,0x31,0x31,0x30,0x31,0x30,0x31};
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
static stc_rtc_intern_cb_t* RtcGetInternDataCb(void);
/******************************************************************************/
/* Local variable prototypes ('static') */
/******************************************************************************/
static stc_rtc_intern_cb_t stcRtcIrqCb = {NULL, NULL};
/**
******************************************************************************
** \brief RTC计数时钟选择
**
** \param [in] enClk时钟源
**
** \retval Ok
**
******************************************************************************/
en_result_t Rtc_SelClk(en_rtc_clk_t enClk)
{
en_result_t enRet = Error;
ASSERT(IS_VALID_CLK(enClk));
M0P_RTC->CR1_f.CKSEL = enClk;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC周期中断方式选择
**
** \param [in] pstccCyc周期中断方式及周期间隔选择
**
** \retval Ok
**
******************************************************************************/
en_result_t Rtc_SetCyc(stc_rtc_cyc_sel_t* pstcCyc)
{
en_result_t enRet = Error;
ASSERT(IS_VALID_CYCSEL(pstcCyc->enCyc_sel));
ASSERT(IS_VALID_PRDS(pstcCyc->enPrds_sel));
M0P_RTC->CR0_f.PRDSEL = pstcCyc->enCyc_sel;
if(pstcCyc->enCyc_sel)
{
M0P_RTC->CR0_f.PRDX = pstcCyc->u8Prdx;
}
else
{
M0P_RTC->CR0_f.PRDS = pstcCyc->enPrds_sel;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC时制选择
**
** \param [in] bmode是12时制or24时制
**
** \retval Ok
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Rtc_SetAmPm(en_rtc_ampm_t enMode)
{
en_result_t enRet = Error;
switch(enMode)
{
case 0:
case 1:
M0P_RTC->CR0_f.AMPM = enMode;
break;
default:
return ErrorInvalidParameter;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC时制获取
**
** \param [in]
**
** \retval
******************************************************************************/
boolean_t Rtc_GetHourMode(void)
{
return(M0P_RTC->CR0_f.AMPM);
}
/**
******************************************************************************
** \brief RTC闹钟中断设置
**
** \param [in] pstcAlarmTime闹钟时间时
**
** \retval Ok
**
******************************************************************************/
en_result_t Rtc_SetAlarmTime(stc_rtc_alarmset_t* pstcAlarmTime)
{
en_result_t enRet = Ok;
ASSERT(NULL != pstcAlarmTime);
if(Rtc12h == M0P_RTC->CR0_f.AMPM)
{
enRet = Check_BCD_Format(pstcAlarmTime->u8Hour,0x00,0x12);
}
else
{
enRet = Check_BCD_Format(pstcAlarmTime->u8Hour,0x00,0x24);
}
if(enRet != Ok)
{
return enRet;
}
enRet = Check_BCD_Format(pstcAlarmTime->u8Minute,0x00,0x59);
if(enRet != Ok)
{
return enRet;
}
// enRet = Check_BCD_Format(pstcAlarmTime->u8Week,0x00,0x06);
if(enRet != Ok)
{
return enRet;
}
M0P_RTC->ALMHOUR = pstcAlarmTime->u8Hour;
M0P_RTC->ALMMIN = pstcAlarmTime->u8Minute;
M0P_RTC->ALMWEEK = pstcAlarmTime->u8Week;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC闹钟中断时间获取
**
** \param [in] pstcAlarmTime闹钟时间时
**
** \retval Ok
**
******************************************************************************/
en_result_t Rtc_GetAlarmTime(stc_rtc_alarmset_t* pstcAlarmTime)
{
en_result_t enRet = Error;
ASSERT(NULL != pstcAlarmTime);
pstcAlarmTime->u8Minute = M0P_RTC->ALMMIN;
pstcAlarmTime->u8Hour = M0P_RTC->ALMHOUR;
pstcAlarmTime->u8Week = M0P_RTC->ALMWEEK;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC 1hz模式选择
**
** \param [in] bmode
**
** \retval Ok
**
******************************************************************************/
en_result_t Rtc_Set1HzMode(boolean_t bMode)
{
en_result_t enRet = Error;
M0P_RTC->CR0_f.HZ1SEL = bMode;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC 1hz补偿值设置
**
** \param [in] u16Cr
**
** \retval Ok
**
******************************************************************************/
en_result_t Rtc_SetCompCr(uint16_t u16Cr)
{
en_result_t enRet = Error;
M0P_RTC->COMPEN_f.CR = u16Cr;
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC 使
**
** \param [in] enFunc
**
** \retval Ok
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Rtc_EnableFunc(en_rtc_func_t enFunc)
{
ASSERT(IS_VALID_FUNC(enFunc));
switch(enFunc)
{
case RtcCount:
M0P_RTC->CR0_f.START = 1u;
break;
case RtcAlarmEn:
M0P_RTC->CR1_f.ALMEN = 1u;
break;
case Rtc_ComenEn:
M0P_RTC->COMPEN_f.EN = 1u;
break;
case Rtc1HzOutEn:
M0P_RTC->CR0_f.HZ1OE = 1u;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief RTC
**
** \param [in] enFunc
**
** \retval Ok
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Rtc_DisableFunc(en_rtc_func_t enFunc)
{
ASSERT(IS_VALID_FUNC(enFunc));
switch(enFunc)
{
case RtcCount:
M0P_RTC->CR0_f.START = 0u;
break;
case RtcAlarmEn:
M0P_RTC->CR1_f.ALMEN = 0u;
break;
case Rtc_ComenEn:
M0P_RTC->COMPEN_f.EN = 0u;
break;
case Rtc1HzOutEn:
M0P_RTC->CR0_f.HZ1OE = 0u;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
uint8_t Change_DateTimeFormat(uint8_t u8sr)
{
uint8_t u8de=0;
while(u8sr>=0x10)
{
u8de +=10;
u8sr -=0x10;
}
u8de += u8sr;
return(u8de);
}
/**
******************************************************************************
** \brief RTC
**
** \param [in] u8year
**
** \retval 1
** \retval 0
******************************************************************************/
uint8_t Rtc_CheckLeapYear(uint8_t u8year)
{
uint8_t u8year_shl,u8year_shr;
u8year_shl = u8year>>2;
u8year_shr = u8year_shl<<2;
if(u8year== u8year_shr)
{
return 1;
}
else
{
return 0;
}
}
/**
******************************************************************************
** \brief RTC根据日期计算周数
**
** \param [in] pu8Date日期
**
** \retval week
**
******************************************************************************/
uint8_t Rtc_CalWeek(uint8_t* pu8Date)
{
uint8_t u8week;
if((Rtc_CheckLeapYear(Change_DateTimeFormat(*(pu8Date+2)))==1))
{
u8week = (Change_DateTimeFormat(*(pu8Date+2))+Change_DateTimeFormat(*(pu8Date+2))/4+Leap_Month_Base[Change_DateTimeFormat(*(pu8Date+1))-1]+Change_DateTimeFormat(*(pu8Date))+2)%7;
}
else
{
u8week = (Change_DateTimeFormat(*(pu8Date+2))+Change_DateTimeFormat(*(pu8Date+2))/4+NonLeap_Month_Base[Change_DateTimeFormat(*(pu8Date+1))-1]+Change_DateTimeFormat(*(pu8Date))+2)%7;
}
return u8week;
}
/**
******************************************************************************
** \brief RTC根据年月获取天数
**
** \param [in] u8month月份u8year年份
**
** \retval u8day天数
**
******************************************************************************/
uint8_t Get_Month_Max_Day(uint8_t u8month, uint8_t u8year)
{
uint8_t u8day = 0;
u8day = Cnst_Month_Tbl[u8month - 1];
if((u8month == 2) && ((u8year % 4) == 0))
{
u8day++;
}
return(u8day);//day的格式是bcd码例如日为31天day=0x31
}
/**
******************************************************************************
** \brief RTC根据日期计算周数
**
** \param [in] pu8buf日期时间数据u8len检查数据长度u8limit_min最小值u8limit_max最大值
**
** \retval Error Ok校验正确
**
******************************************************************************/
en_result_t Check_BCD_Format(uint8_t u8data,uint8_t u8limit_min, uint8_t u8limit_max)
{
if (((u8data & 0x0F) > 0x09) || ((u8data & 0xF0) > 0x90)
||(u8data > u8limit_max) || (u8data < u8limit_min))
{
return Error;
}
return Ok;
}
/**
******************************************************************************
** \brief RTC时间格式检测
**
** \param [in] pu8TimeDate日期时间数据u8Mode检测模式
**
** \retval enRet校验结果
**
******************************************************************************/
en_result_t Rtc_CheckDateTimeFormat(uint8_t* pu8TimeDate,uint8_t u8Mode)
{
uint8_t u8i=0;
uint8_t u8mon_max_day = 0x28;
uint8_t u8date[3];
uint8_t u8Hour = 0;
en_result_t enRet=Error;
while(u8i<7)
{
if(u8Mode&&(1<<u8i))
{
switch(u8i)
{
case 0:
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x59);//秒
break;
case 1:
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x59);//分
break;
case 2:
if(Rtc12h == M0P_RTC->CR0_f.AMPM)
{
u8Hour = *pu8TimeDate&0x1f;
enRet = Check_BCD_Format(u8Hour,0x00,0x12);//时
}
else
{
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x24);
}
break;
case 3:
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x06);
break;
case 4:
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x31);
u8date[0] = *pu8TimeDate;
break;
case 5:
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x12);
u8date[1] = *pu8TimeDate;
break;
case 6:
enRet = Check_BCD_Format(*pu8TimeDate,0x00,0x99);
u8date[2] = *pu8TimeDate;
break;
default:
break;
}
pu8TimeDate++;
}
if(enRet!=Ok)
{
return enRet;
}
u8i++;
}
if((u8Mode&0x10)&&(u8Mode&0x20))
{
if(u8Mode&0x40)
{
u8mon_max_day = Get_Month_Max_Day(Change_DateTimeFormat(u8date[1]), Change_DateTimeFormat(u8date[2]));
}
else
{
u8mon_max_day = Get_Month_Max_Day(Change_DateTimeFormat(u8date[1]), 1);
}
if(u8date[0]>u8mon_max_day)
{
return Error;
}
}
if((u8Mode&0x10)&&(!(u8Mode&0x20)))
{
if(u8date[0]>0x28)
{
return Error;
}
}
enRet = Ok;
return(enRet);
}
/**
******************************************************************************
** \brief RTC设置时间函数
**
** \param [in] pstcTimeDate日期时间数据bUpdateTime是否更改时间bUpdateDate是否更改日期
**
** \retval Ok
** \retval ErrorTimeout
******************************************************************************/
en_result_t Rtc_WriteDateTime(stc_rtc_time_t* pstcTimeDate,boolean_t bUpdateTime,
boolean_t bUpdateDate)
{
int32_t u32TimeOut;
uint8_t* pu8TimeDate;
en_result_t enRet = Ok;
u32TimeOut = RTC_TIMEOUT;
pu8TimeDate = &pstcTimeDate->u8Second;
ASSERT(NULL != pstcTimeDate);
if(1 == M0P_RTC->CR0_f.START)
{
M0P_RTC->CR1_f.WAIT = 1;
while(--u32TimeOut)
{
if(M0P_RTC->CR1_f.WAITF)
{
break;
}
}
if(u32TimeOut==0)
{
return ErrorTimeout;
}
}
if(TRUE == bUpdateTime)
{
enRet = Rtc_CheckDateTimeFormat(pu8TimeDate,CkTime);
if(enRet != Ok)
{
return enRet;
}
M0P_RTC->SEC = pstcTimeDate->u8Second;
M0P_RTC->MIN = pstcTimeDate->u8Minute;
M0P_RTC->HOUR = pstcTimeDate->u8Hour;
}
if(TRUE == bUpdateDate)
{
enRet = Rtc_CheckDateTimeFormat(pu8TimeDate,CkDate);
if(enRet != Ok)
{
return enRet;
}
M0P_RTC->DAY = pstcTimeDate->u8Day;
M0P_RTC->MON = pstcTimeDate->u8Month;
M0P_RTC->YEAR = pstcTimeDate->u8Year;
M0P_RTC->WEEK = pstcTimeDate->u8DayOfWeek;
}
M0P_RTC->CR1_f.WAIT = 0;
if(1 == M0P_RTC->CR0_f.START)
{
while(M0P_RTC->CR1_f.WAITF)
{}
}
return enRet;
}
/**
******************************************************************************
** \brief RTC 12
**
** \param [in]
**
** \retval
******************************************************************************/
boolean_t Rtc_RDAmPm(void)
{
boolean_t bRet;
bRet = M0P_RTC->HOUR&0x20;
bRet>>=5;
return bRet;
}
/**
******************************************************************************
** \brief RTC获取时间函数
**
** \param [in] pstcTimeDate日期时间数据
**
** \retval Ok
** \retval ErrorTimeout
******************************************************************************/
en_result_t Rtc_ReadDateTime(stc_rtc_time_t* pstcTimeDate)
{
uint32_t u32TimeOut;
uint8_t u8DayOfWeek, u8BcdSec, u8BcdMin, u8BcdHour, u8Day, u8Month, u8Year;
ASSERT(NULL != pstcTimeDate);
u32TimeOut = RTC_TIMEOUT;
if(1 == M0P_RTC->CR0_f.START)
{
M0P_RTC->CR1_f.WAIT = 1;
while(u32TimeOut--)
{
if(M0P_RTC->CR1_f.WAITF)
{
break;
}
}
if(u32TimeOut==0)
{
return ErrorTimeout;
}
}
u8BcdSec = M0P_RTC->SEC;
u8BcdMin = M0P_RTC->MIN;
u8BcdHour = M0P_RTC->HOUR;
u8Day = M0P_RTC->DAY;
u8Month = M0P_RTC->MON;
u8Year = M0P_RTC->YEAR;
u8DayOfWeek = M0P_RTC->WEEK;
pstcTimeDate->u8Second = u8BcdSec;
pstcTimeDate->u8Minute = u8BcdMin;
if(1 == M0P_RTC->CR0_f.AMPM)
{
pstcTimeDate->u8Hour = u8BcdHour;
}
else
{
pstcTimeDate->u8Hour = u8BcdHour&0x1f;
}
pstcTimeDate->u8Day = u8Day;
pstcTimeDate->u8Month = u8Month;
pstcTimeDate->u8Year = u8Year;
pstcTimeDate->u8DayOfWeek = u8DayOfWeek;
M0P_RTC->CR1_f.WAIT = 0;
if(1 == M0P_RTC->CR0_f.START)
{
while(M0P_RTC->CR1_f.WAITF)
{}
}
return Ok;
}
/**
******************************************************************************
** \brief RTC计数or读写状态获取
**
** \param [in]
**
** \retval or读写状态
**
******************************************************************************/
boolean_t Rtc_RDStatus(void)
{
boolean_t bRet;
bRet = M0P_RTC->CR1_f.WAITF;
return bRet;
}
/**
******************************************************************************
** \brief RTC闹钟中断使能
**
** \param [in] enordis中断使能or禁止
**
** \retval Ok设置成功
**
******************************************************************************/
en_result_t Rtc_EnAlarmIrq(en_rtc_alarmirq_t enIrqEn)
{
en_result_t enRet = Error;
M0P_RTC->CR1_f.ALMIE = enIrqEn;
Rtc_ClrIrqStatus(RtcAlmf);//使能中断后清除中断请求标记
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief RTC中断请求状态获取
**
** \param [in] enIrqSel获取哪种中断请求
**
** \retval
**
******************************************************************************/
boolean_t Rtc_GetIrqStatus(en_rtc_status_irq_t enIrqSel)
{
boolean_t bRet = FALSE;
ASSERT(IS_VALID_IRQ_SEL(enIrqSel));
switch(enIrqSel)
{
case RtcPrdf:
(M0P_RTC->CR1_f.PRDF == 1)?(bRet = TRUE) : (bRet = FALSE);
break;
case RtcAlmf :
(M0P_RTC->CR1_f.ALMF == 1)?(bRet = TRUE) : (bRet = FALSE);
break;
default:
break;
}
return bRet;
}
/**
******************************************************************************
** \brief RTC中断请求清除
**
** \param [in] enIrqSel清除哪种中断请求
**
** \retval Ok
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Rtc_ClrIrqStatus(en_rtc_status_irq_t enIrqSel)
{
ASSERT(IS_VALID_IRQ_SEL(enIrqSel));
switch(enIrqSel)
{
case RtcPrdf:
M0P_RTC->CR1_f.PRDF = 0;
break;
case RtcAlmf:
M0P_RTC->CR1_f.ALMF = 0;
break;
default:
return ErrorInvalidParameter;
}
return Ok;
}
/**
******************************************************************************
** \brief RTC中断处理函数接口获取
**
** \param [in]
**
** \retval
**
******************************************************************************/
static stc_rtc_intern_cb_t* RtcGetInternDataCb(void)
{
return &stcRtcIrqCb;
}
/**
******************************************************************************
** \brief RTC总体初始化函数
**
** \param [in] pstcRtcConfig初始化结构
**
** \retval Ok初始化成功
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Rtc_Init(stc_rtc_config_t* pstcRtcConfig)
{
en_result_t enRet = Error;
stc_rtc_intern_cb_t* pstcRtcInternCb;
if(NULL == pstcRtcConfig)
{
return Error;
}
pstcRtcInternCb = RtcGetInternDataCb();
enRet = Rtc_SelClk(pstcRtcConfig->enClkSel);
enRet = Rtc_SetAmPm(pstcRtcConfig->enAmpmSel);
if(enRet != Ok)
{
return enRet;
}
if(NULL != pstcRtcConfig->pstcCycSel)
{
if(Ok != Rtc_SetCyc(pstcRtcConfig->pstcCycSel))
{
return Error;
}
}
if(NULL != pstcRtcConfig->pstcTimeDate)
{
if(Ok != Rtc_WriteDateTime(pstcRtcConfig->pstcTimeDate,TRUE,TRUE))
{
return Error;
}
}
if(NULL != pstcRtcConfig->pstcIrqCb)
{
pstcRtcInternCb->pfnAlarmIrqCb = pstcRtcConfig->pstcIrqCb->pfnAlarmIrqCb;
pstcRtcInternCb->pfnTimerIrqCb = pstcRtcConfig->pstcIrqCb->pfnTimerIrqCb;
}
if(TRUE == pstcRtcConfig->bTouchNvic)
{
EnableNvic(RTC_IRQn,IrqLevel3,TRUE);
}
else
{
EnableNvic(RTC_IRQn,IrqLevel3,FALSE);
}
return enRet;
}
/**
******************************************************************************
** \brief RTC计数禁止函数
**
** \param [in]
**
** \retval Ok禁止设置成功
**
******************************************************************************/
en_result_t Rtc_DeInit(void)
{
EnableNvic(RTC_IRQn,IrqLevel3,FALSE);
Rtc_DisableFunc(RtcCount);
Rtc_DisableFunc(RtcAlarmEn);
Rtc_DisableFunc(Rtc_ComenEn);
Rtc_DisableFunc(Rtc1HzOutEn);
return Ok;
}
/**
******************************************************************************
** \brief RTC中断处理函数
**
** \param [in]
**
** \retval
**
******************************************************************************/
void Rtc_IRQHandler(void)
{
stc_rtc_intern_cb_t* pstcRtcInternCb;
pstcRtcInternCb = RtcGetInternDataCb() ;
if(TRUE == M0P_RTC->CR1_f.ALMF)
{
M0P_RTC->CR1_f.ALMF = 0u;
if(NULL != pstcRtcInternCb->pfnAlarmIrqCb)
{
pstcRtcInternCb->pfnAlarmIrqCb();
}
}
if(TRUE == M0P_RTC->CR1_f.PRDF)
{
M0P_RTC->CR1_f.PRDF = 0;
if(NULL != pstcRtcInternCb->pfnTimerIrqCb)
{
pstcRtcInternCb->pfnTimerIrqCb();
}
}
}
//@} // RtcGroup

View File

@ -0,0 +1,526 @@
/******************************************************************************
* Copyright (C) 2016, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with eaenCh copy of this software, whether used in part or whole,
* at all times.
*/
/*****************************************************************************/
/** \file spi.c
**
** SPI driver API.
** @link Driver Group Some description @endlink
**
** - 2018-05-17 1.0 Devi First version for Device Driver Library of
** Module.
**
*****************************************************************************/
/******************************************************************************
* Include files
*****************************************************************************/
#include "spi.h"
/**
******************************************************************************
** \addtogroup SpiGroup
*****************************************************************************/
//@{
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
*****************************************************************************/
#define IS_VALID_STAT(x) ( SpiIf == (x)||\
SpiSserr == (x)||\
SpiBusy == (x)||\
SpiMdf == (x)||\
SpiTxe == (x)||\
SpiRxne == (x))
#define IS_VALID_CH(x) ( Spi0 == (x)||\
Spi1 == (x))
/******************************************************************************/
/* Local function prototypes ('static') */
/******************************************************************************/
/******************************************************************************/
/* Local variable prototypes ('static') */
/******************************************************************************/
static func_ptr_t pfnSpi0Callback = NULL; ///< callback function pointer for SPI Irq
static func_ptr_t pfnSpi1Callback = NULL; ///< callback function pointer for SPI Irq
/**
******************************************************************************
** \brief SPI
**
** \param [in] enCh通道
**
** \retval
**
******************************************************************************/
void Spi_IRQHandler(en_spi_channel_t enCh)
{
if(Spi0 == enCh)
{
if(NULL != pfnSpi0Callback)
{
pfnSpi0Callback();
}
}
else
{
if(NULL != pfnSpi1Callback)
{
pfnSpi1Callback();
}
}
}
/**
******************************************************************************
** \brief SPI
**
** \param [in]enCh
**
** \retval
**
******************************************************************************/
uint8_t Spi_GetState(en_spi_channel_t enCh)
{
uint8_t u8State = 0;
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
u8State = M0P_SPI0->STAT;
}
else
{
u8State = M0P_SPI1->STAT;
}
return u8State;
}
/**
******************************************************************************
** \brief SPI
**
** \param [in]enCh enStatus
**
** \retval
**
******************************************************************************/
boolean_t Spi_GetStatus(en_spi_channel_t enCh,en_spi_status_t enStatus)
{
boolean_t bFlag = FALSE;
ASSERT(IS_VALID_CH(enCh));
ASSERT(IS_VALID_STAT(enStatus));
if(Spi0 == enCh)
{
switch (enStatus)
{
case SpiIf:
bFlag = M0P_SPI0->STAT_f.SPIF;
break;
case SpiSserr:
bFlag = M0P_SPI0->STAT_f.SSERR;
break;
case SpiMdf:
bFlag = M0P_SPI0->STAT_f.MDF;
break;
case SpiBusy:
bFlag = M0P_SPI0->STAT_f.BUSY;
break;
case SpiTxe:
bFlag = M0P_SPI0->STAT_f.TXE;
break;
case SpiRxne:
bFlag = M0P_SPI0->STAT_f.RXNE;
break;
default:
break;
}
}
else
{
switch (enStatus)
{
case SpiIf:
bFlag = M0P_SPI1->STAT_f.SPIF;
break;
case SpiSserr:
bFlag = M0P_SPI1->STAT_f.SSERR;
break;
case SpiMdf:
bFlag = M0P_SPI1->STAT_f.MDF;
break;
case SpiBusy:
bFlag = M0P_SPI1->STAT_f.BUSY;
break;
case SpiTxe:
bFlag = M0P_SPI1->STAT_f.TXE;
break;
case SpiRxne:
bFlag = M0P_SPI1->STAT_f.RXNE;
break;
default:
break;
}
}
return bFlag;
}
/**
******************************************************************************
** \brief SPI中断清除
**
** \param [in]enCh enStatus
**
** \retval
**
******************************************************************************/
en_result_t Spi_ClearStatus(en_spi_channel_t enCh)
{
en_result_t enRet = Error;
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
M0P_SPI0->ICLR_f.INT_CLR = 0;
}
else
{
M0P_SPI1->ICLR_f.INT_CLR = 0;
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief SPI 使
**
** \param [in] enCh通道enFunc功能bFlag 0/1使
**
** \retval Ok初始化成功
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Spi_FuncEn(en_spi_channel_t enCh,en_spi_func_t enFunc,boolean_t bFlag)
{
en_result_t enRet = Error;
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
switch(enFunc)
{
case SpiRxNeIe:
M0P_SPI0->CR2_f.RXNEIE = bFlag;
break;
case SpiTxEIe:
M0P_SPI0->CR2_f.TXEIE = bFlag;
break;
case SpiDmaTxEn:
M0P_SPI0->CR2_f.HDMA_TX = bFlag;
break;
case SpiDmaRxEn:
M0P_SPI0->CR2_f.HDMA_RX = bFlag;
break;
default:
return ErrorInvalidParameter;
}
}
else
{
switch(enFunc)
{
case SpiRxNeIe:
M0P_SPI1->CR2_f.RXNEIE = bFlag;
break;
case SpiTxEIe:
M0P_SPI1->CR2_f.TXEIE = bFlag;
break;
case SpiDmaTxEn:
M0P_SPI1->CR2_f.HDMA_TX = bFlag;
break;
case SpiDmaRxEn:
M0P_SPI1->CR2_f.HDMA_RX = bFlag;
break;
default:
return ErrorInvalidParameter;
}
}
enRet = Ok;
return enRet;
}
/**
******************************************************************************
** \brief SPI
**
** \param [in]
enCh通道
pstcSpiConfig初始化结构
**
** \retval Ok初始化成功
** \retval ErrorInvalidParameter
******************************************************************************/
en_result_t Spi_Init(en_spi_channel_t enCh,stc_spi_config_t *pstcSpiConfig)
{
ASSERT(NULL != pstcSpiConfig);
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
M0P_SPI0->CR = 0x00;
M0P_SPI0->CR_f.MSTR = pstcSpiConfig->bMasterMode;
M0P_SPI0->CR_f.CPOL = pstcSpiConfig->bCPOL;
M0P_SPI0->CR_f.CPHA = pstcSpiConfig->bCPHA;
if(pstcSpiConfig->u8BaudRate > SpiClkDiv16)
{
M0P_SPI0->CR_f.SPR2 = 1;
}
M0P_SPI0->CR |= (pstcSpiConfig->u8BaudRate&0x03u);
M0P_SPI0->STAT = 0x00;
M0P_SPI0->CR_f.SPEN = TRUE;
if (TRUE == pstcSpiConfig->bIrqEn)
{
M0P_SPI0->CR2_f.INT_EN = 1;
EnableNvic(SPI0_IRQn,IrqLevel3,TRUE);
}
else
{
EnableNvic(SPI0_IRQn,IrqLevel3,FALSE);
}
if(NULL != pstcSpiConfig->pfnSpi0IrqCb)
{
pfnSpi0Callback = pstcSpiConfig->pfnSpi0IrqCb;
}
}
else
{
M0P_SPI1->CR = 0x00;
M0P_SPI1->CR_f.MSTR = pstcSpiConfig->bMasterMode;
M0P_SPI1->CR_f.CPOL = pstcSpiConfig->bCPOL;
M0P_SPI1->CR_f.CPHA = pstcSpiConfig->bCPHA;
if(pstcSpiConfig->u8BaudRate > SpiClkDiv16)
{
M0P_SPI1->CR_f.SPR2 = 1;
}
M0P_SPI1->CR |= (pstcSpiConfig->u8BaudRate&0x03u);
M0P_SPI1->STAT = 0x00;
M0P_SPI1->CR_f.SPEN = TRUE;
if (TRUE == pstcSpiConfig->bIrqEn)
{
M0P_SPI1->CR2_f.INT_EN = 1;
EnableNvic(SPI1_IRQn,IrqLevel3,TRUE);
}
else
{
EnableNvic(SPI1_IRQn,IrqLevel3,FALSE);
}
if(NULL != pstcSpiConfig->pfnSpi1IrqCb)
{
pfnSpi1Callback = pstcSpiConfig->pfnSpi1IrqCb;
}
}
return Ok;
}
/**
******************************************************************************
** \brief SPI
**
** \param [in] enCh通道
**
** \retval Ok禁止设置成功
**
******************************************************************************/
en_result_t Spi_DeInit(en_spi_channel_t enCh)
{
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
M0P_SPI0->DATA = 0x00;
M0P_SPI0->STAT = 0x00;
M0P_SPI0->CR = 0x00;
pfnSpi0Callback = NULL;
EnableNvic(SPI0_IRQn,IrqLevel3,FALSE);
}
else
{
M0P_SPI1->DATA = 0x00;
M0P_SPI1->STAT = 0x00;
M0P_SPI1->CR = 0x00;
pfnSpi1Callback = NULL;
EnableNvic(SPI1_IRQn,IrqLevel3,FALSE);
}
return Ok;
}
/**
******************************************************************************
** \brief SPI
**
** \param [in]
**
** \retval
**
******************************************************************************/
void Spi_SetCS(en_spi_channel_t enCh,boolean_t bFlag)
{
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
M0P_SPI0->SSN = bFlag;
}
else
{
M0P_SPI1->SSN = bFlag;
}
}
/**
******************************************************************************
** \brief SPI
**
** \param [in] enCh通道u8Data发送字节
**
** \retval Ok发送成功
**
******************************************************************************/
en_result_t Spi_SendData(en_spi_channel_t enCh,uint8_t u8Data)
{
uint32_t u32TimeOut;
ASSERT(IS_VALID_CH(enCh));
u32TimeOut = 1000;
if(Spi0 == enCh)
{
while(--u32TimeOut)
{
if(TRUE == M0P_SPI0->STAT_f.TXE)
{
break;
}
}
if(u32TimeOut == 0)
{
return ErrorTimeout;
}
M0P_SPI0->DATA = u8Data;
u32TimeOut = 1000;
while(--u32TimeOut)
{
if(TRUE == M0P_SPI0->STAT_f.RXNE)
{
break;
}
}
if(u32TimeOut == 0)
{
return ErrorTimeout;
}
u8Data = M0P_SPI0->DATA;
}
else
{
while(--u32TimeOut)
{
if(TRUE == M0P_SPI1->STAT_f.TXE)
{
break;
}
}
if(u32TimeOut == 0)
{
return ErrorTimeout;
}
M0P_SPI1->DATA = u8Data;
u32TimeOut = 1000;
while(--u32TimeOut)
{
if(TRUE == M0P_SPI1->STAT_f.RXNE)
{
break;
}
}
if(u32TimeOut == 0)
{
return ErrorTimeout;
}
u8Data = M0P_SPI1->DATA;
}
return Ok;
}
/**
******************************************************************************
** \brief SPI
**
** \param [in] enCh接收通道
**
** \retval
**
******************************************************************************/
uint8_t Spi_ReceiveData(en_spi_channel_t enCh,boolean_t bMasterOrSlave)
{
uint8_t temp;
ASSERT(IS_VALID_CH(enCh));
if(Spi0 == enCh)
{
if(1 == bMasterOrSlave)
{
M0P_SPI0->DATA = 0x00;
}
while(0 == M0P_SPI0->STAT_f.RXNE){;}
temp = M0P_SPI0->DATA;
}
else
{
if(1 == bMasterOrSlave)
{
M0P_SPI1->DATA = 0x00;
}
while(0 == M0P_SPI1->STAT_f.RXNE){;}
temp = M0P_SPI1->DATA;
}
return temp;
}
//@} // SpiGroup
/******************************************************************************
* EOF (not truncated)
*****************************************************************************/

View File

@ -0,0 +1,776 @@
/******************************************************************************
*Copyright(C)2018, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file sysctrl.c
**
** Common API of sysctrl.
** @link SysctrlGroup Some description @endlink
**
** - 2018-04-22 Lux
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "sysctrl.h"
/**
*******************************************************************************
** \addtogroup SysctrlGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
#define CLK_TIMEOUT (1000000u)
#define IS_VALID_SRC(x) ( ClkRCH == (x)||\
ClkXTH == (x)||\
ClkRCL == (x)||\
ClkXTL == (x) )
#define IS_VALID_FUNC(x) ( ClkFuncWkupRCH == (x)||\
ClkFuncXTHEn == (x)||\
ClkFuncXTLEn == (x)||\
ClkFuncXTLAWSON == (x)||\
ClkFuncFaultEn == (x)||\
ClkFuncRtcLPWEn == (x)||\
ClkFuncLockUpEn == (x)||\
ClkFuncRstPinIOEn == (x)||\
ClkFuncSwdPinIOEn == (x) )
#define RCH_CR_TRIM_24M_VAL (*((volatile uint16_t*) (0x00100C00ul)))
#define RCH_CR_TRIM_22_12M_VAL (*((volatile uint16_t*) (0x00100C02ul)))
#define RCH_CR_TRIM_16M_VAL (*((volatile uint16_t*) (0x00100C04ul)))
#define RCH_CR_TRIM_8M_VAL (*((volatile uint16_t*) (0x00100C06ul)))
#define RCH_CR_TRIM_4M_VAL (*((volatile uint16_t*) (0x00100C08ul)))
#define RCL_CR_TRIM_38400_VAL (*((volatile uint16_t*) (0x00100C20ul)))
#define RCL_CR_TRIM_32768_VAL (*((volatile uint16_t*) (0x00100C22ul)))
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
extern uint32_t SystemCoreClock;
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*******************************************************************************
** \brief SYSCTRL0\SYSCTRL1寄存器操作解锁
**
** \retval None
******************************************************************************/
static void _SysctrlUnlock(void)
{
M0P_SYSCTRL->SYSCTRL2 = 0x5A5A;
M0P_SYSCTRL->SYSCTRL2 = 0xA5A5;
}
/**
*******************************************************************************
** \brief 使
** \param [in] enSource
** \param [in] bFlag 使1-/0-
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_ClkSourceEnable(en_sysctrl_clk_source_t enSource, boolean_t bFlag)
{
en_result_t enRet = Ok;
_SysctrlUnlock();
bFlag = !!bFlag;
switch (enSource)
{
case SysctrlClkRCH:
M0P_SYSCTRL->SYSCTRL0_f.RCH_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->RCH_CR_f.STABLE))
{
;
}
break;
case SysctrlClkXTH:
M0P_GPIO->PDADS_f.PD00 = 1;
M0P_GPIO->PDADS_f.PD01 = 1;
M0P_SYSCTRL->SYSCTRL0_f.XTH_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->XTH_CR_f.STABLE))
{
;
}
break;
case SysctrlClkRCL:
M0P_SYSCTRL->SYSCTRL0_f.RCL_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->RCL_CR_f.STABLE))
{
;
}
break;
case SysctrlClkXTL:
M0P_GPIO->PCADS_f.PC14 = 1;
M0P_GPIO->PCADS_f.PC15 = 1;
M0P_SYSCTRL->SYSCTRL0_f.XTL_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->XTL_CR_f.STABLE))
{
;
}
break;
case SysctrlClkPLL:
M0P_SYSCTRL->SYSCTRL0_f.PLL_EN = bFlag;
while(bFlag && (1 != M0P_SYSCTRL->PLL_CR_f.STABLE))
{
;
}
break;
default:
enRet = ErrorInvalidParameter;
break;
}
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enFreq
** \param [in] enDriver
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_XTHDriverConfig(en_sysctrl_xtal_driver_t enDriver)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTH_CR_f.DRIVER = enDriver;
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enFreq
** \param [in] enDriver
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_XTLDriverConfig(en_sysctrl_xtl_amp_t enAmp, en_sysctrl_xtal_driver_t enDriver)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTL_CR_f.AMP_SEL = enAmp;
M0P_SYSCTRL->XTL_CR_f.DRIVER = enDriver;
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enCycle
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetXTHStableTime(en_sysctrl_xth_cycle_t enCycle)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTH_CR_f.STARTUP = enCycle;
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enCycle
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetRCLStableTime(en_sysctrl_rcl_cycle_t enCycle)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->RCL_CR_f.STARTUP = enCycle;
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enCycle
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetXTLStableTime(en_sysctrl_xtl_cycle_t enCycle)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTL_CR_f.STARTUP = enCycle;
return enRet;
}
/**
*******************************************************************************
** \brief PLL稳定周期配置
** \param [in] enCycle PLL稳定周期设置
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetPLLStableTime(en_sysctrl_pll_cycle_t enCycle)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->PLL_CR_f.STARTUP = enCycle;
return enRet;
}
/**
*******************************************************************************
** \brief
** \note //使
** \param [in] enSource
**
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SysClkSwitch(en_sysctrl_clk_source_t enSource)
{
en_result_t enRet = Ok;
en_sysctrl_clk_source_t ClkNew = enSource;
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL0_f.CLK_SW5_SEL = ClkNew;
//更新Core时钟HCLK
SystemCoreClockUpdate();
return enRet;
}
/**
*******************************************************************************
** \brief HCLK
** \retval uint32_t HCLK频率值
**
******************************************************************************/
uint32_t Sysctrl_GetHClkFreq(void)
{
uint32_t u32Val = 0;
const uint32_t u32hcr_tbl[] = { 4000000, 8000000, 16000000, 22120000, 24000000};
const uint16_t u32lcr_tbl[] = { 32768, 38400};
en_sysctrl_clk_source_t enSrc;
uint16_t u16Trim[5] = {0};
u16Trim[4] = RCH_CR_TRIM_24M_VAL;
u16Trim[3] = RCH_CR_TRIM_22_12M_VAL;
u16Trim[2] = RCH_CR_TRIM_16M_VAL;
u16Trim[1] = RCH_CR_TRIM_8M_VAL;
u16Trim[0] = RCL_CR_TRIM_38400_VAL;
//获取当前系统时钟
enSrc = (en_sysctrl_clk_source_t)(M0P_SYSCTRL->SYSCTRL0_f.CLK_SW5_SEL);
switch (enSrc)
{
case SysctrlClkRCH:
{
if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[4]))
{
u32Val = u32hcr_tbl[4];
}
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[3]))
{
u32Val = u32hcr_tbl[3];
}
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[2]))
{
u32Val = u32hcr_tbl[2];
}
else if((M0P_SYSCTRL->RCH_CR_f.TRIM) == (u16Trim[1]))
{
u32Val = u32hcr_tbl[1];
}
else
{
u32Val = u32hcr_tbl[0];
}
}
break;
case SysctrlClkXTH:
u32Val = SYSTEM_XTH;
break;
case SysctrlClkRCL:
{
if(u16Trim[0] == (M0P_SYSCTRL->RCL_CR_f.TRIM))
{
u32Val = u32lcr_tbl[1];
}
else
{
u32Val = u32lcr_tbl[0];
}
}
break;
case SysctrlClkXTL:
u32Val = SYSTEM_XTL;
break;
case SysctrlClkPLL:
{
if (SysctrlPllRch == M0P_SYSCTRL->PLL_CR_f.REFSEL)
{
if(u16Trim[4] == M0P_SYSCTRL->RCH_CR_f.TRIM)
{
u32Val = u32hcr_tbl[4];
}
else if(u16Trim[3] == M0P_SYSCTRL->RCH_CR_f.TRIM)
{
u32Val = u32hcr_tbl[3];
}
else if(u16Trim[2] == M0P_SYSCTRL->RCH_CR_f.TRIM)
{
u32Val = u32hcr_tbl[2];
}
else if(u16Trim[1] == M0P_SYSCTRL->RCH_CR_f.TRIM)
{
u32Val = u32hcr_tbl[1];
}
else
{
u32Val = u32hcr_tbl[0];
}
}
else
{
u32Val = SYSTEM_XTH;
}
u32Val = (u32Val * M0P_SYSCTRL->PLL_CR_f.DIVN);
}
break;
default:
u32Val = 0u;
break;
}
u32Val = (u32Val >> M0P_SYSCTRL->SYSCTRL0_f.HCLK_PRS);
return u32Val;
}
/**
*******************************************************************************
** \brief PCLK
** \retval uint32_t PCLK频率值(Hz)
**
******************************************************************************/
uint32_t Sysctrl_GetPClkFreq(void)
{
uint32_t u32Val = 0;
u32Val = Sysctrl_GetHClkFreq();
u32Val = (u32Val >> (M0P_SYSCTRL->SYSCTRL0_f.PCLK_PRS));
return u32Val;
}
/**
*******************************************************************************
** \brief
** \param [in] pstcCfg
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_ClkInit(stc_sysctrl_clk_config_t *pstcCfg)
{
en_result_t enRet = Ok;
//系统时钟参数配置
switch(pstcCfg->enClkSrc)
{
case SysctrlClkRCH:
break;
case SysctrlClkXTH:
Sysctrl_XTHDriverConfig(SysctrlXtalDriver3);
Sysctrl_SetXTHStableTime(SysctrlXthStableCycle16384);
break;
case SysctrlClkRCL:
Sysctrl_SetRCLStableTime(SysctrlRclStableCycle256);
break;
case SysctrlClkXTL:
Sysctrl_XTLDriverConfig(SysctrlXtlAmp3, SysctrlXtalDriver3);
Sysctrl_SetXTLStableTime(SysctrlXtlStableCycle16384);
break;
case SysctrlClkPLL:
Sysctrl_SetPLLStableTime(SysctrlPllStableCycle16384);
break;
default:
enRet = ErrorInvalidParameter;
break;
}
//时钟源使能
Sysctrl_ClkSourceEnable(pstcCfg->enClkSrc, TRUE);
//时钟源切换
Sysctrl_SysClkSwitch(pstcCfg->enClkSrc);
//时钟分频设置
Sysctrl_SetHCLKDiv(pstcCfg->enHClkDiv);
Sysctrl_SetPCLKDiv(pstcCfg->enPClkDiv);
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in]
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_ClkDeInit(void)
{
en_result_t enRet = Ok;
//配置RCH为内部4Hz
Sysctrl_SetRCHTrim(SysctrlRchFreq4MHz);
//时钟源使能
Sysctrl_ClkSourceEnable(SysctrlClkRCH, TRUE);
//时钟源切换
Sysctrl_SysClkSwitch(SysctrlClkRCH);
//其它时钟源使能关闭
Sysctrl_ClkSourceEnable(SysctrlClkXTH, FALSE);
Sysctrl_ClkSourceEnable(SysctrlClkRCL, FALSE);
Sysctrl_ClkSourceEnable(SysctrlClkXTL, FALSE);
Sysctrl_ClkSourceEnable(SysctrlClkPLL, FALSE);
//时钟分频设置
Sysctrl_SetHCLKDiv(SysctrlHclkDiv1);
Sysctrl_SetPCLKDiv(SysctrlPclkDiv1);
return enRet;
}
/**
*******************************************************************************
** \brief TRIM值加载
** \param [in] enRCHFreq RCH目标频率值
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetRCHTrim(en_sysctrl_rch_freq_t enRCHFreq)
{
en_result_t enRet = Ok;
//加载RCH Trim值
switch (enRCHFreq)
{
case SysctrlRchFreq4MHz:
M0P_SYSCTRL->RCH_CR_f.TRIM = RCH_CR_TRIM_4M_VAL;
break;
case SysctrlRchFreq8MHz:
M0P_SYSCTRL->RCH_CR_f.TRIM = RCH_CR_TRIM_8M_VAL;
break;
case SysctrlRchFreq16MHz:
M0P_SYSCTRL->RCH_CR_f.TRIM = RCH_CR_TRIM_16M_VAL;
break;
case SysctrlRchFreq22_12MHz:
M0P_SYSCTRL->RCH_CR_f.TRIM = RCH_CR_TRIM_22_12M_VAL;
break;
case SysctrlRchFreq24MHz:
M0P_SYSCTRL->RCH_CR_f.TRIM = RCH_CR_TRIM_24M_VAL;
break;
default:
enRet = ErrorInvalidParameter;
break;
}
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enXTHFreq
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetXTHFreq(en_sysctrl_xth_freq_t enXTHFreq)
{
en_result_t enRet = Ok;
M0P_SYSCTRL->XTH_CR_f.XTH_FSEL = enXTHFreq;
return enRet;
}
/**
*******************************************************************************
** \brief PLL时钟配置
** \param [in] pstcPLLCfg PLL配置结构体指针
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetPLLFreq(stc_sysctrl_pll_config_t *pstcPLLCfg)
{
en_result_t enRet = Ok;
uint16_t u16Trim[5] = {0};
u16Trim[4] = RCH_CR_TRIM_24M_VAL;
u16Trim[3] = RCH_CR_TRIM_22_12M_VAL;
u16Trim[2] = RCH_CR_TRIM_16M_VAL;
u16Trim[1] = RCH_CR_TRIM_8M_VAL;
////PLL最高时钟不能超过48MHz
//RCH作为PLL输入
if (SysctrlPllRch == pstcPLLCfg->enPllClkSrc)
{
if( ((u16Trim[4] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 2)) ||
((u16Trim[3] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 2)) ||
((u16Trim[2] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 3)) ||
((u16Trim[1] == M0P_SYSCTRL->RCH_CR_f.TRIM) && (pstcPLLCfg->enPllMul > 6)))
{
return ErrorInvalidMode;
}
}
else //XTH作为PLL输入
{
if ((SYSTEM_XTH * pstcPLLCfg->enPllMul) > 48*1000*1000)
{
return ErrorInvalidMode;
}
}
M0P_SYSCTRL->PLL_CR_f.FRSEL = pstcPLLCfg->enInFreq;
M0P_SYSCTRL->PLL_CR_f.FOSC = pstcPLLCfg->enOutFreq;
M0P_SYSCTRL->PLL_CR_f.DIVN = pstcPLLCfg->enPllMul;
M0P_SYSCTRL->PLL_CR_f.REFSEL = pstcPLLCfg->enPllClkSrc;
return enRet;
}
/**
*******************************************************************************
** \brief TRIM值加载
** \param [in] enRCLFreq RCL目标频率值
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetRCLTrim(en_sysctrl_rcl_freq_t enRCLFreq)
{
en_result_t enRet = Ok;
switch (enRCLFreq)
{
case SysctrlRclFreq32768:
M0P_SYSCTRL->RCL_CR_f.TRIM = RCL_CR_TRIM_32768_VAL;
break;
case SysctrlRclFreq38400:
M0P_SYSCTRL->RCL_CR_f.TRIM = RCL_CR_TRIM_38400_VAL;
break;
default:
enRet = ErrorInvalidParameter;
break;
}
return enRet;
}
/**
*******************************************************************************
** \brief HCLK
** \param [in] enHCLKDiv
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetHCLKDiv(en_sysctrl_hclk_div_t enHCLKDiv)
{
en_result_t enRet = Ok;
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL0_f.HCLK_PRS = enHCLKDiv;
return enRet;
}
/**
*******************************************************************************
** \brief PCLK
** \param [in] enPCLKDiv
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetPCLKDiv(en_sysctrl_pclk_div_t enPCLKDiv)
{
en_result_t enRet = Ok;
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL0_f.PCLK_PRS = enPCLKDiv;
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enPeripheral
** \param [in] bFlag 使
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral, boolean_t bFlag)
{
en_result_t enRet = Ok;
bFlag = !!bFlag;
setBit(&(M0P_SYSCTRL->PERI_CLKEN), enPeripheral, bFlag);
return enRet;
}
/**
*******************************************************************************
** \brief
** \param [in] enPeripheral
** \retval TRUE
** FALSE
******************************************************************************/
boolean_t Sysctrl_GetPeripheralGate(en_sysctrl_peripheral_gate_t enPeripheral)
{
return getBit(&(M0P_SYSCTRL->PERI_CLKEN), enPeripheral);
}
/**
*******************************************************************************
** \brief
** \param [in] enFunc
** \param [in] bFlag 1-/0-
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetFunc(en_sysctrl_func_t enFunc, boolean_t bFlag)
{
en_result_t enRet = Ok;
_SysctrlUnlock();
bFlag = !!bFlag;
switch (enFunc)
{
case SysctrlWkupByRCHEn:
M0P_SYSCTRL->SYSCTRL0_f.WAKEUP_BYRCH = bFlag;
break;
case SysctrlEXTHEn:
M0P_SYSCTRL->SYSCTRL1_f.EXTH_EN = bFlag;
break;
case SysctrlEXTLEn:
M0P_SYSCTRL->SYSCTRL1_f.EXTL_EN = bFlag;
break;
case SysctrlXTLAlwaysOnEn:
M0P_SYSCTRL->SYSCTRL1_f.XTL_ALWAYS_ON = bFlag;
break;
case SysctrlClkFuncRTCLpmEn:
M0P_SYSCTRL->SYSCTRL1_f.RTC_LPW = bFlag;
break;
case SysctrlCMLockUpEn:
M0P_SYSCTRL->SYSCTRL1_f.LOCKUP_EN = bFlag;
break;
case SysctrlSWDUseIOEn:
M0P_SYSCTRL->SYSCTRL1_f.SWD_USE_IO = bFlag;
break;
default:
enRet = ErrorInvalidParameter;
break;
}
return enRet;
}
/**
*******************************************************************************
** \brief RTC校准时钟频率
** \param [in] enRtcAdj
** \retval Ok
**
******************************************************************************/
en_result_t Sysctrl_SetRTCAdjustClkFreq(en_sysctrl_rtc_adjust_t enRtcAdj)
{
en_result_t enRet = Ok;
_SysctrlUnlock();
M0P_SYSCTRL->SYSCTRL1_f.RTC_FREQ_ADJUST = enRtcAdj;
return enRet;
}
//@} // SysctrlGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,348 @@
/******************************************************************************
*Copyright(C)2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/** \file trim.c
**
** Common API of trim.
** @link trimGroup Some description @endlink
**
** - 2017-05-16
**
******************************************************************************/
/*******************************************************************************
* Include files
******************************************************************************/
#include "trim.h"
/**
*******************************************************************************
** \addtogroup TrimGroup
******************************************************************************/
//@{
/*******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/*******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
#define IS_VALID_TRIMINT(x) (TrimStop == (x) ||\
TrimCalCntOf == (x) ||\
TrimXTLFault == (x) ||\
TrimXTHFault == (x) ||\
TrimPLLFault == (x))
/*******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/*******************************************************************************
* Local variable definitions ('static')
******************************************************************************/
/*******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
static func_ptr_t pfnTrimCallback = NULL;
/*******************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
/**
*****************************************************************************
** \brief Trim中断标志获取
**
**
** \param [in] enIntType RefStopCalCntOfXTAL32KFaultXTAL32MFault
**
** \retval TRUE or FALSE
*****************************************************************************/
boolean_t Trim_GetIntFlag(en_trim_inttype_t enIntType)
{
boolean_t bRetVal = FALSE;
ASSERT(IS_VALID_TRIMINT(enIntType));
switch (enIntType)
{
case TrimStop:
bRetVal = M0P_CLK_TRIM->IFR_f.STOP ? TRUE : FALSE;
break;
case TrimCalCntOf:
bRetVal = M0P_CLK_TRIM->IFR_f.CALCNT_OF ? TRUE : FALSE;
break;
case TrimXTLFault:
bRetVal = M0P_CLK_TRIM->IFR_f.XTL_FAULT ? TRUE : FALSE;
break;
case TrimXTHFault:
bRetVal = M0P_CLK_TRIM->IFR_f.XTH_FAULT ? TRUE : FALSE;
break;
case TrimPLLFault:
bRetVal = M0P_CLK_TRIM->IFR_f.PLL_FAULT ? TRUE : FALSE;
break;
default:
bRetVal = FALSE;
break;
}
return bRetVal;
}
/**
*****************************************************************************
** \brief Trim中断标志清除
**
**
** \param [in] enIntType RefStopCalCntOfXTAL32KFaultXTAL32MFault
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_ClearIntFlag(en_trim_inttype_t enIntType)
{
en_result_t enResult = Error;
ASSERT(IS_VALID_TRIMINT(enIntType));
switch (enIntType)
{
case TrimStop:
M0P_CLK_TRIM->CR_f.TRIM_START = FALSE;
enResult = Ok;
break;
case TrimCalCntOf:
M0P_CLK_TRIM->CR_f.TRIM_START = FALSE;
enResult = Ok;
break;
case TrimXTLFault:
M0P_CLK_TRIM->ICLR_f.XTL_FAULT_CLR = FALSE;
enResult = Ok;
break;
case TrimXTHFault:
M0P_CLK_TRIM->ICLR_f.XTH_FAULT_CLR = FALSE;
enResult = Ok;
break;
case TrimPLLFault:
M0P_CLK_TRIM->ICLR_f.PLL_FAULT_CLR = FALSE;
enResult = Ok;
break;
default:
enResult = Error;
break;
}
return enResult;
}
/**
*****************************************************************************
** \brief Trim中断服务函数
**
**
** \param [in] u8Param == 0
**
** \retval NULL
*****************************************************************************/
void ClkTrim_IRQHandler(uint8_t u8Param)
{
if(NULL != pfnTrimCallback)
{
pfnTrimCallback();
}
}
/**
*****************************************************************************
** \brief Trim中断使能
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_EnableIrq (void)
{
en_result_t enResult = Error;
M0P_CLK_TRIM->CR_f.IE = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Trim中断禁止
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_DisableIrq(void)
{
en_result_t enResult = Error;
M0P_CLK_TRIM->CR_f.IE = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Trim初始化配置
**
**
** \param [in] pstcConfig Trim配置结构体指针
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_Init(stc_trim_config_t* pstcConfig)
{
en_result_t enResult = Error;
M0P_CLK_TRIM->CR_f.MON_EN = pstcConfig->enMON;
if (TrimCalPLL == pstcConfig->enCALCLK)
{
M0P_CLK_TRIM->CR_f.CALCLK_SEL2 = TRUE;
M0P_CLK_TRIM->CR_f.CALCLK_SEL = pstcConfig->enCALCLK;
}
else
{
M0P_CLK_TRIM->CR_f.CALCLK_SEL2 = FALSE;
M0P_CLK_TRIM->CR_f.CALCLK_SEL = pstcConfig->enCALCLK;
}
M0P_CLK_TRIM->CR_f.REFCLK_SEL = pstcConfig->enREFCLK;
M0P_CLK_TRIM->REFCON_f.RCNTVAL = pstcConfig->u32RefCon;
if(TrimMonEnable == pstcConfig->enMON)
{
M0P_CLK_TRIM->CALCON_f.CCNTVAL = pstcConfig->u32CalCon;
}
pfnTrimCallback = pstcConfig->pfnTrimCb;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Trim校准/
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_Run(void)
{
en_result_t enResult = Error;
M0P_CLK_TRIM->CR_f.TRIM_START = TRUE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Trim校准/
**
**
**
**
** \retval Ok or Error
*****************************************************************************/
en_result_t Trim_Stop(void)
{
en_result_t enResult = Error;
M0P_CLK_TRIM->CR_f.TRIM_START = FALSE;
enResult = Ok;
return enResult;
}
/**
*****************************************************************************
** \brief Trim参考计数器计数值获取
**
**
** \retval u32Data
*****************************************************************************/
uint32_t Trim_RefCntGet(void)
{
uint32_t u32Data = 0;
u32Data = M0P_CLK_TRIM->REFCNT_f.REFCNT;
return u32Data;
}
/**
*****************************************************************************
** \brief Trim校准计数器计数值获取
**
**
**
**
** \retval u32Data
*****************************************************************************/
uint32_t Trim_CalCntGet(void)
{
uint32_t u32Data = 0;
u32Data = M0P_CLK_TRIM->CALCNT_f.CALCNT;
return u32Data;
}
//@} // TrimGroup
/*******************************************************************************
* EOF (not truncated)
******************************************************************************/

Some files were not shown because too many files have changed in this diff Show More