diff --git a/bsp/nv32f100x/SConscript b/bsp/nv32f100x/SConscript new file mode 100644 index 0000000000000000000000000000000000000000..fe0ae941ae9a759ae478de901caec1c961e56af8 --- /dev/null +++ b/bsp/nv32f100x/SConscript @@ -0,0 +1,14 @@ +# for module compiling +import os +Import('RTT_ROOT') + +cwd = str(Dir('#')) +objs = [] +list = os.listdir(cwd) + +for d in list: + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, 'SConscript')): + objs = objs + SConscript(os.path.join(d, 'SConscript')) + +Return('objs') diff --git a/bsp/nv32f100x/SConstruct b/bsp/nv32f100x/SConstruct new file mode 100644 index 0000000000000000000000000000000000000000..47ac06abf22d1c1279b4855796a0da6e869dd561 --- /dev/null +++ b/bsp/nv32f100x/SConstruct @@ -0,0 +1,34 @@ +import os +import sys +import rtconfig + +if os.getenv('RTT_ROOT'): + RTT_ROOT = os.getenv('RTT_ROOT') +else: + RTT_ROOT = os.path.normpath(os.getcwd() + '/../..') + +sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] +from building import * + +TARGET = 'rtthread-nv32f100x.' + rtconfig.TARGET_EXT + +env = Environment(tools = ['mingw'], + AS = rtconfig.AS, ASFLAGS = rtconfig.AFLAGS, + CC = rtconfig.CC, CCFLAGS = rtconfig.CFLAGS, + AR = rtconfig.AR, ARFLAGS = '-rc', + LINK = rtconfig.LINK, LINKFLAGS = rtconfig.LFLAGS) +env.PrependENVPath('PATH', rtconfig.EXEC_PATH) + +if rtconfig.PLATFORM == 'iar': + env.Replace(CCCOM = ['$CC $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS -o $TARGET $SOURCES']) + env.Replace(ARFLAGS = ['']) + env.Replace(LINKCOM = ['$LINK $SOURCES $LINKFLAGS -o $TARGET --map project.map']) + +Export('RTT_ROOT') +Export('rtconfig') + +# prepare building environment +objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) + +# make a building +DoBuilding(TARGET, objs) diff --git a/bsp/nv32f100x/app/SConscript b/bsp/nv32f100x/app/SConscript new file mode 100644 index 0000000000000000000000000000000000000000..5260088eb380ae013ff73fa250f82033108df319 --- /dev/null +++ b/bsp/nv32f100x/app/SConscript @@ -0,0 +1,15 @@ +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = os.path.join(str(Dir('#')), 'app') + +src = Glob('./src/*.c') + +path = [cwd + '/inc', + cwd + '/..', + ] + +group = DefineGroup('Applications', src, depend = [''], CPPPATH = path) + +Return('group') diff --git a/bsp/nv32f100x/app/src/ledapp.c b/bsp/nv32f100x/app/src/ledapp.c new file mode 100644 index 0000000000000000000000000000000000000000..a52b0eb8a946110c8087787f37b45b6470356586 --- /dev/null +++ b/bsp/nv32f100x/app/src/ledapp.c @@ -0,0 +1,39 @@ +/* + * File : ledapp.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-09-19 Quintin.Z the first version + */ + +#include +#include +#include +#include "board.h" +#include + +#ifdef RT_USING_COMPONENTS_INIT +#include +#endif /* RT_USING_COMPONENTS_INIT */ + +#include "gpio.h" + + +void led_thread_entry(void* parameter) +{ + + GPIO_Init (GPIOA, GPIO_PTB5_MASK, GPIO_PinOutput); + + while(1) + { + GPIO_Toggle (GPIOA, GPIO_PTB5_MASK); + rt_thread_delay(RT_TICK_PER_SECOND / 10); + + } +} diff --git a/bsp/nv32f100x/app/src/main.c b/bsp/nv32f100x/app/src/main.c new file mode 100644 index 0000000000000000000000000000000000000000..b63fa2f4dcd74f5f5fe1bb9e75e7f58576e41517 --- /dev/null +++ b/bsp/nv32f100x/app/src/main.c @@ -0,0 +1,46 @@ +/* + * File : _main.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2008 - 2012, RT-Thread Development Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Change Logs: + * Date Author Notes + * 2015-11-19 Urey the first version + * 2017-09-20 Quintin.Z modify for nv32 + */ +#include "rtthread.h" +#include "finsh.h" + +extern void led_thread_entry(void* parameter); + +int main(void) +{ + rt_thread_t thread; + +#ifdef RT_USING_FINSH + finsh_set_device(RT_CONSOLE_DEVICE_NAME); +#endif + + /* Create led thread */ + thread = rt_thread_create("led", + led_thread_entry, RT_NULL, + 256, 20, 20); + if(thread != RT_NULL) + rt_thread_startup(thread); + + return 0; +} diff --git a/bsp/nv32f100x/board/SConscript b/bsp/nv32f100x/board/SConscript new file mode 100644 index 0000000000000000000000000000000000000000..90fe4bb0070629f499eda36805f8d35fa73411bf --- /dev/null +++ b/bsp/nv32f100x/board/SConscript @@ -0,0 +1,12 @@ +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = os.path.join(str(Dir('#')), 'board') +src = Glob('./src/*.c') +path = [cwd + '/inc' + ] + +group = DefineGroup('Drivers', src, depend = [''], CPPPATH = path) + +Return('group') diff --git a/bsp/nv32f100x/board/inc/board.h b/bsp/nv32f100x/board/inc/board.h new file mode 100644 index 0000000000000000000000000000000000000000..3639fa0b0381c085635fd24366277923639686cd --- /dev/null +++ b/bsp/nv32f100x/board/inc/board.h @@ -0,0 +1,30 @@ +/* + * File : board.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2017, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-09-19 Quintin.Z the first version + */ + +// <<< Use Configuration Wizard in Context Menu >>> +#ifndef __BOARD_H__ +#define __BOARD_H__ + +#include +#include + + +// Internal SRAM memory size[Kbytes] <8> +#define NV32_SRAM_SIZE 8 +#define NV32_SRAM_END (0x1FFFF800 + NV32_SRAM_SIZE * 1024) + +void rt_hw_board_init(void); + + +#endif diff --git a/bsp/nv32f100x/board/inc/drv_uart.h b/bsp/nv32f100x/board/inc/drv_uart.h new file mode 100644 index 0000000000000000000000000000000000000000..d1e0c6c109adbcdc2308f52cb6e7cf3007c09ecb --- /dev/null +++ b/bsp/nv32f100x/board/inc/drv_uart.h @@ -0,0 +1,23 @@ +/* + * File : drv_uart.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2017, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-09-19 Quintin.Z the first version + */ + +#ifndef __DRV_UART_H__ +#define __DRV_UART_H__ + +#include +#include + +void rt_hw_uart_init(void); + +#endif diff --git a/bsp/nv32f100x/board/inc/start.h b/bsp/nv32f100x/board/inc/start.h new file mode 100644 index 0000000000000000000000000000000000000000..5a4f7d0991d9f8af574412c7ffcfd62f80b2927a --- /dev/null +++ b/bsp/nv32f100x/board/inc/start.h @@ -0,0 +1,9 @@ +/****************************************************************************** +* @brief provide high-level startup routines for NV32Fxx. +* +*******************************************************************************/ + +/* Function prototypes */ +void cpu_identify(void); +void flash_identify(void); +void start(void); diff --git a/bsp/nv32f100x/board/inc/sysinit.h b/bsp/nv32f100x/board/inc/sysinit.h new file mode 100644 index 0000000000000000000000000000000000000000..e7606b5a290b3490176bdd35c028e37e40d4bdd9 --- /dev/null +++ b/bsp/nv32f100x/board/inc/sysinit.h @@ -0,0 +1,38 @@ +/****************************************************************************** +* @brief provide system init routine/configuration for KExx. +* +*******************************************************************************/ + +/********************************************************************/ + +#ifndef SYSINIT_H_ +#define SYSINIT_H_ + +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + + +/****************************************************************************** +* Macros +******************************************************************************/ +#define SIM_SCGC_VALUE 0x00003000L + + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ +void sysinit (void); +void enable_abort_button(void); +void end_test(void); + +/********************************************************************/ +#endif /* SYSINIT_H_ */ diff --git a/bsp/nv32f100x/board/src/board.c b/bsp/nv32f100x/board/src/board.c new file mode 100644 index 0000000000000000000000000000000000000000..23ec89f11482b61a424aafd9e53cb37ef3353dd5 --- /dev/null +++ b/bsp/nv32f100x/board/src/board.c @@ -0,0 +1,127 @@ +/* + * File : board.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2017, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-09-19 Quintin.Z the first version + */ + +#include +#include +#include "sysinit.h" +#include "board.h" +#include "drv_uart.h" +#include "nv32.h" + +/* RT_USING_COMPONENTS_INIT */ +#ifdef RT_USING_COMPONENTS_INIT +#include +#endif + + +#define portNVIC_SYSTICK_CTRL ( ( volatile uint32_t *) 0xe000e010 ) +#define portNVIC_SYSTICK_LOAD ( ( volatile uint32_t *) 0xe000e014 ) +#define portNVIC_INT_CTRL ( ( volatile uint32_t *) 0xe000ed04 ) +#define portNVIC_SYSPRI2 ( ( volatile uint32_t *) 0xe000ed20 ) +#define portNVIC_SYSTICK_CLK 0x00000004 +#define portNVIC_SYSTICK_INT 0x00000002 +#define portNVIC_SYSTICK_ENABLE 0x00000001 +#define portNVIC_PENDSVSET 0x10000000 +#define portMIN_INTERRUPT_PRIORITY ( 255UL ) +#define portNVIC_PENDSV_PRI ( portMIN_INTERRUPT_PRIORITY << 16UL ) +#define portNVIC_SYSTICK_PRI ( portMIN_INTERRUPT_PRIORITY << 24UL ) + +#ifdef __CC_ARM +extern int Image$$RW_IRAM1$$ZI$$Limit; +#define NV32_SRAM_BEGIN (&Image$$RW_IRAM1$$ZI$$Limit) +#elif __ICCARM__ +#pragma section="HEAP" +#define NV32_SRAM_BEGIN (__segment_end("HEAP")) +#else +extern int __bss_end; +#define NV32_SRAM_BEGIN (&__bss_end) +#endif + +/******************************************************************************* +* Function Name : assert_failed +* Description : Reports the name of the source file and the source line number +* where the assert error has occurred. +* Input : - file: pointer to the source file name +* - line: assert error line source number +* Output : None +* Return : None +*******************************************************************************/ +void assert_failed(uint8_t* file, uint32_t line) +{ + rt_kprintf("\n\r Wrong parameter value detected on\r\n"); + rt_kprintf(" file %s\r\n", file); + rt_kprintf(" line %d\r\n", line); + + while (1) ; +} + +/** + * This is the timer interrupt service routine. + * + */ +void SysTick_Handler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + rt_tick_increase(); + + /* leave interrupt */ + rt_interrupt_leave(); +} + + +/** + * This function will initial STM32 board. + */ +void rt_hw_board_init() +{ + /* Configure the SysTick */ + *(portNVIC_SYSTICK_LOAD) = ( 40000000 / RT_TICK_PER_SECOND ) - 1UL; + *(portNVIC_SYSTICK_CTRL) = portNVIC_SYSTICK_CLK | portNVIC_SYSTICK_INT | portNVIC_SYSTICK_ENABLE; + + rt_hw_uart_init(); + + /* Call components board initial (use INIT_BOARD_EXPORT()) */ +#ifdef RT_USING_COMPONENTS_INIT + rt_components_board_init(); +#endif + + +#ifdef RT_USING_CONSOLE + rt_console_set_device(RT_CONSOLE_DEVICE_NAME); +#endif + + +#ifdef RT_USING_HEAP + rt_system_heap_init((void*)NV32_SRAM_BEGIN, (void*)NV32_SRAM_END); +#endif + + + + +} + +long cmd_reset(int argc, char** argv) +{ + NVIC_SystemReset(); + + return 0; +} + +FINSH_FUNCTION_EXPORT_ALIAS(cmd_reset, __cmd_reset, Reset Board.); + + + +/*@}*/ diff --git a/bsp/nv32f100x/board/src/drv_uart.c b/bsp/nv32f100x/board/src/drv_uart.c new file mode 100644 index 0000000000000000000000000000000000000000..d8629d804dc593da67833c199a55fbd370b94ad2 --- /dev/null +++ b/bsp/nv32f100x/board/src/drv_uart.c @@ -0,0 +1,189 @@ +/* + * File : drv_uart.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006-2017, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2017-09-19 Quintin.Z the first version + */ + +#include +#include +#include "drv_uart.h" +#include "nv32.h" +#include "uart.h" +#include "sim.h" + +/* NV32 uart driver */ +struct nv32_uart +{ + UART_Type* uart_device; + IRQn_Type irq; +}; + +static rt_err_t nv32_configure(struct rt_serial_device *serial, struct serial_configure *cfg) +{ + struct nv32_uart* uart; + + UART_ConfigBaudrateType uart_config; + + RT_ASSERT(serial != RT_NULL); + RT_ASSERT(cfg != RT_NULL); + + uart = (struct nv32_uart *)serial->parent.user_data; + + uart_config.u32SysClkHz = BUS_CLK_HZ; + uart_config.u32Baudrate = cfg->baud_rate; + + UART_SetBaudrate(uart->uart_device, &uart_config); + + + if (cfg->data_bits == DATA_BITS_8) + { + UART_Set8BitMode(uart->uart_device); + } + else if(cfg->data_bits == DATA_BITS_9) + { + UART_Set9BitMode(uart->uart_device); + } + + if (cfg->stop_bits == STOP_BITS_1) + { + uart->uart_device->BDH &= (~UART_BDH_SBNS_MASK); + } + else if (cfg->stop_bits == STOP_BITS_2) + { + uart->uart_device->BDH |= UART_BDH_SBNS_MASK; + } + + /* Enable receiver and transmitter */ + uart->uart_device->C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK ); + + + UART_EnableInterrupt(UART0, UART_RxBuffFullInt); + NVIC_EnableIRQ(UART0_IRQn); + + + return RT_EOK; +} + +static rt_err_t nv32_control(struct rt_serial_device *serial, int cmd, void *arg) +{ + struct nv32_uart* uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct nv32_uart *)serial->parent.user_data; + + switch (cmd) + { + case RT_DEVICE_CTRL_CLR_INT: + /* disable rx irq */ + NVIC_DisableIRQ(uart->irq); + break; + case RT_DEVICE_CTRL_SET_INT: + /* enable rx irq */ + NVIC_EnableIRQ(uart->irq); + break; + } + + return RT_EOK; +} + +static int nv32_putc(struct rt_serial_device *serial, char c) +{ + struct nv32_uart* uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct nv32_uart *)serial->parent.user_data; + + while (!(uart->uart_device->S1 & UART_S1_TDRE_MASK)); + + uart->uart_device->D = (uint8_t)c; + + return 1; +} + + +static int nv32_getc(struct rt_serial_device *serial) +{ + int ch; + struct nv32_uart* uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct nv32_uart *)serial->parent.user_data; + + ch = -1; + if (uart->uart_device->S1 & UART_S1_RDRF_MASK) + { + ch = uart->uart_device->D; + } + + return ch; +} + +static const struct rt_uart_ops nv32_uart_ops = +{ + nv32_configure, + nv32_control, + nv32_putc, + nv32_getc, +}; + +#ifdef RT_USING_UART0 + +struct nv32_uart uart0 = +{ + UART0, + UART0_IRQn, +}; + +struct rt_serial_device serial0; + +void UART0_IRQHandler(void) +{ + /* enter interrupt */ + rt_interrupt_enter(); + + if(UART0->S1 & UART_S1_RDRF_MASK) + { + rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND); + } + + /* leave interrupt */ + rt_interrupt_leave(); +} + +#endif + + +void rt_hw_uart_init(void) +{ + struct nv32_uart* uart; + struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; + +#ifdef RT_USING_UART0 + uart = &uart0; + + serial0.ops = &nv32_uart_ops; + serial0.config = config; + + + SIM->PINSEL |= SIM_PINSEL_UART0PS_MASK; + + SIM->SCGC |= SIM_SCGC_UART0_MASK; + + uart->uart_device->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK ); + + /* Configure the UART for 8-bit mode, no parity */ + uart->uart_device->C1 = 0; + + rt_hw_serial_register(&serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, uart); +#endif + +} + diff --git a/bsp/nv32f100x/board/src/start.c b/bsp/nv32f100x/board/src/start.c new file mode 100644 index 0000000000000000000000000000000000000000..9fdaeed0c2459c528ac70849025a9d051fa85c16 --- /dev/null +++ b/bsp/nv32f100x/board/src/start.c @@ -0,0 +1,36 @@ +/****************************************************************************** +* @brief provide high-level startup routines for NV32Fxx. +* +*******************************************************************************/ + +#include "start.h" +#include "common.h" +#include "wdog.h" +#include "sysinit.h" + +/********************************************************************/ +/********************************************************************/ +/*! + * \brief flash SystemInit + * \return None + * + * this is a system initialization function which dediu16Cated in Keil + * others complier don't use it. + * it is similar to start function + */ +void SystemInit( void ) +{ +#if !defined(ENABLE_WDOG) + /* Disable the watchdog ETMer */ + WDOG_Disable(); +#else + /* Disable the watchdog ETMer but enable update */ + WDOG_DisableWDOGEnableUpdate(); +#endif + + sysinit(); + +} + + + diff --git a/bsp/nv32f100x/board/src/sysinit.c b/bsp/nv32f100x/board/src/sysinit.c new file mode 100644 index 0000000000000000000000000000000000000000..c31732764382326c069ce31b673345ebd86d325e --- /dev/null +++ b/bsp/nv32f100x/board/src/sysinit.c @@ -0,0 +1,124 @@ +/***************************************************************************** +* @brief provide system init routine/configuration for NV32Fxx. +* +*******************************************************************************/ + +#include "common.h" +#include "sysinit.h" +#include "sim.h" +#include "uart.h" +#include "ics.h" + +/********************************************************************/ + +uint16_t global_pass_count = 0; +uint16_t global_fail_count = 0; + + +void print_sys_log(void); +void UART_InitPrint(void); + +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: sysinit +* +* @brief initalize system including SIM, ICS, UART, etc +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void sysinit (void) +{ + SIM_ConfigType sSIMConfig = {{0}, 0}; + ICS_ConfigType sICSConfig = {0}; + + /* initialize the Pass/Fail counts to 0 */ + global_pass_count = 0; + global_fail_count = 0; + + EFMCR &= 0xFFFF0001; // set wait state 1 + +#if defined(TRIM_IRC) + /* if not trimmed, do trim first */ + ICS_Trim(ICS_TRIM_VALUE); +#endif + /* + * Enable SWD pin, RESET pin + */ + /* + * NOTE: please make sure other register bits are also write-once and + * need add other bit mask here if needed. + */ +#if defined(SPI0_PINREMAP) + sSIMConfig.u32PinSel |= SIM_PINSEL_SPI0PS_MASK; +#endif + +#if defined(OUTPUT_BUSCLK) + sSIMConfig.sBits.bEnableCLKOUT = 1; /* output bus clock if enabled */ +#endif + +#if defined(DISABLE_NMI) + sSIMConfig.sBits.bDisableNMI = 1; +#endif + +#if !defined(CPU_NV32M3) + /* make sure clocks to peripheral modules are enabled */ + sSIMConfig.u32SCGC |= SIM_SCGC_SWD_MASK | SIM_SCGC_FLASH_MASK | + SIM_SCGC_UART0_MASK | SIM_SCGC_UART1_MASK | + SIM_SCGC_UART2_MASK + ; +#else + sSIMConfig.u32SCGC |= SIM_SCGC_SWD_MASK | SIM_SCGC_FLASH_MASK | + SIM_SCGC_UART0_MASK + ; +#endif + +#if !defined(CPU_NV32) + /* bus clock divided by 2 */ + // sSIMConfig.u32BusDiv |= SIM_CLKDIV_OUTDIV2_MASK; +#endif + +// sSIMConfig.sBits.bBusDiv |= SIM_BUSDIV_BUSDIV_MASK; + + SIM_Init(&sSIMConfig); /* initialize SIM */ + +#if defined(XOSC_STOP_ENABLE) + sICSConfig.oscConfig.bStopEnable = 1; /* enabled in stop mode */ +#endif + +#if defined(CRYST_HIGH_GAIN) + sICSConfig.oscConfig.bGain = 1; /* high gain */ +#endif + + +#if (EXT_CLK_FREQ_KHZ >=4000) + sICSConfig.oscConfig.bRange = 1; /* high range */ +#endif + + sICSConfig.oscConfig.bEnable = 1; /* enable OSC */ + sICSConfig.u32ClkFreq = EXT_CLK_FREQ_KHZ; + +#if defined(USE_FEE) + sICSConfig.u8ClkMode = ICS_CLK_MODE_FEE; +#elif defined(USE_FBE_OSC) + sICSConfig.u8ClkMode = ICS_CLK_MODE_FBE_OSC; +#elif defined(USE_FEE_OSC) + sICSConfig.u8ClkMode = ICS_CLK_MODE_FEE_OSC; +#elif defined(USE_FBILP) + sICSConfig.u8ClkMode = ICS_CLK_MODE_FBILP; +#elif defined(USE_FBELP) + sICSConfig.u8ClkMode = ICS_CLK_MODE_FBELP; +#endif + + ICS_Init(&sICSConfig); /* initialize ICS */ + + +} + +void NMI_Handler(void) +{ + while(1); +} diff --git a/bsp/nv32f100x/lib/SConscript b/bsp/nv32f100x/lib/SConscript new file mode 100644 index 0000000000000000000000000000000000000000..9f7810805964b0c8faba5c1edaba3e547ca60e36 --- /dev/null +++ b/bsp/nv32f100x/lib/SConscript @@ -0,0 +1,16 @@ +Import('RTT_ROOT') +Import('rtconfig') +from building import * + +cwd = os.path.join(str(Dir('#')), 'lib') +src = Glob('./src/*.c') + +src += Glob('./src/*.s') +path = [cwd + '/inc' + ] + +CPPDEFINES = ['NV32', 'KEIL'] + +group = DefineGroup('Lib', src, depend = [''], CPPPATH = path, CPPDEFINES = CPPDEFINES) + +Return('group') diff --git a/bsp/nv32f100x/lib/inc/BME.h b/bsp/nv32f100x/lib/inc/BME.h new file mode 100644 index 0000000000000000000000000000000000000000..291cd4a0ad0349d249394dbce6c61da3d3ec5a21 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/BME.h @@ -0,0 +1,606 @@ + +/****************************************************************************** +******************************************************************************/ + +#ifndef __BME_H +#define __BME_H +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* BME operation code +* +*//*! @addtogroup BME_OPCode +* @{ +*******************************************************************************/ + +#define BME_OPCODE_AND 1 /*!< AND opcode */ +#define BME_OPCODE_OR 2 /*!< OR opcode */ +#define BME_OPCODE_XOR 3 /*!< XOR opcode */ +#define BME_OPCODE_BITFIELD 4 /*!< Bit field opcode */ + +#define BME_OPCODE_BIT_CLEAR 2 /*!< Bit clear opcode */ +#define BME_OPCODE_BIT_SET 3 /*!< Bit set opcode */ +/*! @} End of BME_OPCode */ + +/****************************************************************************** +* BME macro used to generate hardcoded BME addresses +* +*//*! @addtogroup BME_Utilities +* @{ +*******************************************************************************/ + +/****************************************************************************** +* macro used to generate hardcoded AND address. +* +*******************************************************************************/ + +/*****************************************************************************//*! + * + * @brief generates BME AND operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ +#define BME_AND(ADDR) (*(volatile uint32_t *)(((uint32_t)ADDR) | (BME_OPCODE_AND<<26))) + +/****************************************************************************** +* macro used to generate hardcoded OR address. +* +*******************************************************************************/ + +/*****************************************************************************//*! + * + * @brief generates BME OR operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_OR(ADDR) (*(volatile uint32_t *)(((uint32_t)ADDR) | (BME_OPCODE_OR<<26))) + + +/****************************************************************************** +* macro used to generate hardcoded XOR address. +* +*******************************************************************************/ + +/*****************************************************************************//*! + * + * @brief generates BME XOR operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_XOR(ADDR) (*(volatile uint32_t *)(((uint32_t)ADDR) | (BME_OPCODE_XOR<<26))) + +#if !defined(BME_SANITY_CHECK) + /*! + * @brief This is fastest way for BME without sanity check. + */ + /****************************************************************************** + * macro used to generate hardcoded load 1 bit clear address (LAC1). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bit clear operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BIT_CLEAR(ADDR,bit) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_CLEAR <<26) \ + | ((bit)<<21))) + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit set address (LAS1). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bit set operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BIT_SET(ADDR,bit) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_SET <<26) \ + | ((bit)<<21))) + + /****************************************************************************** + * macro used to generate hardcoded bit field insert address (BFI). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bitfield insert operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * @param[in] width bitfield width, 1-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + #define BME_BITFIELD_INSERT(ADDR,bit,width) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit)<<23) | ((width-1))<<19)) + + + /****************************************************************************** + * macro used to generate hardcoded bit field extract address (UBFX). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bitfield extract operation addresss (hardcoded 32-bit address). + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * @param[in] width bitfield width, 1-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BITFIELD_EXTRACT(ADDR,bit,width) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit)<<23) | ((width-1))<<19)) +#else + /*! + * @brief This is slow way for BME as it has sanity check. + */ + /****************************************************************************** + * macro used to generate hardcoded load 1 bit clear address (LAC1). + * + *******************************************************************************/ + #define BME_BIT_CLEAR(ADDR,bit) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_CLEAR <<26) \ + | ((bit & 0x1F)<<21))) /*!< Bit clear operation */ + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit set address (LAS1). + * + *******************************************************************************/ + #define BME_BIT_SET(ADDR,bit) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_SET <<26) \ + | ((bit & 0x1F)<<21))) /*!< Bit set operation */ + + /****************************************************************************** + * macro used to generate hardcoded bit field insert address (BFI). + * + *******************************************************************************/ + #define BME_BITFIELD_INSERT(ADDR,bit,width) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit & 0x1F)<<23) | ((width-1) & 0xF)<<19)) /*!< Bitfield insert operation */ + + + /****************************************************************************** + * macro used to generate hardcoded bit field extract address (UBFX). + * + *******************************************************************************/ + #define BME_BITFIELD_EXTRACT(ADDR,bit,width) (*(volatile uint32_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit & 0x1F)<<23) | ((width-1) & 0xF)<<19)) /*!< Bitfield extract operation */ + +#endif + +/****************************************************************************** +* The following macros are used to generate hardcoded address for 8-bit operation. +* +*******************************************************************************/ + +/****************************************************************************** +* macro used to generate hardcoded AND address for 8-bit operation. +* +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief generates BME AND operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_AND_8b(ADDR) (*(volatile uint8_t *)(((uint32_t)ADDR) | (BME_OPCODE_AND<<26))) + +/****************************************************************************** +* macro used to generate hardcoded OR address. +* +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief generates BME OR operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_OR_8b(ADDR) (*(volatile uint8_t *)(((uint32_t)ADDR) | (BME_OPCODE_OR<<26))) + + +/****************************************************************************** +* macro used to generate hardcoded XOR address. +* +*******************************************************************************/ + +/*****************************************************************************//*! + * + * @brief generates BME XOR operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_XOR_8b(ADDR) (*(volatile uint8_t *)(((uint32_t)ADDR) | (BME_OPCODE_XOR<<26))) + +#if !defined(BME_SANITY_CHECK) + /*! + * @brief This is fastest way for BME without sanity check. + */ + /****************************************************************************** + * macro used to generate hardcoded load 1 bit clear address (LAC1). + * + *******************************************************************************/ + + /*****************************************************************************//*! + * + * @brief generates BME bit clear operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BIT_CLEAR_8b(ADDR,bit) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_CLEAR <<26) \ + | ((bit)<<21))) + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit set address (LAS1). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bit set operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BIT_SET_8b(ADDR,bit) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_SET <<26) \ + | ((bit)<<21))) + + /****************************************************************************** + * macro used to generate hardcoded bit field insert address (BFI). + * + *******************************************************************************/ + + /*****************************************************************************//*! + * + * @brief generates BME bitfield insert operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * @param[in] width bitfield width, 1-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BITFIELD_INSERT_8b(ADDR,bit,width) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit)<<23) | ((width-1))<<19)) + /****************************************************************************** + * macro used to generate hardcoded bit field extract address (UBFX). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bitfield extract operation addresss (hardcoded 32-bit address) for 8-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * @param[in] width bitfield width, 1-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + #define BME_BITFIELD_EXTRACT_8b(ADDR,bit,width) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit<<23) | ((width-1))<<19)) +#else + /*! + * @brief This is slow way for BME as it has sanity check. + */ + /****************************************************************************** + * macro used to generate hardcoded load 1 bit clear address (LAC1). + * + *******************************************************************************/ + #define BME_BIT_CLEAR_8b(ADDR,bit) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_CLEAR <<26) \ + | ((bit & 0x1F)<<21))) /*!< Bit clear operation on 8-bit*/ + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit set address (LAS1). + * + *******************************************************************************/ + #define BME_BIT_SET_8b(ADDR,bit) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_SET <<26) \ + | ((bit & 0x1F)<<21))) /*!< Bit set operation on 8-bit */ + + /****************************************************************************** + * macro used to generate hardcoded bit field insert address (BFI). + * + *******************************************************************************/ + #define BME_BITFIELD_INSERT_8b(ADDR,bit,width) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit & 0x1F)<<23) | ((width-1) & 0xF)<<19)) /*!< Bitfield insert operation on 8-bit */ + + /****************************************************************************** + * macro used to generate hardcoded bit field extract address (UBFX). + * + *******************************************************************************/ + + #define BME_BITFIELD_EXTRACT_8b(ADDR,bit,width) (*(volatile uint8_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit & 0x1F)<<23) | ((width-1) & 0xF)<<19)) /*!< Bitfield extract operation on 8-bit*/ +#endif + + +/****************************************************************************** +* The following macros are used to generate hardcoded address for 16-bit operation. +* +*******************************************************************************/ + +/****************************************************************************** +* macro used to generate hardcoded AND address for 16-bit operation. +* +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief generates BME AND operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_AND_16b(ADDR) (*(volatile uint16_t *)(((uint32_t)ADDR) | (BME_OPCODE_AND<<26))) + +/****************************************************************************** +* macro used to generate hardcoded OR address. +* +*******************************************************************************/ + +/*****************************************************************************//*! + * + * @brief generates BME OR operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_OR_16b(ADDR) (*(volatile uint16_t *)(((uint32_t)ADDR) | (BME_OPCODE_OR<<26))) + + +/****************************************************************************** +* macro used to generate hardcoded XOR address. +* +*******************************************************************************/ + +/*****************************************************************************//*! + * + * @brief generates BME XOR operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * +*****************************************************************************/ + +#define BME_XOR_16b(ADDR) (*(volatile uint16_t *)(((uint32_t)ADDR) | (BME_OPCODE_XOR<<26))) + + +#if !defined(BME_SANITY_CHECK) + /*! + * @brief This is fastest way for BME without sanity check. + */ + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit clear address (LAC1). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bit clear operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BIT_CLEAR_16b(ADDR,bit) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_CLEAR <<26) \ + | ((bit)<<21))) + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit set address (LAS1). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bit set operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BIT_SET_16b(ADDR,bit) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_SET <<26) \ + | ((bit)<<21))) + + /****************************************************************************** + * macro used to generate hardcoded bit field insert address (BFI). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bitfield insert operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * @param[in] width bitfield width, 1-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BITFIELD_INSERT_16b(ADDR,bit,width) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit)<<23) | ((width-1))<<19)) + + + /****************************************************************************** + * macro used to generate hardcoded bit field extract address (UBFX). + * + *******************************************************************************/ + /*****************************************************************************//*! + * + * @brief generates BME bitfield extract operation addresss (hardcoded 32-bit address) for 16-bit data. + * + * @param[in] ADDR 32-bit address. + * @param[in] bit bit number, 0-based. + * @param[in] width bitfield width, 1-based. + * + * @return hardcoded 32-bit address. + * + * @ Pass/ Fail criteria: none. + * + *****************************************************************************/ + + #define BME_BITFIELD_EXTRACT_16b(ADDR,bit,width) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit)<<23) | ((width-1))<<19)) + +#else + /*! + * @brief This is slow way for BME as it has sanity check. + */ + /****************************************************************************** + * macro used to generate hardcoded load 1 bit clear address (LAC1). + * + *******************************************************************************/ + #define BME_BIT_CLEAR_16b(ADDR,bit) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_CLEAR <<26) \ + | ((bit & 0x1F)<<21))) /*!< Bit clear operation on 16-bit*/ + + /****************************************************************************** + * macro used to generate hardcoded load 1 bit set address (LAS1). + * + *******************************************************************************/ + #define BME_BIT_SET_16b(ADDR,bit) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BIT_SET <<26) \ + | ((bit & 0x1F)<<21))) /*!< Bit set operation on 16-bit */ + + /****************************************************************************** + * macro used to generate hardcoded bit field insert address (BFI). + * + *******************************************************************************/ + #define BME_BITFIELD_INSERT_16b(ADDR,bit,width) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit & 0x1F)<<23) | ((width-1) & 0xF)<<19)) /*!< Bitfield insert operation on 16-bit */ + + + /****************************************************************************** + * macro used to generate hardcoded bit field extract address (UBFX). + * + *******************************************************************************/ + #define BME_BITFIELD_EXTRACT_16b(ADDR,bit,width) (*(volatile uint16_t *)(((uint32_t)ADDR) \ + | (BME_OPCODE_BITFIELD <<26) \ + | ((bit & 0x1F)<<23) | ((width-1) & 0xF)<<19)) /*!< Bitfield extract operation on 16-bit*/ +#endif + +/*! @} End of BME_Utilities */ +#ifdef __cplusplus +} +#endif +#endif /* __BME_H */ + + diff --git a/bsp/nv32f100x/lib/inc/NV32.h b/bsp/nv32f100x/lib/inc/NV32.h new file mode 100644 index 0000000000000000000000000000000000000000..eb16c781c1bf97ace7e7b49c3410f4d9c0ece3d3 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/NV32.h @@ -0,0 +1,2829 @@ +/* + * @brief CMSIS Peripheral Access Layer for NV32 + * + * CMSIS Peripheral Access Layer for NV32 + */ + +#if !defined(NV32_H_) +#define NV32_H_ /**< Symbol preventing repeated inclusion */ + +/** Memory map major version (memory maps with equal major version number are + * compatible) */ +#define MCU_MEM_MAP_VERSION 0x0100u +/** Memory map minor version */ +#define MCU_MEM_MAP_VERSION_MINOR 0x0004u + + +/* ---------------------------------------------------------------------------- + -- Interrupt vector numbers + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup Interrupt_vector_numbers Interrupt vector numbers + * @{ + */ + +/** Interrupt Number Definitions */ +typedef enum IRQn { + /* Core interrupts */ + NonMaskableInt_IRQn = -14, /**< Non Maskable Interrupt */ + HardFault_IRQn = -13, /**< Cortex-M0 SV Hard Fault Interrupt */ + SVCall_IRQn = -5, /**< Cortex-M0 SV Call Interrupt */ + PendSV_IRQn = -2, /**< Cortex-M0 Pend SV Interrupt */ + SysTick_IRQn = -1, /**< Cortex-M0 System Tick Interrupt */ + + /* Device specific interrupts */ + Reserved16_IRQn = 0, /**< Reserved interrupt 16 */ + Reserved17_IRQn = 1, /**< Reserved interrupt 17 */ + Reserved18_IRQn = 2, /**< Reserved interrupt 18 */ + Reserved19_IRQn = 3, /**< Reserved interrupt 19 */ + Reserved20_IRQn = 4, /**< Reserved interrupt 20 */ + ETMRH_IRQn = 5, /**< ETMRH command complete/read collision interrupt */ + LVD_LVW_IRQn = 6, /**< Low Voltage Detect, Low Voltage Warning */ + IRQ_IRQn = 7, /**< External interrupt */ + I2C0_IRQn = 8, /**< I2C0 interrupt */ + Reserved25_IRQn = 9, /**< Reserved interrupt 25 */ + SPI0_IRQn = 10, /**< SPI0 interrupt */ + SPI1_IRQn = 11, /**< SPI1 interrupt */ + UART0_IRQn = 12, /**< UART0 status/error interrupt */ + UART1_IRQn = 13, /**< UART1 status/error interrupt */ + UART2_IRQn = 14, /**< UART2 status/error interrupt */ + ADC0_IRQn = 15, /**< ADC0 interrupt */ + ACMP0_IRQn = 16, /**< ACMP0 interrupt */ + ETM0_IRQn = 17, /**< ETM0 Single interrupt vector for all sources */ + ETM1_IRQn = 18, /**< ETM1 Single interrupt vector for all sources */ + ETM2_IRQn = 19, /**< ETM2 Single interrupt vector for all sources */ + RTC_IRQn = 20, /**< RTC overflow */ + ACMP1_IRQn = 21, /**< ACMP1 interrupt */ + PIT_CH0_IRQn = 22, /**< PIT CH0 overflow */ + PIT_CH1_IRQn = 23, /**< PIT CH1 overflow */ + KBI0_IRQn = 24, /**< Keyboard interrupt 0 */ + KBI1_IRQn = 25, /**< Keyboard interrupt 1 */ + Reserved42_IRQn = 26, /**< Reserved interrupt 42 */ + ICS_IRQn = 27, /**< ICS interrupt */ + Watchdog_IRQn = 28, /**< WDOG Interrupt */ + Reserved45_IRQn = 29, /**< Reserved interrupt 45 */ + Reserved46_IRQn = 30, /**< Reserved interrupt 46 */ + Reserved47_IRQn = 31 /**< Reserved interrupt 47 */ +} IRQn_Type; + +/*! + * @} + */ /* end of group Interrupt_vector_numbers */ + + +/* ---------------------------------------------------------------------------- + -- Cortex M0 Core Configuration + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup Cortex_Core_Configuration Cortex M0 Core Configuration + * @{ + */ + +#define __CM0PLUS_REV 0x0000 /**< Core revision r0p0 */ +#define __MPU_PRESENT 0 /**< Defines if an MPU is present or not */ +#define __VTOR_PRESENT 1 /**< Defines if an MPU is present or not */ +#define __NVIC_PRIO_BITS 2 /**< Number of priority bits implemented in the NVIC */ +#define __Vendor_SysTickConfig 0 /**< Vendor specific implementation of SysTickConfig is defined */ + +#include "core_cm0plus.h" /* Core Peripheral Access Layer */ +//#include "system_nv32.h" /* Device specific configuration file */ + +/*! + * @} + */ /* end of group Cortex_Core_Configuration */ + + +/* ---------------------------------------------------------------------------- + -- Device Peripheral Access Layer + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup Peripheral_access_layer Device Peripheral Access Layer + * @{ + */ + + +/* +** Start of section using anonymous unions +*/ + +#if defined(__ARMCC_VERSION) + #pragma push + #pragma anon_unions +#elif defined(__CWCC__) + #pragma push + #pragma cpp_extensions on +#elif defined(__GNUC__) + /* anonymous unions are enabled by default */ +#elif defined(__IAR_SYSTEMS_ICC__) + #pragma language=extended +#else + #error Not supported compiler type +#endif + +/* ---------------------------------------------------------------------------- + -- ACMP Peripheral Access Layer + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup ACMP_Peripheral_Access_Layer ACMP Peripheral Access Layer + * @{ + */ + +/** ACMP - Register Layout Typedef */ +typedef struct { + __IO uint8_t CS; /**< ACMP Control and Status Register, offset: 0x0 */ + __IO uint8_t C0; /**< ACMP Control Register 0, offset: 0x1 */ + __IO uint8_t C1; /**< ACMP Control Register 1, offset: 0x2 */ + __IO uint8_t C2; /**< ACMP Control Register 2, offset: 0x3 */ +} ACMP_Type; + +/* ---------------------------------------------------------------------------- + -- ACMP Register Masks + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup ACMP_Register_Masks ACMP Register Masks + * @{ + */ + +/* CS Bit Fields */ +#define ACMP_CS_ACMOD_MASK 0x3u +#define ACMP_CS_ACMOD_SHIFT 0 +#define ACMP_CS_ACMOD(x) (((uint8_t)(((uint8_t)(x))<EFMCR) +#define EFM_SEC0_reg(base) ((base)->EFMSEC0) +#define EFM_SEC1_reg(base) ((base)->EFMSEC1) +#define EFM_SEC2_reg(base) ((base)->EFMSEC2) +#define EFM_ETM0_reg(base) ((base)->EFMETM0) +#define EFM_ETM1_reg(base) ((base)->EFMETM1) +#define EFM_CMD_reg(base) ((base)->EFMCMD) + +/** Peripheral Map **/ +#define ETMRH ((ETMRH_MemMapPtr)0x40020000u) + + +#define ETMRH_FCLKDIV_FDIVLD_MASK 0x80u +#define ETMRH_FSTAT_CCIF_MASK 0x80u +#define ETMRH_FSTAT_ACCERR_MASK 0x20u +#define ETMRH_FSTAT_FPVIOL_MASK 0x10u +#define ETMRH_FSTAT_MGSTAT_MASK 0x3u +#define ETMRH_ERROR (ETMRH_FSTAT_ACCERR_MASK | ETMRH_FSTAT_FPVIOL_MASK | ETMRH_FSTAT_MGSTAT_MASK) +#define ETMRH_FCCOB *((volatile uint16_t *)(0x0a + 0x40020000)) + +#define EFMCR EFM_CR_reg(ETMRH) +#define EFMSEC0 EFM_SEC0_reg(ETMRH) +#define EFMSEC1 EFM_SEC1_reg(ETMRH) +#define EFMSEC2 EFM_SEC2_reg(ETMRH) +#define EFMETM0 EFM_ETM0_reg(ETMRH) +#define EFMETM1 EFM_ETM1_reg(ETMRH) +#define EFMCMD EFM_CMD_reg(ETMRH) + +typedef struct NVR_BKDOOR_MemMap{ + volatile unsigned long Custombkd; +} *NVR_BKDOOR_MemMapPtr; + + +#define Custombkd_reg(base) ((base)->Custombkd) +#define NVR_BKDOOR ((NVR_BKDOOR_MemMapPtr)0x40020038u) + +#define Custombkd Custombkd_reg(NVR_BKDOOR) + +/*! + * @} + */ /* end of group ETMRH_Peripheral_Access_Layer */ + + +/* ---------------------------------------------------------------------------- + -- GPIO Peripheral Access Layer + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup GPIO_Peripheral_Access_Layer GPIO Peripheral Access Layer + * @{ + */ + +/** GPIO - Register Layout Typedef */ +typedef struct { + __IO uint32_t PDOR; /**< Port Data Output Register, offset: 0x0 */ + __O uint32_t PSOR; /**< Port Set Output Register, offset: 0x4 */ + __O uint32_t PCOR; /**< Port Clear Output Register, offset: 0x8 */ + __O uint32_t PTOR; /**< Port Toggle Output Register, offset: 0xC */ + __I uint32_t PDIR; /**< Port Data Input Register, offset: 0x10 */ + __IO uint32_t PDDR; /**< Port Data Direction Register, offset: 0x14 */ + __IO uint32_t PIDR; /**< Port Input Disable Register, offset: 0x18 */ +} GPIO_Type; + +/* ---------------------------------------------------------------------------- + -- GPIO Register Masks + ---------------------------------------------------------------------------- */ + +/*! + * @addtogroup GPIO_Register_Masks GPIO Register Masks + * @{ + */ + +/* PDOR Bit Fields */ +#define GPIO_PDOR_PDO_MASK 0xFFFFFFFFu +#define GPIO_PDOR_PDO_SHIFT 0 +#define GPIO_PDOR_PDO(x) (((uint32_t)(((uint32_t)(x))< + +#define CPU_NV32 +#define TEST + + +//#define TRIM_IRC /*!< ÊÇ·ñʹÓö¨ÒåµÄTRIMÖµÀ´Ð£×¼ÄÚ²¿IRC£¬Èô×¢ÊÍÔòʹÓóö³§Ð£×¼µÄTRIMÖµ³ö³§Ð£×¼ÖÁ37.5K--48M */ +//#define SPI0_PINREMAP /*!< SPI0µÄ¹Ü½ÅÓ³É䶨Òå */ +//#define ENABLE_WDOG /*!< ʹÄÜ¿´ÃŹ· */ +//#define DISABLE_NMI /*!< ½ûÓÃNMIÖжÏÊäÈëÒý½Å */ + +/*! ¶¨ÒåÊÇ·ñ´òӡϵͳÐÅÏ¢ */ +//#define PRINT_SYS_LOG + +#if !defined(BOOT_LOADER) +#endif + +//#define OUTPUT_BUSCLK /*!< ¶¨ÒåÊÇ·ñÊä³öϵͳʱÖÓ£¬Êä³öÒý½ÅΪPH2 */ +#define ICS_TRIM_VALUE 0x2c + + + /*! ¶¨ÒåʱÖÓµÄʱÖÓģʽÒÔ¼°ÆµÂÊ + */ + //#define USE_FEE /*!< ʹÓÃÍⲿʱÖÓFEEģʽ */ + //#define USE_FEE_OSC /*!< ʹÓÃÍⲿʱÖÓÊäÈëOSCģʽ */ + #define USE_FEI /*!< ʹÓÃϵͳÄÚ²¿Ê±ÖÓIRC */ + // #define USE_FBELP + //#define USE_FBE_OSC + + /*! ¶¨ÒåÍⲿ¾§ÕñƵÂÊ. */ + //#define EXT_CLK_FREQ_KHZ 32 /* in KHz */ + //#define EXT_CLK_FREQ_KHZ 4000 /* in KHz */ + //#define EXT_CLK_FREQ_KHZ 4000 /* in KHz */ + //#define EXT_CLK_FREQ_KHZ 1000 /* in KHz */ + #define EXT_CLK_FREQ_KHZ 10000 /* in KHz */ + /*! ¶¨ÒåËùʹÓõÄUART¿Ú */ + #define TERM_PORT UART1 /*!< ¶¨ÒåʹÓÃUART1¿Ú£¬¿ª·¢°åÉÏĬÈÏʹÓÃUART1¿Ú */ + + + /* ¶¨Òå×ÜÏßʱÖÓÖ÷Ƶ */ + #if defined(USE_FEI) + #define BUS_CLK_HZ 40000000L + + #elif (EXT_CLK_FREQ_KHZ == 10000) + #define BUS_CLK_HZ 50000000L + #elif (EXT_CLK_FREQ_KHZ == 12000) + #define BUS_CLK_HZ 30000000L + #elif (EXT_CLK_FREQ_KHZ == 8000) + #define BUS_CLK_HZ 24000000L + #elif (EXT_CLK_FREQ_KHZ == 4000) + #define BUS_CLK_HZ 40000000L + #elif (EXT_CLK_FREQ_KHZ == 32) + #define BUS_CLK_HZ 16777216L + #else + #define BUS_CLK_HZ 60000000L + #endif + + /*! define UART baud rate */ + #define UART_PRINT_BITRATE 115200 /*! UART²¨ÌØÂÊ */ + + +#endif /* NVxx_CONFIG_H_ */ diff --git a/bsp/nv32f100x/lib/inc/acmp.h b/bsp/nv32f100x/lib/inc/acmp.h new file mode 100644 index 0000000000000000000000000000000000000000..7b06be070e6f9de281c138809d6c8bf26620f111 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/acmp.h @@ -0,0 +1,568 @@ +/****************************************************************************** +* @brief header file for ACMP utilities. +* +******************************************************************************* +* +* provide APIs for accessing ACMP +******************************************************************************/ +#ifndef _MY_ACMP_H_ +#define _MY_ACMP_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/* DAC reference select */ +enum +{ + DAC_REF_BANDGAP = 0, + DAC_REF_VDDA +}; + +/****************************************************************************** +* Macros +******************************************************************************/ + +/****************************************************************************** + * ACMP module number definition * + ******************************************************************************/ +#define MAX_ACMP_NO 2 + +/****************************************************************************** +* ACMP positive and negative pin select definition +* +*//*! @addtogroup acmp_pinsel_list +* @{ +*******************************************************************************/ +#define ACMP_INPUT_P_EXT0 (0<<4) /*!< positive pin select external pin 0 */ +#define ACMP_INPUT_P_EXT1 (1<<4) /*!< positive pin select external pin 1 */ +#define ACMP_INPUT_P_EXT2 (2<<4) /*!< positive pin select external pin 2 */ +#define ACMP_INPUT_P_DAC (3<<4) /*!< positive pin select internal DAC */ + +#define ACMP_INPUT_N_EXT0 0 /*!< positive pin select external pin 0 */ +#define ACMP_INPUT_N_EXT1 1 /*!< positive pin select external pin 1 */ +#define ACMP_INPUT_N_EXT2 2 /*!< positive pin select external pin 2 */ +#define ACMP_INPUT_N_DAC 3 /*!< positive pin select internal DAC */ +/*! @} End of acmp_pinsel_list */ + +/****************************************************************************** +* ACMP interrupt sensitivity edge definition +* +*//*! @addtogroup acmp_intedgesel +* @{ +*******************************************************************************/ +#define ACMP_SENSITIVITYMODE_FALLING 0 /*!< interrupt on falling edge */ +#define ACMP_SENSITIVITYMODE_RISING 1 /*!< interrupt on rising edge */ +#define ACMP_SENSITIVITYMODE_ANY 3 /*!< interrupt on falling or rising edge */ +/*! @} End of acmp_intedgesel */ + + +/****************************************************************************** +* ACMP hysterisis selection definition +* +*//*! @addtogroup acmp_hyst +* @{ +*******************************************************************************/ +#define ACMP_HYST_20MV (0<<6) /*!< 20mv hyst */ +#define ACMP_HYST_30MV (1<<6) /*!< 30mv hyst */ +/*! @} End of acmp_hyst */ + + +/****************************************************************************** +* ACMP internal DAC reference selection definition +* +*//*! @addtogroup acmp_dacref +* @{ +*******************************************************************************/ +#define ACMP_DAC_REFERENCE_BANDGAP (0<<6) /*!< select bandgap as refference */ +#define ACMP_DAC_REFERENCE_VDDA (1<<6) /*!< select VDDA as refference */ +/*! @} End of acmp_dacref */ + + +/****************************************************************************** +* Types +******************************************************************************/ + +/*! @brief ACMP_CALLBACK function declaration */ +typedef void (*ACMP_CallbackPtr)(void); +/*! @} End of acmp_callback */ + +/****************************************************************************** +* ACMP control status struct +* +*//*! @addtogroup acmp_ctrlstatusstruct +* @{ +*******************************************************************************/ +/*! + * @brief ACMP control and status fields type. + * + */ + +typedef union +{ + uint8_t byte; /*!< byte field of union type */ + struct + { + uint8_t bMod : 2; /*!< Sensitivity modes of the interrupt trigger */ + uint8_t bOutEn : 1; /*!< Output can be placed onto an external pin */ + uint8_t bOutState : 1; /*!< The current value of the analog comparator output */ + uint8_t bIntEn : 1; /*!< ACMP interrupt enable */ + uint8_t bIntFlag : 1; /*!< ACMP Interrupt Flag Bit */ + uint8_t bHyst : 1; /*!< Selects ACMP hystersis */ + uint8_t bEn : 1; /*!< Enables the ACMP module */ + }bits; /*!< bitfield of union type */ +}ACMP_CtrlStatusType, *ACMP_CtrlStatusPtr; /*!< ACMP Control/Status reg structure */ +/*! @} End of acmp_ctrlstatusstruct */ + +/****************************************************************************** +* ACMP pin select struct +* +*//*! @addtogroup acmp_pinselectstruct +* @{ +*******************************************************************************/ +/*! +* @brief ACMP external pins control struct. +* +*/ + +typedef union +{ + uint8_t byte; /*!< byte field of union type */ + struct + { + uint8_t bNegPin : 2; /*!< Negative pin select */ + uint8_t : 2; + uint8_t bPosPin : 2; /*!< Positive pin select */ + uint8_t : 2; + }bits; /*!< bitfield of union type */ +}ACMP_PinSelType, *ACMP_PinSelPtr; /*!< ACMP Pin select structure */ +/*! @} End of acmp_pinselectstruct */ + +/****************************************************************************** +* ACMP DAC control struct +* +*//*! @addtogroup acmp_dacctrlstruct +* @{ +*******************************************************************************/ +/*! +* @brief ACMP internal ADC control struct. +* +*/ +typedef union +{ + uint8_t byte; /*!< byte field of union type */ + struct + { + uint8_t bVal : 6; /*!< 6 bit DAC value */ + uint8_t bRef : 1; /*!< 6 bit DAC reference select */ + uint8_t bEn : 1; /*!< 6 bit DAC enable bit */ + }bits; /*!< bitfield of union type */ +}ACMP_DACType, *ACMP_DACPtr; /*!< ACMP DAC control structure */ +/*! @} End of acmp_dacctrlstruct */ + +/****************************************************************************** +* ACMP pin enable union +* +*//*! @addtogroup acmp_pinenunion +* @{ +*******************************************************************************/ +/*! +* @brief ACMP external input pin enable control struct. +* +*/ +typedef union +{ + uint8_t byte; /*!< byte field of union type */ + struct + { + uint8_t bEn : 3; /*!< ACMP external input pin enable */ + uint8_t bRsvd : 5; + }bits; /*!< bitfield of union type */ +}ACMP_PinEnType, *ACMP_PinEnPtr; /*!< ACMP Pin enable structure */ +/*! @} End of acmp_pinenunion */ + +/****************************************************************************** +* ACMP config struct +* +*//*! @addtogroup acmp_configstruct +* @{ +*******************************************************************************/ +/*! +* @brief ACMP module configuration struct. +* +*/ + +typedef struct +{ + ACMP_CtrlStatusType sCtrlStatus; /*!< ACMP control and status */ + ACMP_PinSelType sPinSelect; /*!< ACMP pin select */ + ACMP_DACType sDacSet; /*!< ACMP internal dac set */ + ACMP_PinEnType sPinEnable; /*!< ACMP external pin control */ +}ACMP_ConfigType, *ACMP_ConfigPtr; +/*! @} End of acmp_configstruct */ + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/*! + * inline functions + */ +/****************************************************************************** +* ACMP api list. +* +*//*! @addtogroup acmp_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! +* +* @brief enable the acmp module. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_Disable. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_Enable(ACMP_Type *pACMPx) +{ + pACMPx->CS |= ACMP_CS_ACE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable the acmp module. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_Enable. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_Disable(ACMP_Type *pACMPx) +{ + pACMPx->CS &= ~ACMP_CS_ACE_MASK; +} + +/*****************************************************************************//*! +* +* @brief select sensitivity modes of the interrupt trigger. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8EdgeSelect falling or rising selction, 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_SelectIntMode(ACMP_Type *pACMPx, uint8_t u8EdgeSelect) +{ + pACMPx->CS &= ~ACMP_CS_ACMOD_MASK; + pACMPx->CS |= ACMP_CS_ACMOD(u8EdgeSelect & 0x3); +} + +/*****************************************************************************//*! +* +* @brief enable the ACMP module analog comparator output. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_DisablePinOut. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_EnablePinOut(ACMP_Type *pACMPx) +{ + pACMPx->CS |= ACMP_CS_ACOPE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable the ACMP module analog comparator output. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_EnablePinOut. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_DisablePinOut(ACMP_Type *pACMPx) +{ + pACMPx->CS &= ~ACMP_CS_ACOPE_MASK; +} + +/*****************************************************************************//*! +* +* @brief select ACMP hystersis. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8HystSelect ACMP_HYST_20MV or ACMP_HYST_30MV. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_SelectHyst(ACMP_Type *pACMPx, uint8_t u8HystSelect) +{ + pACMPx->CS &= ~ACMP_CS_HYST_MASK; + pACMPx->CS |= u8HystSelect; +} + +/*****************************************************************************//*! +* +* @brief enable the acmp module interrupt. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_DisableInterrupt. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_EnableInterrupt(ACMP_Type *pACMPx) +{ + pACMPx->CS |= ACMP_CS_ACIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable the acmp module interrupt. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_EnableInterrupt. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_DisableInterrupt(ACMP_Type *pACMPx) +{ + pACMPx->CS &= ~ACMP_CS_ACIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief get the interrupt flag bit. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_ClrFlag. +* +*****************************************************************************/ +__STATIC_INLINE uint8_t ACMP_GetFlag(ACMP_Type *pACMPx) +{ + return (pACMPx->CS & ACMP_CS_ACF_MASK); +} + +/*****************************************************************************//*! +* +* @brief clear the interrupt flag bit. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_GetFlag. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_ClrFlag(ACMP_Type *pACMPx) +{ + pACMPx->CS &= ~ACMP_CS_ACF_MASK; +} + +/*****************************************************************************//*! +* +* @brief ACMP Positive Input Select. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8PosPinSel positive input select, ACMP_INPUT_P_EXT0~2 or ACMP_INPUT_P_DAC. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_NegativeInputSelect. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_PositiveInputSelect(ACMP_Type *pACMPx, uint8_t u8PosPinSel) +{ + pACMPx->C0 &= ~ACMP_C0_ACPSEL_MASK; + pACMPx->C0 |= u8PosPinSel; +} + +/*****************************************************************************//*! +* +* @brief ACMP Negative Input Select. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8NegPinSel negative input select, ACMP_INPUT_N_EXT0~2 or ACMP_INPUT_N_DAC. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_PositiveInputSelect. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_NegativeInputSelect(ACMP_Type *pACMPx, uint8_t u8NegPinSel) +{ + pACMPx->C0 &= ~ACMP_C0_ACNSEL_MASK; + pACMPx->C0 |= u8NegPinSel; +} + +/*****************************************************************************//*! +* +* @brief Enable 6 bit DAC in ACMP module. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_DacDisable. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_DacEnable(ACMP_Type *pACMPx) +{ + pACMPx->C1 |= ACMP_C1_DACEN_MASK; +} + +/*****************************************************************************//*! +* +* @brief Disable 6 bit DAC in ACMP module. +* +* @param[in] pACMPx pointer to an ACMP module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_DacEnable. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_DacDisable(ACMP_Type *pACMPx) +{ + pACMPx->C1 &= ~ACMP_C1_DACEN_MASK; +} + +/*****************************************************************************//*! +* +* @brief ACMP 6 bit DAC Reference Select. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8RefSelect dac reference select:ACMP_DAC_REFERENCE_BANDGAP or ACMP_DAC_REFERENCE_VDDA. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_DacReferenceSelect(ACMP_Type *pACMPx, uint8_t u8RefSelect) +{ + pACMPx->C1 &= ~ACMP_C1_DACREF_MASK; + pACMPx->C1 |= u8RefSelect; +} + +/*****************************************************************************//*! +* +* @brief ACMP 6 bit DAC Output Value Set. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8DacValue dac output set, Voutput= (Vin/64)x(DACVAL[5:0]+1). +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_DacOutputSet(ACMP_Type *pACMPx, uint8_t u8DacValue) +{ + ASSERT(!(u8DacValue & (~ACMP_C1_DACVAL_MASK))); + pACMPx->C1 &= ~ACMP_C1_DACVAL_MASK; + pACMPx->C1 |= ACMP_C1_DACVAL(u8DacValue); +} + +/*****************************************************************************//*! +* +* @brief Enable ACMP input pin. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8InputPin ACMP external pin, 0~2. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_InputPinEnable(ACMP_Type *pACMPx, uint8_t u8InputPin) +{ + ASSERT(!(u8InputPin & (~ACMP_C2_ACIPE_MASK))); + pACMPx->C2 |= ACMP_C2_ACIPE(u8InputPin); +} + +/*****************************************************************************//*! +* +* @brief Disable ACMP input pin. +* +* @param[in] pACMPx pointer to an ACMP module. +* @param[in] u8InputPin ACMP external pin, 0~2. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +__STATIC_INLINE void ACMP_InputPinDisable(ACMP_Type *pACMPx, uint8_t u8InputPin) +{ + ASSERT(!(u8InputPin & (~ACMP_C2_ACIPE_MASK))); + pACMPx->C2 &= ~ACMP_C2_ACIPE(u8InputPin); +} + +/*! @} End of acmp_api_list */ + +/****************************************************************************** +* Global functions +******************************************************************************/ +void ACMP_Init(ACMP_Type *pACMPx, ACMP_ConfigType *pConfig); +void ACMP_DeInit(ACMP_Type *pACMPx); +void ACMP_ConfigDAC(ACMP_Type *pACMPx, ACMP_DACType *pDACConfig); +void ACMP_SetCallback(ACMP_Type *pACMPx, ACMP_CallbackPtr pfnCallback); + +#ifdef __cplusplus +} +#endif +#endif /* _MY_ACMP_H_ */ + + + diff --git a/bsp/nv32f100x/lib/inc/adc.h b/bsp/nv32f100x/lib/inc/adc.h new file mode 100644 index 0000000000000000000000000000000000000000..31babb0a5810f2730438cdc5685d87b9e6d7267d --- /dev/null +++ b/bsp/nv32f100x/lib/inc/adc.h @@ -0,0 +1,711 @@ +/****************************************************************************** +* +* @brief header file for ADC module utilities (ADC). +* +******************************************************************************* +* +* provide APIs for accessing ADC module (ADC) +******************************************************************************/ + +#ifndef ADC_H_ +#define ADC_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Macros +******************************************************************************/ +/****************************************************************************** +*define ADC refernce voltage +* +*//*! @addtogroup adc_ref_list +* @{ +*******************************************************************************/ + +#define ADC_VREF_VREFH 0x00 /*!< ADC reference voltage is VREFH*/ +#define ADC_VREF_VDDA 0x01 /*!< ADC reference voltage is VDDA*/ + +/*! @} End of adc_ref_list */ + +/****************************************************************************** +* define ADC clock source +* +*//*! @addtogroup adc_clock_source_list +* @{ +*******************************************************************************/ + +#define CLOCK_SOURCE_BUS_CLOCK 0x00 /*!< ADC clock source is bus clock*/ +#define CLOCK_SOURCE_BUS_CLOCK_DIVIDE_2 0x01 /*!< ADC clock source is bus clock devided by 2*/ +#define CLOCK_SOURCE_ALTCLK 0x02 /*!< ADC clock source is alternative clcok*/ +#define CLOCK_SOURCE_ADACK 0x03 /*!< ADC clock source is asynchronous clock*/ +/*! @} End of adc_clock_source_list */ + + +/****************************************************************************** +* define ADC divider +* +*//*! @addtogroup adc_clock_divider_list +* @{ +*******************************************************************************/ + +#define ADC_ADIV_DIVIDE_1 0x00 /*!< ADC clock divide by 1*/ +#define ADC_ADIV_DIVIDE_2 0x01 /*!< ADC clock divide by 2*/ +#define ADC_ADIV_DIVIDE_4 0x02 /*!< ADC clock divide by 4*/ +#define ADC_ADIV_DIVIDE_8 0x03 /*!< ADC clock divide by 8*/ +/*! @} End of adc_clock_divider_list */ + +/****************************************************************************** +* define ADC mode +* +*//*! @addtogroup adc_mode_list +* @{ +*******************************************************************************/ + +#define ADC_MODE_8BIT 0x00 /*!< ADC 8bit mode*/ +#define ADC_MODE_10BIT 0x01 /*!< ADC 10bit mode*/ +#define ADC_MODE_12BIT 0x02 /*!< ADC 12bit mode */ +/*! @} End of adc_mode_list */ + +/****************************************************************************** +* define ADC channel +* +*//*! @addtogroup adc_channel_list +* @{ +*******************************************************************************/ + +#define ADC_CHANNEL_AD0 0x0 /*!< ADC input channel 0 */ +#define ADC_CHANNEL_AD1 0x1 /*!< ADC input channel 1 */ +#define ADC_CHANNEL_AD2 0x2 /*!< ADC input channel 2 */ +#define ADC_CHANNEL_AD3 0x3 /*!< ADC input channel 3 */ +#define ADC_CHANNEL_AD4 0x4 /*!< ADC input channel 4 */ +#define ADC_CHANNEL_AD5 0x5 /*!< ADC input channel 5 */ +#define ADC_CHANNEL_AD6 0x6 /*!< ADC input channel 6 */ +#define ADC_CHANNEL_AD7 0x7 /*!< ADC input channel 7 */ +#define ADC_CHANNEL_AD8 0x8 /*!< ADC input channel 8 */ +#define ADC_CHANNEL_AD9 0x9 /*!< ADC input channel 9 */ +#define ADC_CHANNEL_AD10 0xa /*!< ADC input channel 10 */ +#define ADC_CHANNEL_AD11 0xb /*!< ADC input channel 11 */ +#define ADC_CHANNEL_AD12 0xc /*!< ADC input channel 12 */ +#define ADC_CHANNEL_AD13 0xd /*!< ADC input channel 13 */ +#define ADC_CHANNEL_AD14 0xe /*!< ADC input channel 14 */ +#define ADC_CHANNEL_AD15 0xf /*!< ADC input channel 15 */ +#define ADC_CHANNEL_AD18_VSS 0x12 /*!< ADC input channel VSS */ +#define ADC_CHANNEL_AD22_TEMPSENSOR 0x16 /*!< ADC input channel internal temperature sensor */ +#define ADC_CHANNEL_AD23_BANDGAP 0x17 /*!< ADC input channel bandgap */ +#define ADC_CHANNEL_AD29_VREFH 0x1D /*!< ADC input channel Vrefh */ +#define ADC_CHANNEL_AD30_VREFL 0x1E /*!< ADC input channel Vrefl */ +#define ADC_CHANNEL_DISABLE 0x1F /*!< ADC disable */ +/*! @} End of adc_channel_list */ + + +/****************************************************************************** +* define ADC FIFO_LEVEL +* +*//*! @addtogroup adc_fifo_level_list +* @{ +*******************************************************************************/ +#define ADC_FIFO_DISABLE 0 /*!< FIFO Level 0 */ +#define ADC_FIFO_LEVEL2 1 /*!< FIFO Level 1 */ +#define ADC_FIFO_LEVEL3 2 /*!< FIFO Level 2 */ +#define ADC_FIFO_LEVEL4 3 /*!< FIFO Level 3 */ +#define ADC_FIFO_LEVEL5 4 /*!< FIFO Level 4 */ +#define ADC_FIFO_LEVEL6 5 /*!< FIFO Level 5 */ +#define ADC_FIFO_LEVEL7 6 /*!< FIFO Level 6 */ +#define ADC_FIFO_LEVEL8 7 /*!< FIFO Level 7 */ +/*! @} End of adc_fifo_level_list */ + + +/****************************************************************************** +* define ADC trigger source +* +*//*! @addtogroup adc_trigger_list +* @{ +*******************************************************************************/ +#define ADC_HARDWARE_TRIGGER 0x01 /*!< hardware trigger */ +#define ADC_SOFTWARE_TRIGGER 0x00 /*!< software trigger */ +#define ADC_TRIGGER_RTC 0x00 /*!< RTC act as trigger source */ +#define ADC_TRIGGER_PIT 0x01 /*!< PIT act as trigger source */ +#define ADC_TRIGGER_ETM2INIT 0x10 /*!< ETM2 initialization act as trigger source */ +#define ADC_TRIGGER_ETM2MATCH 0x11 /*!< ETM2 match interrupt act as trigger source */ +/*! @} End of adc_trigger_list */ + + +#define ADC_COMPARE_LESS 0x00 +#define ADC_COMPARE_GREATER 0x01 + + +/****************************************************************************** +* define ADC call back +* +*//*! @addtogroup adc_callback +* @{ +*******************************************************************************/ +typedef void (*ADC_CallbackType)(void); /*!< ADC call back function */ +/*! @} End of adc_callback */ + +/****************************************************************************** +* +* +*//*! @addtogroup adc_setting_type +* @{ +*******************************************************************************/ +/*! + * @brief ADC setting type. + * + */ +typedef struct +{ + uint16_t bIntEn :1; /*!< 1: Interrupt Enable, 0: Interrupt disable */ + uint16_t bContinuousEn :1; /*!< 1: Continuous Conversion Enable, 0: Continuous Conversion disable */ + uint16_t bHardwareTriggerEn :1; /*!< 1: hardware trigger, 0: software trigger */ + uint16_t bCompareEn :1; /*!< 1: compare mode Enable, 0: compare mode disable */ + uint16_t bCompareGreaterEn :1; /*!< 1: Compare greater mode, 0: compare less than mode */ + uint16_t bLowPowerEn :1; /*!< 1: Low power mode, 0: high speed mode */ + uint16_t bLongSampleEn :1; /*!< 1: long sample mode, 0: short sample mode */ + uint16_t bFiFoScanModeEn :1; /*!< 1: FIFO scan mode enable, 0: FIFO scan mode disable */ + uint16_t bCompareAndEn :1; /*!< 1: Compare and logic, 0: Compare and logic */ +#ifdef CPU_NV32 + uint16_t bReverse :7; +#else + uint16_t bHTRGMEn :1; /*!< one hardware trigger pulse trigger multiple conversions in fifo mode */ + uint16_t bHTRGMASKEn :1; /*!< Hardware trigger mask enable. */ + uint16_t bHTRGMASKSEL :1; /*!< This field selects hardware trigger mask mode. */ + uint16_t Reserve :4; +#endif +}ADC_SettingType; +/*! @} End of adc_setting_type */ + +/****************************************************************************** +* +* +*//*! @addtogroup adc_config_type +* @{ +*******************************************************************************/ +/*! + * @brief ADC configure type. + * + */ +typedef struct +{ + ADC_SettingType sSetting; /*!< ADC setting structure*/ + uint16_t u16PinControl; /*!< pin control */ + uint8_t u8ClockSource; /*!< clock source selection */ + uint8_t u8ClockDiv; /*!< set clock divider */ + uint8_t u8Mode; /*!< set clcok mode(8/10/12 bit mode) */ + uint8_t u8FiFoLevel; /*!< set FIFO level */ +}ADC_ConfigType,*ADC_ConfigTypePtr; +/*! @} End of adc_config_type */ + +/****************************************************************************** +* define ADC APIs +* +*//*! @addtogroup adc_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief enable ADC interrupt. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_IntEnable( ADC_Type *pADC ) +{ + pADC->SC1 |= ADC_SC1_AIEN_MASK; +} +/*****************************************************************************//*! + * + * @brief disable ADC interrupt. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_IntDisable( ADC_Type *pADC ) +{ + pADC->SC1 &= ~ADC_SC1_AIEN_MASK; +} +/*****************************************************************************//*! + * + * @brief enable ADC continuous conversion. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_ContinuousConversion( ADC_Type *pADC ) +{ + pADC->SC1 |= ADC_SC1_ADCO_MASK; +} +/*****************************************************************************//*! + * + * @brief enable ADC single conversion + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SingleConversion( ADC_Type *pADC ) +{ + pADC->SC1 &= ~ADC_SC1_ADCO_MASK; +} +/*****************************************************************************//*! + * + * @brief set the ADC to hardware trigger. + * + * @param[in] pADC point to ADC module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +__STATIC_INLINE void ADC_SetHardwareTrigger( ADC_Type *pADC ) +{ + pADC->SC2 |= ADC_SC2_ADTRG_MASK; +} +/*****************************************************************************//*! + * + * @brief set the ADC to software trigger. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SetSoftwareTrigger( ADC_Type *pADC ) +{ + pADC->SC2 &= ~ADC_SC2_ADTRG_MASK; +} +/*****************************************************************************//*! + * + * @brief enable ADC compare function. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_CompareEnable( ADC_Type *pADC ) +{ + pADC->SC2 |= ADC_SC2_ACFE_MASK; +} +/*****************************************************************************//*! + * + * @brief disable ADC compare function. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_CompareDisable( ADC_Type *pADC ) +{ + pADC->SC2 &= ~ADC_SC2_ACFE_MASK; +} +/*****************************************************************************//*! + * + * @brief enable ADC compare greater function. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_CompareGreaterFunction( ADC_Type *pADC ) +{ + pADC->SC2 |= ADC_SC2_ACFGT_MASK; +} +/*****************************************************************************//*! + * + * @brief enable ADC compare less function. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_CompareLessFunction( ADC_Type *pADC ) +{ + pADC->SC2 &= ~ADC_SC2_ACFGT_MASK; +} +/*****************************************************************************//*! + * + * @brief set ADC to low power configuration. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SetLowPower( ADC_Type *pADC ) +{ + pADC->SC3 |= ADC_SC3_ADLPC_MASK; +} +/*****************************************************************************//*! + * + * @brief set ADC to high speed configuration. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SetHighSpeed( ADC_Type *pADC ) +{ + pADC->SC3 &= ~ADC_SC3_ADLPC_MASK; +} +/*****************************************************************************//*! + * + * @brief Long Sample ETMe Configuration. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SetLongSample( ADC_Type *pADC ) +{ + pADC->SC3 |= ADC_SC3_ADLSMP_MASK; +} +/*****************************************************************************//*! + * + * @brief Short Sample ETMe Configuration. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SetShortSample( ADC_Type *pADC ) +{ + pADC->SC3 &= ~ADC_SC3_ADLSMP_MASK; +} +/*****************************************************************************//*! + * + * @brief FIFO scan mode enable. + * + * @param[in] pADC point to ADC module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +__STATIC_INLINE void ADC_FifoScanModeEnable( ADC_Type *pADC ) +{ + pADC->SC4 |= ADC_SC4_ASCANE_MASK; +} +/*****************************************************************************//*! + * + * @brief FIFO scan mode disable. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_FifoScanModeDisable( ADC_Type *pADC ) +{ + pADC->SC4 &= ~ADC_SC4_ASCANE_MASK; +} +/*****************************************************************************//*! + * + * @brief OR all of compare trigger. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_CompareFifoOr( ADC_Type *pADC ) +{ + pADC->SC4 &= ~ADC_SC4_ACFSEL_MASK; +} +/*****************************************************************************//*! + * + * @brief And all of compare trigger. + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_CompareFifoAnd( ADC_Type *pADC ) +{ + pADC->SC4 |= ADC_SC4_ACFSEL_MASK; +} +/*****************************************************************************//*! + * + * @brief read ADC result register. + * + * @param[in] pADC point to ADC module type. + * + * @return ADC result value. + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE uint16_t ADC_ReadResultReg( ADC_Type *pADC ) +{ + return (uint16_t)pADC->R; +} +/*****************************************************************************//*! + * + * @brief set ADC compare value. + * + * @param[in] pADC point to ADC module type. + * @param[in] u16Compare compare value. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_SetCompareValue( ADC_Type *pADC, uint16_t u16Compare ) +{ + pADC->CV = u16Compare; +} +/*****************************************************************************//*! + * + * @brief ADC pin control enable. + * + * @param[in] pADC point to ADC module type. + * @param[in] u16PinNumber enable ADC function to specified pin number. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_PinControlEnable( ADC_Type *pADC, uint16_t u16PinNumber) +{ + ASSERT((u16PinNumber<16)); + pADC->APCTL1 &= ~(0x01<APCTL1 |= (0x01<SC2 & ADC_SC2_ADACT_MASK); +} +/*****************************************************************************//*! + * + * @brief check COCO flag + * + * @param[in] pADC point to ADC module type. + * + * @return TRUE or FALSE + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE uint8_t ADC_IsCOCOFlag( ADC_Type *pADC ) +{ + return(pADC->SC1 & ADC_SC1_COCO_MASK); +} +/*****************************************************************************//*! + * + * @brief check Result FIFO empty + * + * @param[in] pADC point to ADC module type. + * + * @return TRUE or FALSE + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE uint8_t ADC_IsFIFOEmptyFlag( ADC_Type *pADC ) +{ + return(pADC->SC2 & ADC_SC2_FEMPTY_MASK); +} +/*****************************************************************************//*! + * + * @brief check Result FIFO full + * + * @param[in] pADC point to ADC module type. + * + * @return TRUE or FALSE + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE uint8_t ADC_IsFIFOFullFlag( ADC_Type *pADC ) +{ + return(pADC->SC2 & ADC_SC2_FFULL_MASK); +} +#ifndef CPU_NV32 +/*****************************************************************************//*! + * + * @brief Hardware Trigger Multiple Conversion Enable + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_HardwareTriggerMultiple( ADC_Type *pADC ) +{ + pADC->SC4 |= ADC_SC4_HTRGME_MASK; +} +/*****************************************************************************//*! + * + * @brief Hardware Trigger Single Conversion + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_HardwareTriggerSingle( ADC_Type *pADC ) +{ + pADC->SC4 &= ~ADC_SC4_HTRGME_MASK; +} +/*****************************************************************************//*! + * + * @brief Hardware Trigger Mask Enable + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_HardwareTriggerMaskEnable( ADC_Type *pADC ) +{ + pADC->SC5 |= ADC_SC5_HTRGMASKE_MASK; +} +/*****************************************************************************//*! + * + * @brief Hardware Trigger Mask Disable + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_HardwareTriggerMaskDisable( ADC_Type *pADC ) +{ + pADC->SC5 &= ~ADC_SC5_HTRGMASKE_MASK; +} +/*****************************************************************************//*! + * + * @brief Hardware Trigger Mask Mode Select Automatic Mode + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_HardwareTriggerMaskAuto( ADC_Type *pADC ) +{ + pADC->SC5 |= ADC_SC5_HTRGMASKSEL_MASK; +} +/*****************************************************************************//*! + * + * @brief Hardware Trigger Mask Mode Select to be with HTRGMASKE + * + * @param[in] pADC point to ADC module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +__STATIC_INLINE void ADC_HardwareTriggerMaskNonAuto( ADC_Type *pADC ) +{ + pADC->SC5 &= ~ADC_SC5_HTRGMASKSEL_MASK; +} +#endif +/****************************************************************************** +* Global function +******************************************************************************/ + +void ADC_SetChannel( ADC_Type *pADC, uint8_t u8Channel ); +void ADC_IntEnable( ADC_Type *pADC ); +void ADC_IntDisable( ADC_Type *pADC ); +void ADC_ContinuousConversion( ADC_Type *pADC ); +void ADC_SingleConversion( ADC_Type *pADC ); +void ADC_SetSoftwareTrigger( ADC_Type *pADC ); +void ADC_SetHardwareTrigger( ADC_Type *pADC ); +void ADC_VrefSelect( ADC_Type *pADC, uint8_t u8Vref ); +void ADC_CompareEnable( ADC_Type *pADC ); +void ADC_CompareDisable( ADC_Type *pADC ); +void ADC_CompareGreaterFunction( ADC_Type *pADC ); +void ADC_CompareLessFunction( ADC_Type *pADC ); +void ADC_SetLowPower( ADC_Type *pADC ); +void ADC_SetHighSpeed( ADC_Type *pADC ); +void ADC_SelectClockDivide( ADC_Type *pADC, uint8_t u8Div); +void ADC_SetLongSample(ADC_Type *pADC); +void ADC_SetShortSample(ADC_Type *pADC); +void ADC_SetMode(ADC_Type *pADC, uint8_t u8Mode); +void ADC_SelectClock(ADC_Type *pADC, uint8_t u8Clock); +void ADC_FifoScanModeEnable(ADC_Type *pADC); +void ADC_FifoScanModeDisable(ADC_Type *pADC); +void ADC_CompareFifoOr(ADC_Type *pADC); +void ADC_CompareFifoAnd(ADC_Type *pADC); +void ADC_SetFifoLevel(ADC_Type *pADC, uint8_t u8FifoLevel); +uint16_t ADC_ReadResultReg(ADC_Type *pADC ); +void ADC_SetCompareValue(ADC_Type *pADC, uint16_t u16Compare ); +void ADC_PinControlEnable(ADC_Type *pADC, uint16_t u16PinNumber); +void ADC_PinControlDisable(ADC_Type *pADC, uint16_t u16PinNumber); +uint8_t ADC_IsConversionActiveFlag(ADC_Type *pADC); +uint8_t ADC_IsCOCOFlag(ADC_Type *pADC); +uint8_t ADC_IsFIFOEmptyFlag(ADC_Type *pADC); +uint8_t ADC_IsFIFOFullFlag(ADC_Type *pADC); +void ADC_HardwareTriggerMaskNonAuto(ADC_Type *pADC); +void ADC_HardwareTriggerMaskAuto(ADC_Type *pADC); +void ADC_HardwareTriggerMaskDisable( ADC_Type *pADC ); +void ADC_HardwareTriggerMaskEnable( ADC_Type *pADC ); +void ADC_HardwareTriggerSingle( ADC_Type *pADC ); +void ADC_HardwareTriggerMultiple( ADC_Type *pADC ); +unsigned int ADC_PollRead( ADC_Type *pADC, uint8_t u8Channel); +void ADC_SetCallBack(ADC_CallbackType pADC_CallBack); +void ADC_DeInit(ADC_Type *pADC); +void ADC_Init(ADC_Type *pADC, ADC_ConfigTypePtr pADC_Config); +/*! @} End of adc_api_list */ + +#ifdef __cplusplus +} +#endif +#endif /* ADC_H_ */ diff --git a/bsp/nv32f100x/lib/inc/arm_cm0.h b/bsp/nv32f100x/lib/inc/arm_cm0.h new file mode 100644 index 0000000000000000000000000000000000000000..481507f4bc098039c29c9cf649d87c264a7b1b33 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/arm_cm0.h @@ -0,0 +1,100 @@ +/****************************************************************************** +* +* @brief provide generic high-level routines for ARM Cortex M0/M0+ processors. +* +*******************************************************************************/ + +#ifndef _CPU_ARM_CM0_H +#define _CPU_ARM_CM0_H + +/*ARM Cortex M0 implementation for interrupt priority shift*/ +#define ARM_INTERRUPT_LEVEL_BITS 2 + + +/***********************************************************************/ + /*!< Macro to enable all interrupts. */ +#ifndef KEIL +#define EnableInterrupts asm(" CPSIE i"); +#else +#define EnableInterrupts __enable_irq() +#endif + + /*!< Macro to disable all interrupts. */ +#ifndef KEIL +#define DisableInterrupts asm(" CPSID i"); +#else +#define DisableInterrupts __disable_irq() +#endif + +#define disable_irq(irq) NVIC_DisableIRQ(irq) +#define enable_irq(irq) NVIC_EnableIRQ(irq) +#define set_irq_priority(irq, prio) NVIC_SetPriority(irq, prio) +/***********************************************************************/ + + +/* + * Misc. Defines + */ +#ifdef FALSE +#undef FALSE +#endif +#define FALSE (0) + +#ifdef TRUE +#undef TRUE +#endif +#define TRUE (1) + +#ifdef NULL +#undef NULL +#endif +#define NULL (0) + +#ifdef ON +#undef ON +#endif +#define ON (1) + +#ifdef OFF +#undef OFF +#endif +#define OFF (0) + +#undef ENABLE +#define ENABLE (1) + +#undef DISABLE +#define DISABLE (0) + + +/***********************************************************************/ +/* + * The basic data types + */ +typedef unsigned char uint8; /* 8 bits */ +typedef unsigned short int uint16; /* 16 bits */ +typedef unsigned long int uint32; /* 32 bits */ + +typedef char int8; /* 8 bits */ +typedef short int int16; /* 16 bits */ +typedef int int32; /* 32 bits */ + +typedef volatile int8 vint8; /* 8 bits */ +typedef volatile int16 vint16; /* 16 bits */ +typedef volatile int32 vint32; /* 32 bits */ + +typedef volatile uint8 vuint8; /* 8 bits */ +typedef volatile uint16 vuint16; /* 16 bits */ +typedef volatile uint32 vuint32; /* 32 bits */ + +// function prototype for main function +int main(void); +/***********************************************************************/ +// function prototypes for arm_cm0.c +void stop (void); +void wait (void); +void write_vtor (int); + +/***********************************************************************/ +#endif /* _CPU_ARM_CM4_H */ + diff --git a/bsp/nv32f100x/lib/inc/common.h b/bsp/nv32f100x/lib/inc/common.h new file mode 100644 index 0000000000000000000000000000000000000000..f943e6f8fcee4e45e45cd8cc89a6d4a53efe35e9 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/common.h @@ -0,0 +1,88 @@ +/****************************************************************************** +* +* @brief provide header files to be included by all project files. +* +*******************************************************************************/ + + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#define swap_bytes(ptrWord) *ptrWord = (*ptrWord >>8) | (*ptrWord<<8) +typedef unsigned long dword; +typedef unsigned short word; + +/********************************************************************/ + +/* + * Debug prints ON (#define) or OFF (#undef) + */ + +#define DEBUG +#define DEBUG_PRINT + +/* + * Include the generic CPU header file + */ +#include "arm_cm0.h" + +/* + * Include the platform specific header file + */ +#if (defined(NV32)) + #include "NV32_config.h" +#elif (defined(FRDM_NV32M3)) + #include "NV32M3_config.h" +#elif (defined(FRDM_NV32M4)) + #include "NV32M4_config.h" +#else + #error "No valid board defined" +#endif + +/* + * Include the cpu specific header file +*/ +#if (defined(CPU_NV32)) + #include "NV32.h" +#elif (defined(CPU_NV32M3)) + #include "NV32M3.h" +#elif (defined(CPU_NV32M4)) + #include "NV32M4.h" +#else + #error "No valid CPU defined" +#endif + + +/* + * Include any toolchain specfic header files + */ +#if (defined(__MWERKS__)) + #include "mwerks.h" +#elif (defined(__DCC__)) + #include "build/wrs/diab.h" +#elif (defined(__ghs__)) + #include "build/ghs/ghs.h" +#elif (defined(__GNUC__)) + #if (defined(IAR)) + #include "build/gnu/gnu.h" + #endif +#elif (defined(IAR)) + #include "iar.h" +#elif (defined(KEIL)) + +#else +#warning "No toolchain specific header included" +#endif + +/* + * Include common utilities + */ + +#define ASSERT(x) + +#if (defined(IAR)) +#include "intrinsics.h" +#endif +/********************************************************************/ + +#endif /* _COMMON_H_ */ diff --git a/bsp/nv32f100x/lib/inc/core_cm0plus.h b/bsp/nv32f100x/lib/inc/core_cm0plus.h new file mode 100644 index 0000000000000000000000000000000000000000..17e43984fcf972bf1c642c5e3bb73e8285e6ef82 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/core_cm0plus.h @@ -0,0 +1,822 @@ +/**************************************************************************//** + * @file core_cm0plus.h + * @brief CMSIS Cortex-M0+ Core Peripheral Access Layer Header File + * @version V4.00 + * @date 22. August 2014 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2014 ARM LIMITED + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name of ARM nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + * + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + ---------------------------------------------------------------------------*/ + + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#endif + +#ifndef __CORE_CM0PLUS_H_GENERIC +#define __CORE_CM0PLUS_H_GENERIC + +#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.
+ Function definitions in header files are used to allow 'inlining'. + + \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
+ Unions are used for effective representation of core registers. + + \li Advisory Rule 19.7, Function-like macro defined.
+ Function-like macros are used to allow more efficient code. + */ + + +/******************************************************************************* + * CMSIS definitions + ******************************************************************************/ +/** \ingroup Cortex-M0+ + @{ + */ + +/* CMSIS CM0P definitions */ +#define __CM0PLUS_CMSIS_VERSION_MAIN (0x04) /*!< [31:16] CMSIS HAL main version */ +#define __CM0PLUS_CMSIS_VERSION_SUB (0x00) /*!< [15:0] CMSIS HAL sub version */ +#define __CM0PLUS_CMSIS_VERSION ((__CM0PLUS_CMSIS_VERSION_MAIN << 16) | \ + __CM0PLUS_CMSIS_VERSION_SUB) /*!< CMSIS HAL version number */ + +#define __CORTEX_M (0x00) /*!< Cortex-M Core */ + + +#if defined ( __CC_ARM ) + #define __ASM __asm /*!< asm keyword for ARM Compiler */ + #define __INLINE __inline /*!< inline keyword for ARM Compiler */ + #define __STATIC_INLINE static __inline + +#elif defined ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU Compiler */ + #define __STATIC_INLINE static inline + +#elif defined ( __ICCARM__ ) + #define __ASM __asm /*!< asm keyword for IAR Compiler */ + #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ + #define __STATIC_INLINE static inline + +#elif defined ( __TMS470__ ) + #define __ASM __asm /*!< asm keyword for TI CCS Compiler */ + #define __STATIC_INLINE static inline + +#elif defined ( __TASKING__ ) + #define __ASM __asm /*!< asm keyword for TASKING Compiler */ + #define __INLINE inline /*!< inline keyword for TASKING Compiler */ + #define __STATIC_INLINE static inline + +#elif defined ( __CSMC__ ) + #define __packed + #define __ASM _asm /*!< asm keyword for COSMIC Compiler */ + #define __INLINE inline /*use -pc99 on compile line !< inline keyword for COSMIC Compiler */ + #define __STATIC_INLINE static inline + +#endif + +/** __FPU_USED indicates whether an FPU is used or not. + This core does not support an FPU at all +*/ +#define __FPU_USED 0 + +#if defined ( __CC_ARM ) + #if defined __TARGET_FPU_VFP + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __GNUC__ ) + #if defined (__VFP_FP__) && !defined(__SOFTFP__) + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __ICCARM__ ) + #if defined __ARMVFP__ + #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif + +#elif defined ( __TMS470__ ) + #if defined __TI__VFP_SUPPORT____ + #warning "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__ ) /* Cosmic */ + #if ( __CSMC__ & 0x400) // FPU present for parser + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif +#endif + +#include /* standard types definitions */ +#include /* Core Instruction Access */ +#include /* Core Function Access */ + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM0PLUS_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_CM0PLUS_H_DEPENDANT +#define __CORE_CM0PLUS_H_DEPENDANT + +#ifdef __cplusplus + extern "C" { +#endif + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __CM0PLUS_REV + #define __CM0PLUS_REV 0x0000 + #warning "__CM0PLUS_REV not defined in device header file; using default!" + #endif + + #ifndef __MPU_PRESENT + #define __MPU_PRESENT 0 + #warning "__MPU_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __VTOR_PRESENT + #define __VTOR_PRESENT 0 + #warning "__VTOR_PRESENT not defined in device header file; using default!" + #endif + + #ifndef __NVIC_PRIO_BITS + #define __NVIC_PRIO_BITS 2 + #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" + #endif + + #ifndef __Vendor_SysTickConfig + #define __Vendor_SysTickConfig 0 + #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 + + IO Type Qualifiers 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 */ + +/*@} end of group Cortex-M0+ */ + + + +/******************************************************************************* + * Register Abstraction + Core Register contain: + - Core Register + - Core NVIC Register + - Core SCB Register + - Core SysTick Register + - Core MPU 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 + { +#if (__CORTEX_M != 0x04) + uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */ +#else + uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ +#endif + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + 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; + + +/** \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; + + +/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). + */ +typedef union +{ + struct + { + uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ +#if (__CORTEX_M != 0x04) + uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ +#else + uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ + uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ + uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ +#endif + uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ + uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ + uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ + 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; + + +/** \brief Union type to access the Control Registers (CONTROL). + */ +typedef union +{ + struct + { + uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ + uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ + uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ + uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ + } b; /*!< Structure used for bit access */ + uint32_t w; /*!< Type used for word access */ +} CONTROL_Type; + +/*@} 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 +{ + __IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ + uint32_t RESERVED0[31]; + __IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ + uint32_t RSERVED1[31]; + __IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ + uint32_t RESERVED2[31]; + __IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ + uint32_t RESERVED3[31]; + uint32_t RESERVED4[64]; + __IO uint32_t IP[8]; /*!< 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 +{ + __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ + __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ +#if (__VTOR_PRESENT == 1) + __IO uint32_t VTOR; /*!< Offset: 0x008 (R/W) Vector Table Offset Register */ +#else + uint32_t RESERVED0; +#endif + __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ + __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ + __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ + uint32_t RESERVED1; + __IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ + __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ +} SCB_Type; + +/* SCB CPUID Register Definitions */ +#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */ +#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ + +#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */ +#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ + +#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */ +#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ + +#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */ +#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ + +#define SCB_CPUID_REVISION_Pos 0 /*!< 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 31 /*!< SCB ICSR: NMIPENDSET Position */ +#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ + +#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */ +#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ + +#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */ +#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ + +#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */ +#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ + +#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */ +#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ + +#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */ +#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ + +#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */ +#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ + +#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */ +#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ + +#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */ +#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */ + +#if (__VTOR_PRESENT == 1) +/* SCB Interrupt Control State Register Definitions */ +#define SCB_VTOR_TBLOFF_Pos 8 /*!< SCB VTOR: TBLOFF Position */ +#define SCB_VTOR_TBLOFF_Msk (0xFFFFFFUL << SCB_VTOR_TBLOFF_Pos) /*!< SCB VTOR: TBLOFF Mask */ +#endif + +/* SCB Application Interrupt and Reset Control Register Definitions */ +#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ +#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ + +#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */ +#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ + +#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */ +#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ + +#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ +#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ + +#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< 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 4 /*!< SCB SCR: SEVONPEND Position */ +#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ + +#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */ +#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ + +#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< 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 9 /*!< SCB CCR: STKALIGN Position */ +#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ + +#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< 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 15 /*!< 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 +{ + __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ + __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ + __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ + __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ +} SysTick_Type; + +/* SysTick Control / Status Register Definitions */ +#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */ +#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ + +#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */ +#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ + +#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */ +#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ + +#define SysTick_CTRL_ENABLE_Pos 0 /*!< 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 0 /*!< 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 0 /*!< 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 31 /*!< SysTick CALIB: NOREF Position */ +#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ + +#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */ +#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ + +#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */ +#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_CALIB_TENMS_Pos) /*!< SysTick CALIB: TENMS Mask */ + +/*@} end of group CMSIS_SysTick */ + +#if (__MPU_PRESENT == 1) +/** \ingroup CMSIS_core_register + \defgroup CMSIS_MPU Memory Protection Unit (MPU) + \brief Type definitions for the Memory Protection Unit (MPU) + @{ + */ + +/** \brief Structure type to access the Memory Protection Unit (MPU). + */ +typedef struct +{ + __I uint32_t TYPE; /*!< Offset: 0x000 (R/ ) MPU Type Register */ + __IO uint32_t CTRL; /*!< Offset: 0x004 (R/W) MPU Control Register */ + __IO uint32_t RNR; /*!< Offset: 0x008 (R/W) MPU Region RNRber Register */ + __IO uint32_t RBAR; /*!< Offset: 0x00C (R/W) MPU Region Base Address Register */ + __IO uint32_t RASR; /*!< Offset: 0x010 (R/W) MPU Region Attribute and Size Register */ +} MPU_Type; + +/* MPU Type Register */ +#define MPU_TYPE_IREGION_Pos 16 /*!< MPU TYPE: IREGION Position */ +#define MPU_TYPE_IREGION_Msk (0xFFUL << MPU_TYPE_IREGION_Pos) /*!< MPU TYPE: IREGION Mask */ + +#define MPU_TYPE_DREGION_Pos 8 /*!< MPU TYPE: DREGION Position */ +#define MPU_TYPE_DREGION_Msk (0xFFUL << MPU_TYPE_DREGION_Pos) /*!< MPU TYPE: DREGION Mask */ + +#define MPU_TYPE_SEPARATE_Pos 0 /*!< MPU TYPE: SEPARATE Position */ +#define MPU_TYPE_SEPARATE_Msk (1UL << MPU_TYPE_SEPARATE_Pos) /*!< MPU TYPE: SEPARATE Mask */ + +/* MPU Control Register */ +#define MPU_CTRL_PRIVDEFENA_Pos 2 /*!< MPU CTRL: PRIVDEFENA Position */ +#define MPU_CTRL_PRIVDEFENA_Msk (1UL << MPU_CTRL_PRIVDEFENA_Pos) /*!< MPU CTRL: PRIVDEFENA Mask */ + +#define MPU_CTRL_HFNMIENA_Pos 1 /*!< MPU CTRL: HFNMIENA Position */ +#define MPU_CTRL_HFNMIENA_Msk (1UL << MPU_CTRL_HFNMIENA_Pos) /*!< MPU CTRL: HFNMIENA Mask */ + +#define MPU_CTRL_ENABLE_Pos 0 /*!< MPU CTRL: ENABLE Position */ +#define MPU_CTRL_ENABLE_Msk (1UL << MPU_CTRL_ENABLE_Pos) /*!< MPU CTRL: ENABLE Mask */ + +/* MPU Region Number Register */ +#define MPU_RNR_REGION_Pos 0 /*!< MPU RNR: REGION Position */ +#define MPU_RNR_REGION_Msk (0xFFUL << MPU_RNR_REGION_Pos) /*!< MPU RNR: REGION Mask */ + +/* MPU Region Base Address Register */ +#define MPU_RBAR_ADDR_Pos 8 /*!< MPU RBAR: ADDR Position */ +#define MPU_RBAR_ADDR_Msk (0xFFFFFFUL << MPU_RBAR_ADDR_Pos) /*!< MPU RBAR: ADDR Mask */ + +#define MPU_RBAR_VALID_Pos 4 /*!< MPU RBAR: VALID Position */ +#define MPU_RBAR_VALID_Msk (1UL << MPU_RBAR_VALID_Pos) /*!< MPU RBAR: VALID Mask */ + +#define MPU_RBAR_REGION_Pos 0 /*!< MPU RBAR: REGION Position */ +#define MPU_RBAR_REGION_Msk (0xFUL << MPU_RBAR_REGION_Pos) /*!< MPU RBAR: REGION Mask */ + +/* MPU Region Attribute and Size Register */ +#define MPU_RASR_ATTRS_Pos 16 /*!< MPU RASR: MPU Region Attribute field Position */ +#define MPU_RASR_ATTRS_Msk (0xFFFFUL << MPU_RASR_ATTRS_Pos) /*!< MPU RASR: MPU Region Attribute field Mask */ + +#define MPU_RASR_XN_Pos 28 /*!< MPU RASR: ATTRS.XN Position */ +#define MPU_RASR_XN_Msk (1UL << MPU_RASR_XN_Pos) /*!< MPU RASR: ATTRS.XN Mask */ + +#define MPU_RASR_AP_Pos 24 /*!< MPU RASR: ATTRS.AP Position */ +#define MPU_RASR_AP_Msk (0x7UL << MPU_RASR_AP_Pos) /*!< MPU RASR: ATTRS.AP Mask */ + +#define MPU_RASR_TEX_Pos 19 /*!< MPU RASR: ATTRS.TEX Position */ +#define MPU_RASR_TEX_Msk (0x7UL << MPU_RASR_TEX_Pos) /*!< MPU RASR: ATTRS.TEX Mask */ + +#define MPU_RASR_S_Pos 18 /*!< MPU RASR: ATTRS.S Position */ +#define MPU_RASR_S_Msk (1UL << MPU_RASR_S_Pos) /*!< MPU RASR: ATTRS.S Mask */ + +#define MPU_RASR_C_Pos 17 /*!< MPU RASR: ATTRS.C Position */ +#define MPU_RASR_C_Msk (1UL << MPU_RASR_C_Pos) /*!< MPU RASR: ATTRS.C Mask */ + +#define MPU_RASR_B_Pos 16 /*!< MPU RASR: ATTRS.B Position */ +#define MPU_RASR_B_Msk (1UL << MPU_RASR_B_Pos) /*!< MPU RASR: ATTRS.B Mask */ + +#define MPU_RASR_SRD_Pos 8 /*!< MPU RASR: Sub-Region Disable Position */ +#define MPU_RASR_SRD_Msk (0xFFUL << MPU_RASR_SRD_Pos) /*!< MPU RASR: Sub-Region Disable Mask */ + +#define MPU_RASR_SIZE_Pos 1 /*!< MPU RASR: Region Size Field Position */ +#define MPU_RASR_SIZE_Msk (0x1FUL << MPU_RASR_SIZE_Pos) /*!< MPU RASR: Region Size Field Mask */ + +#define MPU_RASR_ENABLE_Pos 0 /*!< MPU RASR: Region enable bit Position */ +#define MPU_RASR_ENABLE_Msk (1UL << MPU_RASR_ENABLE_Pos) /*!< MPU RASR: Region enable bit Disable Mask */ + +/*@} end of group CMSIS_MPU */ +#endif + + +/** \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_base Core Definitions + \brief Definitions for base addresses, unions, and structures. + @{ + */ + +/* Memory mapping of Cortex-M0+ 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 */ + +#if (__MPU_PRESENT == 1) + #define MPU_BASE (SCS_BASE + 0x0D90UL) /*!< Memory Protection Unit */ + #define MPU ((MPU_Type *) MPU_BASE ) /*!< Memory Protection Unit */ +#endif + +/*@} */ + + + +/******************************************************************************* + * 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. + @{ + */ + +/* Interrupt Priorities are WORD accessible only under ARMv6M */ +/* The following MACROS handle generation of the register offset and byte masks */ +#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 ) +#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) ) +#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) ) + + +/** \brief Enable External Interrupt + + The function enables a device-specific interrupt in the NVIC interrupt controller. + + \param [in] IRQn External interrupt number. Value cannot be negative. + */ +__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) +{ + NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + + +/** \brief Disable External Interrupt + + The function disables a device-specific interrupt in the NVIC interrupt controller. + + \param [in] IRQn External interrupt number. Value cannot be negative. + */ +__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) +{ + NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + + +/** \brief Get Pending Interrupt + + The function reads the pending register in the NVIC and returns the pending bit + for the specified interrupt. + + \param [in] IRQn Interrupt number. + + \return 0 Interrupt status is not pending. + \return 1 Interrupt status is pending. + */ +__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) +{ + return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); +} + + +/** \brief Set Pending Interrupt + + The function sets the pending bit of an external interrupt. + + \param [in] IRQn Interrupt number. Value cannot be negative. + */ +__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) +{ + NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); +} + + +/** \brief Clear Pending Interrupt + + The function clears the pending bit of an external interrupt. + + \param [in] IRQn External interrupt number. Value cannot be negative. + */ +__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) +{ + NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ +} + + +/** \brief Set Interrupt Priority + + The function sets the priority of an interrupt. + + \note The priority cannot be set for every core interrupt. + + \param [in] IRQn Interrupt number. + \param [in] priority Priority to set. + */ +__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) +{ + if(IRQn < 0) { + SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | + (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } + else { + NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | + (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } +} + + +/** \brief Get Interrupt Priority + + The function reads the priority of an interrupt. The interrupt + number can be positive to specify an external (device specific) + interrupt, or negative to specify an internal (core) interrupt. + + + \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(IRQn < 0) { + return((uint32_t)(((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */ + else { + return((uint32_t)(((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) & 0xFF) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ +} + + +/** \brief System Reset + + The function initiates a system reset request to reset the MCU. + */ +__STATIC_INLINE void NVIC_SystemReset(void) +{ + __DSB(); /* Ensure all outstanding memory accesses included + buffered write are completed before reset */ + SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | + SCB_AIRCR_SYSRESETREQ_Msk); + __DSB(); /* Ensure completion of memory access */ + while(1); /* wait until reset */ +} + +/*@} end of CMSIS_Core_NVICFunctions */ + + + +/* ################################## SysTick function ############################################ */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_SysTickFunctions SysTick Functions + \brief Functions that configure the System. + @{ + */ + +#if (__Vendor_SysTickConfig == 0) + +/** \brief System Tick Configuration + + The function 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 __Vendor_SysTickConfig is set to 1, then the + function SysTick_Config is not included. In this case, the file device.h + must contain a vendor-specific implementation of this function. + + */ +__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) +{ + if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ + + SysTick->LOAD = ticks - 1; /* set reload register */ + NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */ + SysTick->VAL = 0; /* 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 (0); /* Function successful */ +} + +#endif + +/*@} end of CMSIS_Core_SysTickFunctions */ + + + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CM0PLUS_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ diff --git a/bsp/nv32f100x/lib/inc/core_cmFunc.h b/bsp/nv32f100x/lib/inc/core_cmFunc.h new file mode 100644 index 0000000000000000000000000000000000000000..01089f1333bd097ac99868e007c84e1cb6ef85a6 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/core_cmFunc.h @@ -0,0 +1,637 @@ +/**************************************************************************//** + * @file core_cmFunc.h + * @brief CMSIS Cortex-M Core Function Access Header File + * @version V4.00 + * @date 28. August 2014 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2014 ARM LIMITED + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name of ARM nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + * + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + ---------------------------------------------------------------------------*/ + + +#ifndef __CORE_CMFUNC_H +#define __CORE_CMFUNC_H + + +/* ########################### Core Function Access ########################### */ +/** \ingroup CMSIS_Core_FunctionInterface + \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions + @{ + */ + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ +/* ARM armcc specific functions */ + +#if (__ARMCC_VERSION < 400677) + #error "Please use ARM Compiler Toolchain V4.0.677 or later!" +#endif + +/* intrinsic void __enable_irq(); */ +/* intrinsic void __disable_irq(); */ + +/** \brief Get Control Register + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 + + This function 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 (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) + +/** \brief Enable FIQ + + This function 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 + + This function 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 + + This function 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 + + This function 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 & 0xff); +} + + +/** \brief Get Fault Mask + + This function 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 + + This function 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)1); +} + +#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */ + + +#if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) + +/** \brief Get FPSCR + + This function 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 (__FPU_PRESENT == 1) && (__FPU_USED == 1) + register uint32_t __regfpscr __ASM("fpscr"); + return(__regfpscr); +#else + return(0); +#endif +} + + +/** \brief Set FPSCR + + This function 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 (__FPU_PRESENT == 1) && (__FPU_USED == 1) + register uint32_t __regfpscr __ASM("fpscr"); + __regfpscr = (fpscr); +#endif +} + +#endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */ + + +#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ +/* GNU gcc specific functions */ + +/** \brief Enable IRQ Interrupts + + This function enables IRQ interrupts by clearing the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void) +{ + __ASM volatile ("cpsie i" : : : "memory"); +} + + +/** \brief Disable IRQ Interrupts + + This function disables IRQ interrupts by setting the I-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void) +{ + __ASM volatile ("cpsid i" : : : "memory"); +} + + +/** \brief Get Control Register + + This function returns the content of the Control Register. + + \return Control Register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, control" : "=r" (result) ); + return(result); +} + + +/** \brief Set Control Register + + This function writes the given value to the Control Register. + + \param [in] control Control Register value to set + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control) +{ + __ASM volatile ("MSR control, %0" : : "r" (control) : "memory"); +} + + +/** \brief Get IPSR Register + + This function returns the content of the IPSR Register. + + \return IPSR Register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); + return(result); +} + + +/** \brief Get APSR Register + + This function returns the content of the APSR Register. + + \return APSR Register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, apsr" : "=r" (result) ); + return(result); +} + + +/** \brief Get xPSR Register + + This function returns the content of the xPSR Register. + + \return xPSR Register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); + return(result); +} + + +/** \brief Get Process Stack Pointer + + This function returns the current value of the Process Stack Pointer (PSP). + + \return PSP Register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, psp\n" : "=r" (result) ); + return(result); +} + + +/** \brief Set Process Stack Pointer + + This function assigns the given value to the Process Stack Pointer (PSP). + + \param [in] topOfProcStack Process Stack Pointer value to set + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) +{ + __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp"); +} + + +/** \brief Get Main Stack Pointer + + This function returns the current value of the Main Stack Pointer (MSP). + + \return MSP Register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void) +{ + register uint32_t result; + + __ASM volatile ("MRS %0, msp\n" : "=r" (result) ); + return(result); +} + + +/** \brief Set Main Stack Pointer + + This function assigns the given value to the Main Stack Pointer (MSP). + + \param [in] topOfMainStack Main Stack Pointer value to set + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) +{ + __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp"); +} + + +/** \brief Get Priority Mask + + This function returns the current state of the priority mask bit from the Priority Mask Register. + + \return Priority Mask value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, primask" : "=r" (result) ); + return(result); +} + + +/** \brief Set Priority Mask + + This function assigns the given value to the Priority Mask Register. + + \param [in] priMask Priority Mask + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) +{ + __ASM volatile ("MSR primask, %0" : : "r" (priMask) : "memory"); +} + + +#if (__CORTEX_M >= 0x03) + +/** \brief Enable FIQ + + This function enables FIQ interrupts by clearing the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void) +{ + __ASM volatile ("cpsie f" : : : "memory"); +} + + +/** \brief Disable FIQ + + This function disables FIQ interrupts by setting the F-bit in the CPSR. + Can only be executed in Privileged modes. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void) +{ + __ASM volatile ("cpsid f" : : : "memory"); +} + + +/** \brief Get Base Priority + + This function returns the current value of the Base Priority register. + + \return Base Priority register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, basepri_max" : "=r" (result) ); + return(result); +} + + +/** \brief Set Base Priority + + This function assigns the given value to the Base Priority register. + + \param [in] basePri Base Priority value to set + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value) +{ + __ASM volatile ("MSR basepri, %0" : : "r" (value) : "memory"); +} + + +/** \brief Get Fault Mask + + This function returns the current value of the Fault Mask register. + + \return Fault Mask register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void) +{ + uint32_t result; + + __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); + return(result); +} + + +/** \brief Set Fault Mask + + This function assigns the given value to the Fault Mask register. + + \param [in] faultMask Fault Mask value to set + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) +{ + __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) : "memory"); +} + +#endif /* (__CORTEX_M >= 0x03) */ + + +#if (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) + +/** \brief Get FPSCR + + This function returns the current value of the Floating Point Status/Control register. + + \return Floating Point Status/Control register value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void) +{ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + uint32_t result; + + /* Empty asm statement works as a scheduling barrier */ + __ASM volatile (""); + __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); + __ASM volatile (""); + return(result); +#else + return(0); +#endif +} + + +/** \brief Set FPSCR + + This function assigns the given value to the Floating Point Status/Control register. + + \param [in] fpscr Floating Point Status/Control value to set + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) +{ +#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) + /* Empty asm statement works as a scheduling barrier */ + __ASM volatile (""); + __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) : "vfpcc"); + __ASM volatile (""); +#endif +} + +#endif /* (__CORTEX_M == 0x04) || (__CORTEX_M == 0x07) */ + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ +#include + + +#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ +/* TI CCS specific functions */ +#include + + +#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ +/* TASKING carm specific functions */ +/* + * 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. + */ + + +#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/ +/* Cosmic specific functions */ +#include + +#endif + +/*@} end of CMSIS_Core_RegAccFunctions */ + +#endif /* __CORE_CMFUNC_H */ diff --git a/bsp/nv32f100x/lib/inc/core_cmInstr.h b/bsp/nv32f100x/lib/inc/core_cmInstr.h new file mode 100644 index 0000000000000000000000000000000000000000..d14110b2abd16c8d93acece894985d4fe2841cb0 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/core_cmInstr.h @@ -0,0 +1,880 @@ +/**************************************************************************//** + * @file core_cmInstr.h + * @brief CMSIS Cortex-M Core Instruction Access Header File + * @version V4.00 + * @date 28. August 2014 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2014 ARM LIMITED + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name of ARM nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + * + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + ---------------------------------------------------------------------------*/ + + +#ifndef __CORE_CMINSTR_H +#define __CORE_CMINSTR_H + + +/* ########################## Core Instruction Access ######################### */ +/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface + Access to dedicated instructions + @{ +*/ + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ +/* ARM armcc specific functions */ + +#if (__ARMCC_VERSION < 400677) + #error "Please use ARM Compiler Toolchain V4.0.677 or later!" +#endif + + +/** \brief No Operation + + No Operation does nothing. This instruction can be used for code alignment purposes. + */ +#define __NOP __nop + + +/** \brief Wait For Interrupt + + 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 + + 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 + + Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +#define __SEV __sev + + +/** \brief Instruction Synchronization Barrier + + 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() __isb(0xF) + + +/** \brief Data Synchronization Barrier + + This function acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +#define __DSB() __dsb(0xF) + + +/** \brief Data Memory Barrier + + This function ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +#define __DMB() __dmb(0xF) + + +/** \brief Reverse byte order (32 bit) + + This function reverses the byte order in integer value. + + \param [in] value Value to reverse + \return Reversed value + */ +#define __REV __rev + + +/** \brief Reverse byte order (16 bit) + + This function reverses the byte order in two unsigned short values. + + \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 in signed short value + + This function reverses the byte order in a signed short value with sign extension to integer. + + \param [in] value Value to reverse + \return Reversed value + */ +#ifndef __NO_EMBEDDED_ASM +__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value) +{ + revsh r0, r0 + bx lr +} +#endif + + +/** \brief Rotate Right in unsigned value (32 bit) + + This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + + \param [in] value Value to rotate + \param [in] value Number of Bits to rotate + \return Rotated value + */ +#define __ROR __ror + + +/** \brief Breakpoint + + This function 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) + + +#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) + +/** \brief Reverse bit order of value + + This function reverses the bit order of the given value. + + \param [in] value Value to reverse + \return Reversed value + */ +#define __RBIT __rbit + + +/** \brief LDR Exclusive (8 bit) + + This function executes a exclusive LDR instruction for 8 bit value. + + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) + + +/** \brief LDR Exclusive (16 bit) + + This function executes a exclusive LDR instruction for 16 bit values. + + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) + + +/** \brief LDR Exclusive (32 bit) + + This function executes a exclusive LDR instruction for 32 bit values. + + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) + + +/** \brief STR Exclusive (8 bit) + + This function 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 + */ +#define __STREXB(value, ptr) __strex(value, ptr) + + +/** \brief STR Exclusive (16 bit) + + This function 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 + */ +#define __STREXH(value, ptr) __strex(value, ptr) + + +/** \brief STR Exclusive (32 bit) + + This function 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 + */ +#define __STREXW(value, ptr) __strex(value, ptr) + + +/** \brief Remove the exclusive lock + + This function removes the exclusive lock which is created by LDREX. + + */ +#define __CLREX __clrex + + +/** \brief Signed Saturate + + This function 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 + + This function 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 Count leading zeros + + This function 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 + + +/** \brief Rotate Right with Extend (32 bit) + + This function 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) + + This function 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) + + This function 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) + + This function 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) + + This function 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) + + This function 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) + + This function 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) + +#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */ + + +#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ +/* GNU gcc specific functions */ + +/* Define macros for porting to both thumb1 and thumb2. + * For thumb1, use low register (r0-r7), specified by constrant "l" + * Otherwise, use general registers, specified by constrant "r" */ +#if defined (__thumb__) && !defined (__thumb2__) +#define __CMSIS_GCC_OUT_REG(r) "=l" (r) +#define __CMSIS_GCC_USE_REG(r) "l" (r) +#else +#define __CMSIS_GCC_OUT_REG(r) "=r" (r) +#define __CMSIS_GCC_USE_REG(r) "r" (r) +#endif + +/** \brief No Operation + + No Operation does nothing. This instruction can be used for code alignment purposes. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void) +{ + __ASM volatile ("nop"); +} + + +/** \brief Wait For Interrupt + + Wait For Interrupt is a hint instruction that suspends execution + until one of a number of events occurs. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void) +{ + __ASM volatile ("wfi"); +} + + +/** \brief Wait For Event + + 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. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void) +{ + __ASM volatile ("wfe"); +} + + +/** \brief Send Event + + Send Event is a hint instruction. It causes an event to be signaled to the CPU. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void) +{ + __ASM volatile ("sev"); +} + + +/** \brief Instruction Synchronization Barrier + + 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. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void) +{ + __ASM volatile ("isb"); +} + + +/** \brief Data Synchronization Barrier + + This function acts as a special kind of Data Memory Barrier. + It completes when all explicit memory accesses before this instruction complete. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void) +{ + __ASM volatile ("dsb"); +} + + +/** \brief Data Memory Barrier + + This function ensures the apparent order of the explicit memory operations before + and after the instruction, without ensuring their completion. + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void) +{ + __ASM volatile ("dmb"); +} + + +/** \brief Reverse byte order (32 bit) + + This function reverses the byte order in integer value. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value) +{ +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) + return __builtin_bswap32(value); +#else + uint32_t result; + + __ASM volatile ("rev %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); +#endif +} + + +/** \brief Reverse byte order (16 bit) + + This function reverses the byte order in two unsigned short values. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rev16 %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); +} + + +/** \brief Reverse byte order in signed short value + + This function reverses the byte order in a signed short value with sign extension to integer. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value) +{ +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + return (short)__builtin_bswap16(value); +#else + uint32_t result; + + __ASM volatile ("revsh %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); +#endif +} + + +/** \brief Rotate Right in unsigned value (32 bit) + + This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. + + \param [in] value Value to rotate + \param [in] value Number of Bits to rotate + \return Rotated value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2) +{ + return (op1 >> op2) | (op1 << (32 - op2)); +} + + +/** \brief Breakpoint + + This function 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) __ASM volatile ("bkpt "#value) + + +#if (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) + +/** \brief Reverse bit order of value + + This function reverses the bit order of the given value. + + \param [in] value Value to reverse + \return Reversed value + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); + return(result); +} + + +/** \brief LDR Exclusive (8 bit) + + This function executes a exclusive LDR instruction for 8 bit value. + + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrexb %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint8_t) result); /* Add explicit type cast here */ +} + + +/** \brief LDR Exclusive (16 bit) + + This function executes a exclusive LDR instruction for 16 bit values. + + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrexh %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint16_t) result); /* Add explicit type cast here */ +} + + +/** \brief LDR Exclusive (32 bit) + + This function executes a exclusive LDR instruction for 32 bit values. + + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("ldrex %0, %1" : "=r" (result) : "Q" (*addr) ); + return(result); +} + + +/** \brief STR Exclusive (8 bit) + + This function 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 + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) +{ + uint32_t result; + + __ASM volatile ("strexb %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** \brief STR Exclusive (16 bit) + + This function 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 + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) +{ + uint32_t result; + + __ASM volatile ("strexh %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" ((uint32_t)value) ); + return(result); +} + + +/** \brief STR Exclusive (32 bit) + + This function 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 + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("strex %0, %2, %1" : "=&r" (result), "=Q" (*addr) : "r" (value) ); + return(result); +} + + +/** \brief Remove the exclusive lock + + This function removes the exclusive lock which is created by LDREX. + + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void) +{ + __ASM volatile ("clrex" ::: "memory"); +} + + +/** \brief Signed Saturate + + This function 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(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + + +/** \brief Unsigned Saturate + + This function 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(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + + +/** \brief Count leading zeros + + This function 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 + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) ); + return ((uint8_t) result); /* Add explicit type cast here */ +} + + +/** \brief Rotate Right with Extend (32 bit) + + This function 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 + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RRX(uint32_t value) +{ + uint32_t result; + + __ASM volatile ("rrx %0, %1" : __CMSIS_GCC_OUT_REG (result) : __CMSIS_GCC_USE_REG (value) ); + return(result); +} + + +/** \brief LDRT Unprivileged (8 bit) + + This function executes a Unprivileged LDRT instruction for 8 bit value. + + \param [in] ptr Pointer to data + \return value of type uint8_t at (*ptr) + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDRBT(volatile uint8_t *addr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrbt %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrbt %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint8_t) result); /* Add explicit type cast here */ +} + + +/** \brief LDRT Unprivileged (16 bit) + + This function executes a Unprivileged LDRT instruction for 16 bit values. + + \param [in] ptr Pointer to data + \return value of type uint16_t at (*ptr) + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDRHT(volatile uint16_t *addr) +{ + uint32_t result; + +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) + __ASM volatile ("ldrht %0, %1" : "=r" (result) : "Q" (*addr) ); +#else + /* Prior to GCC 4.8, "Q" will be expanded to [rx, #0] which is not + accepted by assembler. So has to use following less efficient pattern. + */ + __ASM volatile ("ldrht %0, [%1]" : "=r" (result) : "r" (addr) : "memory" ); +#endif + return ((uint16_t) result); /* Add explicit type cast here */ +} + + +/** \brief LDRT Unprivileged (32 bit) + + This function executes a Unprivileged LDRT instruction for 32 bit values. + + \param [in] ptr Pointer to data + \return value of type uint32_t at (*ptr) + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDRT(volatile uint32_t *addr) +{ + uint32_t result; + + __ASM volatile ("ldrt %0, %1" : "=r" (result) : "Q" (*addr) ); + return(result); +} + + +/** \brief STRT Unprivileged (8 bit) + + This function executes a Unprivileged STRT instruction for 8 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __STRBT(uint8_t value, volatile uint8_t *addr) +{ + __ASM volatile ("strbt %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) ); +} + + +/** \brief STRT Unprivileged (16 bit) + + This function executes a Unprivileged STRT instruction for 16 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __STRHT(uint16_t value, volatile uint16_t *addr) +{ + __ASM volatile ("strht %1, %0" : "=Q" (*addr) : "r" ((uint32_t)value) ); +} + + +/** \brief STRT Unprivileged (32 bit) + + This function executes a Unprivileged STRT instruction for 32 bit values. + + \param [in] value Value to store + \param [in] ptr Pointer to location + */ +__attribute__( ( always_inline ) ) __STATIC_INLINE void __STRT(uint32_t value, volatile uint32_t *addr) +{ + __ASM volatile ("strt %1, %0" : "=Q" (*addr) : "r" (value) ); +} + +#endif /* (__CORTEX_M >= 0x03) || (__CORTEX_SC >= 300) */ + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ +#include + + +#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ +/* TI CCS specific functions */ +#include + + +#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ +/* TASKING carm specific functions */ +/* + * 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. + */ + + +#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/ +/* Cosmic specific functions */ +#include + +#endif + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + +#endif /* __CORE_CMINSTR_H */ diff --git a/bsp/nv32f100x/lib/inc/core_cmSimd.h b/bsp/nv32f100x/lib/inc/core_cmSimd.h new file mode 100644 index 0000000000000000000000000000000000000000..ee58eee56dd773194d453098a7f632aabf9610c0 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/core_cmSimd.h @@ -0,0 +1,697 @@ +/**************************************************************************//** + * @file core_cmSimd.h + * @brief CMSIS Cortex-M SIMD Header File + * @version V4.00 + * @date 22. August 2014 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2014 ARM LIMITED + + All rights reserved. + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + - Neither the name of ARM nor the names of its contributors may be used + to endorse or promote products derived from this software without + specific prior written permission. + * + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + ---------------------------------------------------------------------------*/ + + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#endif + +#ifndef __CORE_CMSIMD_H +#define __CORE_CMSIMD_H + +#ifdef __cplusplus + extern "C" { +#endif + + +/******************************************************************************* + * Hardware Abstraction Layer + ******************************************************************************/ + + +/* ################### Compiler specific Intrinsics ########################### */ +/** \defgroup CMSIS_SIMD_intrinsics CMSIS SIMD Intrinsics + Access to dedicated SIMD instructions + @{ +*/ + +#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ +/* ARM armcc specific functions */ +#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) << 32) ) >> 32)) + + +#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ +/* GNU gcc specific functions */ +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhadd8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsub8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHADD16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhadd16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSUB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsub16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHASX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhasx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("ssax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SHSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("shsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UQSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uqsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UHSAX(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uhsax %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USAD8(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("usad8 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __USADA8(uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("usada8 %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +#define __SSAT16(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("ssat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + +#define __USAT16(ARG1,ARG2) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1); \ + __ASM ("usat16 %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ + __RES; \ + }) + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTB16(uint32_t op1) +{ + uint32_t result; + + __ASM volatile ("uxtb16 %0, %1" : "=r" (result) : "r" (op1)); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __UXTAB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("uxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTB16(uint32_t op1) +{ + uint32_t result; + + __ASM volatile ("sxtb16 %0, %1" : "=r" (result) : "r" (op1)); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SXTAB16(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sxtab16 %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUAD (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smuad %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUADX (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smuadx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLAD (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlad %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLADX (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smladx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALD (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ // Little endian + __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else // Big endian + __ASM volatile ("smlald %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLALDX (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ // Little endian + __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else // Big endian + __ASM volatile ("smlaldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSD (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smusd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMUSDX (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("smusdx %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSD (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlsd %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMLSDX (uint32_t op1, uint32_t op2, uint32_t op3) +{ + uint32_t result; + + __ASM volatile ("smlsdx %0, %1, %2, %3" : "=r" (result) : "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLD (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ // Little endian + __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else // Big endian + __ASM volatile ("smlsld %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint64_t __SMLSLDX (uint32_t op1, uint32_t op2, uint64_t acc) +{ + union llreg_u{ + uint32_t w32[2]; + uint64_t w64; + } llr; + llr.w64 = acc; + +#ifndef __ARMEB__ // Little endian + __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[0]), "=r" (llr.w32[1]): "r" (op1), "r" (op2) , "0" (llr.w32[0]), "1" (llr.w32[1]) ); +#else // Big endian + __ASM volatile ("smlsldx %0, %1, %2, %3" : "=r" (llr.w32[1]), "=r" (llr.w32[0]): "r" (op1), "r" (op2) , "0" (llr.w32[1]), "1" (llr.w32[0]) ); +#endif + + return(llr.w64); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SEL (uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("sel %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QADD(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qadd %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __QSUB(uint32_t op1, uint32_t op2) +{ + uint32_t result; + + __ASM volatile ("qsub %0, %1, %2" : "=r" (result) : "r" (op1), "r" (op2) ); + return(result); +} + +#define __PKHBT(ARG1,ARG2,ARG3) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ + __ASM ("pkhbt %0, %1, %2, lsl %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ + __RES; \ + }) + +#define __PKHTB(ARG1,ARG2,ARG3) \ +({ \ + uint32_t __RES, __ARG1 = (ARG1), __ARG2 = (ARG2); \ + if (ARG3 == 0) \ + __ASM ("pkhtb %0, %1, %2" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2) ); \ + else \ + __ASM ("pkhtb %0, %1, %2, asr %3" : "=r" (__RES) : "r" (__ARG1), "r" (__ARG2), "I" (ARG3) ); \ + __RES; \ + }) + +__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __SMMLA (int32_t op1, int32_t op2, int32_t op3) +{ + int32_t result; + + __ASM volatile ("smmla %0, %1, %2, %3" : "=r" (result): "r" (op1), "r" (op2), "r" (op3) ); + return(result); +} + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ +#include + + +#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ +/* TI CCS specific functions */ +#include + + +#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ +/* TASKING carm specific functions */ +/* not yet supported */ + + +#elif defined ( __CSMC__ ) /*------------------ COSMIC Compiler -------------------*/ +/* Cosmic specific functions */ +#include + +#endif + +/*@} end of group CMSIS_SIMD_intrinsics */ + + +#ifdef __cplusplus +} +#endif + +#endif /* __CORE_CMSIMD_H */ diff --git a/bsp/nv32f100x/lib/inc/crc.h b/bsp/nv32f100x/lib/inc/crc.h new file mode 100644 index 0000000000000000000000000000000000000000..64824624c5912aa182d2b45569b046d6df998023 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/crc.h @@ -0,0 +1,109 @@ +/****************************************************************************** +* +* @brief Cyclic redundancy check (CRC) header file. +* +******************************************************************************/ +#ifndef CRC_H_ +#define CRC_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ + + +/****************************************************************************** +* CRC control bit definition +* +*//*! @addtogroup crc_controlbit +* @{ +*******************************************************************************/ + +/*! + * @brief CRC control register bit definition. + * + */ + +#define CRC_WIDTH_16BIT 0 /*!< select CRC16 protocol */ +#define CRC_WIDTH_32BIT 1 /*!< select CRC32 protocol */ +#define CRC_DATA_SEED 1 /*!< Write CRC Data Register are seed */ +#define CRC_DATA_DATA 0 /*!< Write CRC Data Register are data */ +#define CRC_READ_COMPLETE 1 /*!< Invert or complement read CRC Data register */ +#define CRC_READ_NONE 0 /*!< No XOR on reading */ +#define CRC_READ_TRANSPOSE_NONE 0 /*!< No transposition in read */ +#define CRC_READ_TRANSPOSE_BIT 1 /*!< only bits in bytes are transposed in read */ +#define CRC_READ_TRANSPOSE_ALL 2 /*!< both bits in bytes and bytes are transposed in read */ +#define CRC_READ_TRANSPOSE_BYTE 3 /*!< only bytes are transposed in read */ +#define CRC_WRITE_TRANSPOSE_NONE 0 /*!< No transposition write */ +#define CRC_WRITE_TRANSPOSE_BIT 1 /*!< only bits in bytes are transposed in write */ +#define CRC_WRITE_TRANSPOSE_ALL 2 /*!< both bits in bytes and bytes are transposed in write */ +#define CRC_WRITE_TRANSPOSE_BYTE 3 /*!< only bytes are transposed in write */ + +/*! @} End of crc_controlbit */ + + +/****************************************************************************** +* Types +******************************************************************************/ +/* CRC configuration structure + */ +/****************************************************************************** +* CRC Configuration Structure type. +* +*//*! @addtogroup crc_config_type +* @{ +*******************************************************************************/ +/*! + * @brief CRC Configuration Structure. + * + */ + +typedef struct +{ + uint8_t bWidth : 1; /*!< 1: 32-bit CRC protocol , 0: 16-bit CRC protocol */ + uint8_t bDataType : 1; /*!< 1: write seed , 0: write data */ + uint8_t bFinalXOR : 1; /*!< 1: Invert or complement read , 0: No XOR on reading */ + uint8_t bRESERVED : 1; /*!< reserved bit */ + uint8_t bTransposeReadType : 2; /*!< type of transpose For read, see reference manual */ + uint8_t bTransposeWriteType : 2; /*!< type of transpose For write, see reference manual */ + uint32_t u32PolyData ; /*!< 32bit or 16-biy poly data */ +} CRC_ConfigType, *CRC_ConfigPtr ; +/*! @} End of crc_config_type */ + + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* CRC API list +* +*//*! @addtogroup crc_api_list +* @{ +*******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ +void CRC_Init(CRC_ConfigType *pConfig); +uint32_t CRC_Cal16(uint32_t u32Seed, uint8_t *msg, uint32_t u32SizeBytes); +uint32_t CRC_Cal32(uint32_t u32Seed, uint8_t *msg, uint32_t u32SizeBytes); +void CRC_DeInit(void); +/*! @} End of crc_api_list */ + +#ifdef __cplusplus +} +#endif +#endif /* CRC_H_ */ + + + diff --git a/bsp/nv32f100x/lib/inc/eeprom.h b/bsp/nv32f100x/lib/inc/eeprom.h new file mode 100644 index 0000000000000000000000000000000000000000..711aeda0898a70d1ed2266550306d236ecfb4225 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/eeprom.h @@ -0,0 +1,28 @@ +#ifndef EEPROM_H_ +#define EEPROM_H_ + +/****************************************************************************** +* Includes +******************************************************************************/ +#include "common.h" + +#define EERPOM_SIZE 1024 // in bytes +#define EEPROM_START_ADR 0x00401000 +#define EEPROM_ERR_SUCCESS 0x01 +#define EEPROM_ADR_OverFlow 0x02 +#define EEPROM_ERR_INVALID_PARAM 0x04 +#define EEPROM_BLANK 0xffffffff +#define EEPROM_SECTOR_MASK 0x00401200 +#define EEPROM_ARRAY_ADR_MASK 0x1ff + + +uint16_t Adress_Js(uint32_t adr); +uint16_t EEPROM_Erase(uint32_t adr); +uint32_t EEPROM_Read(uint32_t adr); +uint8_t EEPROM_ReadByte(uint32_t adr); + + +uint16_t EEPROM_Write(uint32_t adr, uint32_t Data); +uint16_t EEPROM_WriteByte(uint32_t adr, uint8_t Data); +uint16_t EERPOM_Writeup4byte(uint32_t adr, uint8_t *pData,uint32_t length); +#endif diff --git a/bsp/nv32f100x/lib/inc/etm.h b/bsp/nv32f100x/lib/inc/etm.h new file mode 100644 index 0000000000000000000000000000000000000000..4800c4fa9924667e64025e3841ac89e23b636b25 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/etm.h @@ -0,0 +1,1166 @@ +/****************************************************************************** +* @brief header file for ETM. +* +******************************************************************************* +* +* provide APIs for accessing ETM +******************************************************************************/ +#ifndef ETM_H_ +#define ETM_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ + +/****************************************************************************** +* ETM return status definition +* +*//*! @addtogroup ETM_returnstatus +* @{ +*******************************************************************************/ +#define ETM_ERR_SUCCESS 0 /*!< return ok */ +#define ETM_ERR_INVALID_PARAM 1 /*!< return invalid parameter */ +/*! @} End of ETM_returnstatus */ + + +/****************************************************************************** +* ETM channel number definition +* +*//*! @addtogroup ETM_channelnumber +* @{ +*******************************************************************************/ +#define ETM_CHANNEL_CHANNEL0 0 /*!< channel 0 */ +#define ETM_CHANNEL_CHANNEL1 1 /*!< channel 1 */ +#define ETM_CHANNEL_CHANNEL2 2 /*!< channel 2 */ +#define ETM_CHANNEL_CHANNEL3 3 /*!< channel 3 */ +#define ETM_CHANNEL_CHANNEL4 4 /*!< channel 4 */ +#define ETM_CHANNEL_CHANNEL5 5 /*!< channel 5 */ + +#define ETM_CHANNELPAIR0 0 /*!< channel pair 0:ch0 & ch1 */ +#define ETM_CHANNELPAIR1 2 /*!< channel pair 1:ch2 & ch3 */ +#define ETM_CHANNELPAIR2 4 /*!< channel pair 2:ch4 & ch5 */ + +/*! @} End of ETM_channelnumber */ + +/****************************************************************************** +* ETM pwm mode definition +* +*//*! @addtogroup ETM_pwmmode +* @{ +*******************************************************************************/ +#define ETM_PWMMODE_EDGEALLIGNED 1 /*!< EPWM */ +#define ETM_PWMMODE_CENTERALLIGNED 2 /*!< CPWM */ +#define ETM_PWMMODE_COMBINE 3 /*!< Combine PWM */ +/*! @} End of ETM_pwmmode */ + +/****************************************************************************** +* ETM init value definition +* +*//*! @addtogroup ETM_initvalue +* @{ +*******************************************************************************/ +#define ETM_MOD_INIT (20000-1) /*!< MOD inite value */ +#define ETM_C0V_INIT 1000 /*!< C0V inite value */ +#define ETM_C1V_INIT 1000 /*!< C1V inite value */ +#define ETM_C2V_INIT 1000 /*!< C2V inite value */ +#define ETM_C3V_INIT 1000 /*!< C3V inite value */ +#define ETM_C4V_INIT 1000 /*!< C4V inite value */ +#define ETM_C5V_INIT 1000 /*!< C5V inite value */ +/*! @} End of ETM_initvalue */ + +/****************************************************************************** +* ETM combine feature definition +* +*//*! @addtogroup ETM_combinefeature +* @{ +*******************************************************************************/ +#define ETM_COMBINE_FAULTEN_MASK 0x40 /*!< fault enable */ +#define ETM_COMBINE_SYNCEN_MASK 0x20 /*!< sync enable */ +#define ETM_COMBINE_DTEN_MASK 0x10 /*!< dead ETMe insertion enable */ +#define ETM_COMBINE_DECAP_MASK 0x08 /*!< dual capture status */ +#define ETM_COMBINE_DECAPEN_MASK 0x04 /*!< dual capture enable */ +#define ETM_COMBINE_COMP_MASK 0x02 /*!< complementary enable */ +#define ETM_COMBINE_COMBINE_MASK 0x01 /*!< combine enable */ +/*! @} End of ETM_combinefeature */ + +/****************************************************************************** +* ETM clock sources definition +* +*//*! @addtogroup ETM_clocksource +* @{ +*******************************************************************************/ +#define ETM_CLOCK_NOCLOCK 0 /*!< No Clock */ +#define ETM_CLOCK_SYSTEMCLOCK 1 /*!< System clock/2 */ +#define ETM_CLOCK_FIXEDFREQCLOCK 2 /*!< Fixed Freq Clock */ +#define ETM_CLOCK_EXTERNALCLOCK 3 /*!< External Clock */ + +/* clock prescale */ +#define ETM_CLOCK_PS_DIV1 0 /*!< DIV 1 */ +#define ETM_CLOCK_PS_DIV2 1 /*!< DIV 2 */ +#define ETM_CLOCK_PS_DIV4 2 /*!< DIV 4 */ +#define ETM_CLOCK_PS_DIV8 3 /*!< DIV 8 */ +#define ETM_CLOCK_PS_DIV16 4 /*!< DIV 16 */ +#define ETM_CLOCK_PS_DIV32 5 /*!< DIV 32 */ +#define ETM_CLOCK_PS_DIV64 6 /*!< DIV 64 */ +#define ETM_CLOCK_PS_DIV128 7 /*!< DIV 128 */ +/*! @} End of ETM_clocksource */ + +/****************************************************************************** +* ETM dead ETMe clock prescale definition +* +*//*! @addtogroup ETM_deadETMeprescale +* @{ +*******************************************************************************/ +/* */ +#define ETM_DEADETME_DTPS_DIV1 0 /*!< DIV 1 */ +#define ETM_DEADETME_DTPS_DIV4 2 /*!< DIV 4 */ +#define ETM_DEADETME_DTPS_DIV16 3 /*!< DIV 16 */ +/*! @} End of ETM_deadETMeprescale */ + +/****************************************************************************** +* ETM output mode definition +* +*//*! @addtogroup ETM_outputmode +* @{ +*******************************************************************************/ +/* output mode */ +#define ETM_OUTPUT_TOGGLE 1 /*!< toggle output on match */ +#define ETM_OUTPUT_CLEAR 2 /*!< clear output on match */ +#define ETM_OUTPUT_SET 3 /*!< set output on match */ +/*! @} End of ETM_outputmode */ + +/****************************************************************************** +* ETM input capture edge definition +* +*//*! @addtogroup ETM_inputcaptureedge +* @{ +*******************************************************************************/ +/* mode edge select*/ +#define ETM_INPUTCAPTURE_RISINGEDGE 1 /*!< rising edge */ +#define ETM_INPUTCAPTURE_FALLINGEDGE 2 /*!< falling edge */ +#define ETM_INPUTCAPTURE_BOTHEDGE 3 /*!< both edge */ + +#define ETM_INPUTCAPTURE_DUALEDGE_NOEDGE 0 /*!< none */ +#define ETM_INPUTCAPTURE_DUALEDGE_RISINGEDGE 1 /*!< rising edge*/ +#define ETM_INPUTCAPTURE_DUALEDGE_FALLInGEDGE 2 /*!< falling edge*/ +#define ETM_INPUTCAPTURE_DUALEDGE_BOTHEDGE 3 /*!< both edge */ +/*! @} End of ETM_inputcaptureedge */ + +/****************************************************************************** +* ETM dual edge capture mode definition +* +*//*! @addtogroup ETM_dualcapturemode +* @{ +*******************************************************************************/ +#define ETM_INPUTCAPTURE_DUALEDGE_ONESHOT 4 /*!< dual edge one shot mode*/ +#define ETM_INPUTCAPTURE_DUALEDGE_CONTINUOUS 5 /*!< dual edge continuouse mode*/ +/*! @} End of ETM_dualcapturemode */ + +/****************************************************************************** +* ETM PWM edge definition +* +*//*! @addtogroup ETM_pwmedge +* @{ +*******************************************************************************/ +#define ETM_PWM_HIGHTRUEPULSE 1 /*!< high true pulses */ +#define ETM_PWM_LOWTRUEPULSE 2 /*!< low true pulses */ +/*! @} End of ETM_pwmedge */ + +/****************************************************************************** +* ETM sync trigger source definition +* +*//*! @addtogroup ETM_syncsource +* @{ +*******************************************************************************/ +#define ETM_SYNC_TRIGGER_SOFTWARE 1 /*!< Software synchronization */ +#define ETM_SYNC_TRIGGER_TRIGGER2 2 /*!< Tigger2 synchronization, SIM_SOPT[ETMSYNC] */ +#define ETM_SYNC_TRIGGER_TRIGGER1 3 /*!< Tigger1 synchronization, ETM0CH0 */ +#define ETM_SYNC_TRIGGER_TRIGGER0 4 /*!< Tigger0 synchronization, ACMP0 */ +/*! @} End of ETM_syncsource */ + +/****************************************************************************** +* ETM SW output control definition +* +*//*! @addtogroup ETM_swoutputcontrol +* @{ +*******************************************************************************/ +#define ETM_SWOCTRL_HIGH 1 /*!< software output high */ +#define ETM_SWOCTRL_LOW 0 /*!< software output low */ +/*! @} End of ETM_swoutputcontrol */ + +/****************************************************************************** +* ETM polarity definition +* +*//*! @addtogroup ETM_polarity +* @{ +*******************************************************************************/ +#define ETM_POLARITY_HIGHACTIVE 0 /*!< active high */ +#define ETM_POLARITY_LOWACTIVE 1 /*!< active low */ +/*! @} End of ETM_polarity */ + + +/****************************************************************************** +* Types +******************************************************************************/ +/*! @brief ETM_CALLBACK function declaration */ +typedef void (*ETM_CallbackPtr)(void); +/*! @} End of ETM_callback */ + +/****************************************************************************** +* ETM configure struct. +* +*//*! @addtogroup ETM_configsturct +* @{ +*******************************************************************************/ +/*! +* @brief ETM configure struct. +* +*/ + +typedef struct +{ + uint8_t clk_source; /*!< clock source */ + uint8_t prescaler; /*!< clock prescaler */ + uint8_t sc; /*!< status and control */ + uint16_t modulo; /*!< counter mod */ + uint16_t cnt; /*!< counter value */ + uint16_t cntin; /*!< counter inite */ + uint8_t mode; /*!< features mode selction */ + uint8_t sync; /*!< synchronization */ + uint8_t outinit; /*!< initial state for channels output */ + uint8_t outmask; /*!< output mask */ + uint32_t combine; /*!< function for linked channels */ + uint16_t deadETMe; /*!< dead ETMe insertion control */ + uint8_t exttrig; /*!< external trigger */ + uint8_t pol; /*!< channels polarity */ + uint16_t filter; /*!< input filter control */ + uint8_t fms; /*!< fault mode status */ + uint16_t fltctrl; /*!< fault control */ + uint8_t fltpol; /*!< fault input polarity */ + uint16_t conf; /*!< ETM configuration */ + uint32_t synconf; /*!< synchronization configuration*/ + uint8_t invctrl; /*!< inverting control */ + uint16_t swoctrl; /*!< software output control */ + uint16_t pwmload; /*!< pwm load control */ +} ETM_ConfigType, *ETM_ConfigPtr; +/*! @} End of ETM_configsturct */ + +/****************************************************************************** +* ETM channel configure struct. +* +*//*! @addtogroup ETM_chconfigsturct +* @{ +*******************************************************************************/ +/*! +* @brief ETM channel configure struct. +* +*/ +typedef struct +{ + uint8_t u8CnSC; /*!< ETM channel status and control */ + uint16_t u16CnV; /*!< ETM channel value control */ + union + { + uint32_t u32dw; + struct + { + uint32_t bMode : 3; /*!< flexETMer mode: GPIO, INPUT_CAPTURE, OUTPUT_COMPARE, EDGE_ALIGNED_PWM, CENTER_ALIGNED_PWM, + * COMBINE_PWM, DUAL_EDGE_CAPTURE + */ + uint32_t bEdge : 2; /*!< edge select */ + uint32_t bOutCmp : 2; /*!< toggle, clear, set */ + uint32_t bPWMPol : 1; /*!< high-true pulse, low-true pulses */ + uint32_t bDualCapMode : 1; /*!< dual edge capture mode: one-shot, continuous mode */ + uint32_t bCHIE : 1; /*!< enable channel interrupt */ + }bits; + }ctrl; /*!< ETM channel feature control */ +} ETM_ChParamsType; + +/*! @} End of ETM_chconfigsturct */ + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/*! + * inline functions + */ +/****************************************************************************** +* ETM inline functions +* +*//*! @addtogroup ETM_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! +* +* @brief enable the over flow interrupt. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_DisableOverflowInt. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_EnableOverflowInt(ETM_Type *pETM) +{ + if(pETM->SC & ETM_SC_TOF_MASK) + { + pETM->SC &= ~ETM_SC_TOF_MASK; + } + pETM->SC |= ETM_SC_TOIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable the over flow interrupt. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see ETM_EnableOverflowInt. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_DisableOverflowInt(ETM_Type *pETM) +{ + pETM->SC &= ~ETM_SC_TOIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief enable the channel interrupt. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8ETM_Channel channel number. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_DisableChannelInt. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_EnableChannelInt(ETM_Type *pETM, uint8_t u8ETM_Channel) +{ + pETM->CONTROLS[u8ETM_Channel].CnSC |= ETM_CnSC_CHIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable the channel interrupt. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8ETM_Channel channel number. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_EnableChannelInt. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_DisableChannelInt(ETM_Type *pETM, uint8_t u8ETM_Channel) +{ + pETM->CONTROLS[u8ETM_Channel].CnSC &= ~ETM_CnSC_CHIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief get the over flow flag. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_ClrOverFlowFlag. +* +*****************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetOverFlowFlag(ETM_Type *pETM) +{ + return (pETM->SC & ETM_SC_TOF_MASK); +} + +/*****************************************************************************//*! +* +* @brief clear the over flow flag. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_GetOverFlowFlag. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_ClrOverFlowFlag(ETM_Type *pETM) +{ + if(pETM->SC & ETM_SC_TOF_MASK) + { + pETM->SC &= ~ETM_SC_TOF_MASK; + } +} + +/*****************************************************************************//*! +* +* @brief get the channel flag. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8ETM_Channel channel number. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_ClrChannelFlag. +* +*****************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetChannelFlag(ETM_Type *pETM, uint8_t u8ETM_Channel) +{ + return (pETM->CONTROLS[u8ETM_Channel].CnSC & ETM_CnSC_CHF_MASK); +} + +/*****************************************************************************//*! +* +* @brief clear the channel flag. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_GetChannelFlag. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_ClrChannelFlag(ETM_Type *pETM, uint8_t u8ETM_Channel) +{ + pETM->CONTROLS[u8ETM_Channel].CnSC &= ~ETM_CnSC_CHF_MASK; +} + +/*********************************************************************************//*! +* +* @brief enable the write protection function.Write protected bits cannot be written. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_WriteProtectionDisable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_WriteProtectionEnable(ETM_Type *pETM) +{ + pETM->FMS |= ETM_FMS_WPEN_MASK; +} + +/*********************************************************************************//*! +* +* @brief disable the write protection function.Write protected bits can be written. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_WriteProtectionDisable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_WriteProtectionDisable(ETM_Type *pETM) +{ + if (pETM->FMS & ETM_FMS_WPEN_MASK) + { + pETM->MODE |= ETM_MODE_WPDIS_MASK; + } +} + +/*****************************************************************************//*! +* +* @brief set ETMEN bit to enable ETM-specific register. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetETMBasic. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_SetETMEnhanced(ETM_Type *pETM) +{ + if(pETM->MODE & ETM_MODE_WPDIS_MASK) /* if not write protected */ + { + pETM->MODE |= ETM_MODE_ETMEN_MASK; + } + else + { + ETM_WriteProtectionDisable(pETM); + pETM->MODE |= ETM_MODE_ETMEN_MASK; + ETM_WriteProtectionEnable(pETM); + } +} + +/*****************************************************************************//*! +* +* @brief clear ETMEN bit to disable ETM-specific registers, only TPM-compatible +* registers can be used. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetETMEnhanced. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_SetETMBasic(ETM_Type *pETM) +{ + if(pETM->MODE & ETM_MODE_WPDIS_MASK) /* if not write protected */ + { + pETM->MODE &= ~ETM_MODE_ETMEN_MASK; + } + else + { + ETM_WriteProtectionDisable(pETM); + pETM->MODE &= ~ETM_MODE_ETMEN_MASK; + ETM_WriteProtectionEnable(pETM); + } +} + +/*****************************************************************************//*! +* +* @brief set the ETM mod value. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u16ModValue the mod value required to set. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetChannelValue. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_SetModValue(ETM_Type *pETM, uint16_t u16ModValue) +{ + pETM->CNT = 0; + pETM->MOD = u16ModValue; + if(ETM2 == pETM) + { + if(pETM->MODE & ETM_MODE_ETMEN_MASK) + { + pETM->PWMLOAD |= ETM_PWMLOAD_LDOK_MASK; + } + else + { + } + } + else + { + } +} + +/*****************************************************************************//*! +* +* @brief set the ETM channel value. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u16ChannelValue the CnV value required to set. +* @param[in] u8ETM_Channel ETM channel number. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetModValue. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_SetChannelValue(ETM_Type *pETM, uint8_t u8ETM_Channel, uint16_t u16ChannelValue) +{ + pETM->CONTROLS[u8ETM_Channel].CnV = u16ChannelValue; + if(ETM2 == pETM) + { + if(pETM->MODE & ETM_MODE_ETMEN_MASK) + { + if(u8ETM_Channel < 2) + { + pETM->COMBINE |= ETM_COMBINE_SYNCEN0_MASK; /* enable the sync function */ + } + else if (u8ETM_Channel < 4) + { + pETM->COMBINE |= ETM_COMBINE_SYNCEN1_MASK; + } + else + { + pETM->COMBINE |= ETM_COMBINE_SYNCEN2_MASK; + } + pETM->PWMLOAD |= ETM_PWMLOAD_LDOK_MASK; + } + else + { + } + } + else + { + } +} + +/*****************************************************************************//*! +* +* @brief set the ETM channel value. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u16CounterValue the CNTIN value required to set. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see ETM_SetModValue. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_SetCounterInitValue(ETM_Type *pETM, uint16_t u16CounterValue) +{ + pETM->CNTIN = u16CounterValue; + if(pETM->MODE & ETM_MODE_ETMEN_MASK) + { + pETM->PWMLOAD |= ETM_PWMLOAD_LDOK_MASK; + } + else + { + } +} + +/*****************************************************************************//*! +* +* @brief set the channel output mask value, ETM2 used only. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u16ChMask the CNTIN value required to set. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see ETM_UnMaskChannels. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_MaskChannels(ETM_Type *pETM, uint16_t u16ChMask) +{ + pETM->OUTMASK |= u16ChMask; +} + +/*****************************************************************************//*! +* +* @brief clear the channel output mask value, ETM2 used only. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u16ChMask the CNTIN value required to set. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see ETM_MaskChannels. +* +*****************************************************************************/ +__STATIC_INLINE void ETM_UnMaskChannels(ETM_Type *pETM, uint16_t u16ChMask) +{ + pETM->OUTMASK &= ~u16ChMask; +} + +/*********************************************************************************//*! +* +* @brief set ETM channels polarity. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8ChsPolValue the channels value need to be set. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_GetChannelsPolarity. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_SetChannelsPolarity(ETM_Type *pETM, uint8_t u8ChsPolValue) +{ + pETM->POL = u8ChsPolValue; +} + +/*********************************************************************************//*! +* +* @brief get ETM channels polarity. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return uint8_t the channels polarity. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetChannelsPolarity. +* +*********************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetChannelsPolarity(ETM_Type *pETM) +{ + return (pETM->POL); +} + +/*********************************************************************************//*! +* +* @brief select the enhanced SYNC mode. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_DisableEnhancedSYNCMode. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_EnableEnhancedSYNCMode(ETM_Type *pETM) +{ + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; /* recommend enhanced sync mode */ +} + +/*********************************************************************************//*! +* +* @brief select the legacy SYNC mode. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_EnableEnhancedSYNCMode. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_DisableEnhancedSYNCMode(ETM_Type *pETM) +{ + pETM->SYNCONF &= ~ETM_SYNCONF_SYNCMODE_MASK; /* recommend enhanced sync mode */ +} + +/*********************************************************************************//*! +* +* @brief set the external trigger source. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8TirggerSource initial trigger or CHn(0~5)trigger +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_GetExternalTriggerFlag. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_SetExternalTrigger(ETM_Type *pETM, uint8_t u8TirggerSource) +{ + pETM->EXTTRIG = u8TirggerSource; +} + +/*********************************************************************************//*! +* +* @brief get the external trigger flag. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return ex trigger flag. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetExternalTrigger. +* +*********************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetExternalTriggerFlag(ETM_Type *pETM) +{ + return (pETM->EXTTRIG & ETM_EXTTRIG_TRIGF_MASK); +} + +/*********************************************************************************//*! +* +* @brief set LDOK bit. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetLoadMatchChannel. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_SetLoadEnable(ETM_Type *pETM) +{ + pETM->PWMLOAD |= ETM_PWMLOAD_LDOK_MASK; +} + +/*********************************************************************************//*! +* +* @brief set the channel in the matching process. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8Matchchannel the channel in the matching process. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_SetLoadEnable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_SetLoadMatchChannel(ETM_Type *pETM, uint8_t u8Matchchannel) +{ + pETM->PWMLOAD |= u8Matchchannel; +} + +/*********************************************************************************//*! +* +* @brief disable the channel input capture filter. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8ETM_Channel the channel number: 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_InputCaptureFilterSet. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_InputCaptureFilterClr(ETM_Type *pETM, uint8_t u8ETM_Channel) +{ + pETM->FILTER &= ~(0x000F << (u8ETM_Channel << 2)); +} + +/*********************************************************************************//*! +* +* @brief set the channel input capture filter value. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8ETM_Channel the channel number: 0~3. +* @param[in] u8FilterValue fliter cycles:1~15, 0: disable channel filter. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_InputCaptureFilterClr. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_InputCaptureFilterSet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8FilterValue) +{ + if (u8FilterValue) + { + pETM->FILTER |= (u8FilterValue << (u8ETM_Channel << 2)); + } + else + { + ETM_InputCaptureFilterClr(pETM, u8ETM_Channel); + } +} + + +/*********************************************************************************//*! +* +* @brief enable the fault input pin. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8FaultPin the fault input channel number: 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_FaultPinDisable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_FaultPinEnable(ETM_Type *pETM, uint8_t u8FaultPin) +{ + if (pETM->MODE & ETM_MODE_WPDIS_MASK) /* if not protected */ + { + pETM->FLTCTRL |= (1 << u8FaultPin); + } + else /* if protected */ + { + ETM_WriteProtectionDisable(pETM); + pETM->FLTCTRL |= (1 << u8FaultPin); + ETM_WriteProtectionEnable(pETM); + } +} + +/*********************************************************************************//*! +* +* @brief disable the fault input pin. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8FaultPin the fault input channel number: 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_FaultPinEnable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_FaultPinDisable(ETM_Type *pETM, uint8_t u8FaultPin) +{ + if (pETM->MODE & ETM_MODE_WPDIS_MASK) /* if not protected */ + { + pETM->FLTCTRL &= ~(1 << u8FaultPin); + } + else /* if protected */ + { + ETM_WriteProtectionDisable(pETM); + pETM->FLTCTRL &= ~(1 << u8FaultPin); + ETM_WriteProtectionEnable(pETM); + } +} + +/*********************************************************************************//*! +* +* @brief enable the fault pin filter. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8FaultPin the fault input channel number: 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_FaultPinFilterDisable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_FaultPinFilterEnable(ETM_Type *pETM, uint8_t u8FaultPin) +{ + if (pETM->MODE & ETM_MODE_WPDIS_MASK) /* if not protected */ + { + pETM->FLTCTRL |= (0x10 << u8FaultPin); + } + else /* if protected */ + { + ETM_WriteProtectionDisable(pETM); + pETM->FLTCTRL |= (0x10 << u8FaultPin); + ETM_WriteProtectionEnable(pETM); + } +} + +/*********************************************************************************//*! +* +* @brief disable the fault pin filter. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8FaultPin the fault input channel number: 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_FaultPinFilterDisable. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_FaultPinFilterDisable(ETM_Type *pETM, uint8_t u8FaultPin) +{ + if (pETM->MODE & ETM_MODE_WPDIS_MASK) /* if not protected */ + { + pETM->FLTCTRL &= ~(0x10 << u8FaultPin); + } + else /* if protected */ + { + ETM_WriteProtectionDisable(pETM); + pETM->FLTCTRL &= ~(0x10 << u8FaultPin); + ETM_WriteProtectionEnable(pETM); + } +} + +/*********************************************************************************//*! +* +* @brief disable all the fault pins filter together. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_FaultPinFilterSet. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_FaultPinFilterCDisableAll(ETM_Type *pETM) +{ + pETM->FLTCTRL &= ~ETM_FLTCTRL_FFVAL_MASK; +} + +/*********************************************************************************//*! +* +* @brief set the fault filter value. All channels share the same filter value. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8FilterValue the fault input filter value: 1~15, 0 disable the filter. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_FaultPinFilterCDisableAll. +* +*********************************************************************************/ +__STATIC_INLINE void ETM_FaultPinFilterSet(ETM_Type *pETM, uint8_t u8FilterValue) +{ + if (u8FilterValue) + { + pETM->FLTCTRL |= ETM_FLTCTRL_FFVAL(u8FilterValue); + } + else + { + ETM_FaultPinFilterCDisableAll(pETM); + } +} + +/*********************************************************************************//*! +* +* @brief get the logic OR of all the fault detection flags +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_GetFaultDetectionFlag. +* +*********************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetFaultDetectionLogicORFlag(ETM_Type *pETM) +{ + return (pETM->FMS & ETM_FMS_FAULTF_MASK); +} + +/*********************************************************************************//*! +* +* @brief get the fault detection flag +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8FaultPin fault input pin number: 0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ETM_GetFaultDetectionLogicORFlag. +* +*********************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetFaultDetectionFlag(ETM_Type *pETM, uint8_t u8FaultPin) +{ + return (pETM->FMS & (1 << u8FaultPin)); +} + +/*********************************************************************************//*! +* +* @brief get the logic OR value of the fault inputs +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +__STATIC_INLINE uint8_t ETM_GetFaultInputsLogicORValue(ETM_Type *pETM) +{ + return (pETM->FMS & ETM_FMS_FAULTIN_MASK); +} + +/*! @} End of ETM_api_list */ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +void ETM_ClockSet(ETM_Type *pETM, uint8_t u8ClockSource, uint8_t u8ClockPrescale); +void ETM_PWMInit(ETM_Type *pETM, uint8_t u8PWMModeSelect, uint8_t u8PWMEdgeSelect); +void ETM_InputCaptureInit(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8CaptureMode); +void ETM_DualEdgeCaptureInit(ETM_Type *pETM, uint8_t u8ChannelPair, uint8_t u8CaptureMode, + uint8_t u8Channel_N_Edge, uint8_t u8Channel_Np1_Edge); +void ETM_OutputCompareInit(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8CompareMode); +void ETM_SoftwareSync(ETM_Type *pETM); +void ETM_HardwareSync(ETM_Type *pETM, uint8_t u8TriggerN); +void ETM_HardwareSyncCombine(ETM_Type *pETM, uint8_t u8TriggerMask); +void ETM_GenerateTrig2(ETM_Type *pETM); +void ETM_PWMDeadETMeSet(ETM_Type *pETM, uint8_t u8PrescalerValue, uint8_t u8DeadETMeValue); +void ETM_OutputMaskSet(ETM_Type *pETM, uint8_t u8ETM_Channel); +void ETM_SWOutputControlSet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8ChannelValue); +void ETM_SetDebugModeBehavior(ETM_Type *pETM, uint8_t u8DebugMode); +void ETM_SetTOFFrequency(ETM_Type *pETM, uint8_t u8TOFNUM); +void ETM_PolaritySet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8ActiveValue); +void ETM_InvertChannel(ETM_Type *pETM, uint8_t u8ChannelPair); +void ETM_Init(ETM_Type *pETM, ETM_ConfigType *pConfig); +void ETM_DeInit(ETM_Type *pETM); +void ETM_ChannelInit(ETM_Type *pETM, uint8_t u8ETM_Channel, ETM_ChParamsType *pETM_ChParams); +void ETM_SetDutyCycleCombine(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8DutyCycle); +void ETM_SetCallback(ETM_Type *pETM, ETM_CallbackPtr pfnCallback); +void ETM_SyncConfigActivate(ETM_Type *pETM, uint32_t u32ConfigValue); +void ETM_SyncConfigDeactivate(ETM_Type * pETM, uint32_t u32ConfigValue); +uint8_t ETM_GetFaultDetectionLogicORFlag(ETM_Type *pETM); +uint8_t ETM_GetFaultDetectionFlag(ETM_Type *pETM, uint8_t u8FaultPin); +uint8_t ETM_GetFaultInputsLogicORValue(ETM_Type *pETM); +void ETM_WriteProtectionEnable(ETM_Type *pETM); +void ETM_WriteProtectionDisable(ETM_Type *pETM); +void ETM_FaultPinFilterCDisableAll(ETM_Type *pETM); +void ETM_FaultPinFilterSet(ETM_Type *pETM, uint8_t u8FilterValue); +void ETM_FaultPinFilterDisable(ETM_Type *pETM, uint8_t u8FaultPin); +void ETM_FaultPinFilterEnable(ETM_Type *pETM, uint8_t u8FaultPin); +void ETM_FaultPinEnable(ETM_Type *pETM, uint8_t u8FaultPin); +void ETM_FaultPinDisable(ETM_Type *pETM, uint8_t u8FaultPin); +void ETM_InputCaptureFilterClr(ETM_Type *pETM, uint8_t u8ETM_Channel); +void ETM_InputCaptureFilterSet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8FilterValue); +void ETM_SetLoadMatchChannel(ETM_Type *pETM, uint8_t u8Matchchannel); +void ETM_SetLoadEnable(ETM_Type *pETM); +uint8_t ETM_GetExternalTriggerFlag(ETM_Type *pETM); +void ETM_DisableEnhancedSYNCMode(ETM_Type *pETM); +void ETM_EnableEnhancedSYNCMode(ETM_Type *pETM); +uint8_t ETM_GetChannelsPolarity(ETM_Type *pETM); +void ETM_SetChannelsPolarity(ETM_Type *pETM, uint8_t u8ChsPolValue); +void ETM_UnMaskChannels(ETM_Type *pETM, uint16_t u16ChMask); +void ETM_MaskChannels(ETM_Type *pETM, uint16_t u16ChMask); +void ETM_SetCounterInitValue(ETM_Type *pETM, uint16_t u16CounterValue); +void ETM_SetChannelValue(ETM_Type *pETM, uint8_t u8ETM_Channel, uint16_t u16ChannelValue); +void ETM_SetModValue(ETM_Type *pETM, uint16_t u16ModValue); +void ETM_SetETMBasic(ETM_Type *pETM); +void ETM_SetETMEnhanced(ETM_Type *pETM); +void ETM_ClrChannelFlag(ETM_Type *pETM, uint8_t u8ETM_Channel); +uint8_t ETM_GetChannelFlag(ETM_Type *pETM, uint8_t u8ETM_Channel); +void ETM_ClrOverFlowFlag(ETM_Type *pETM); +uint8_t ETM_GetOverFlowFlag(ETM_Type *pETM); +void ETM_DisableChannelInt(ETM_Type *pETM, uint8_t u8ETM_Channel); +void ETM_EnableChannelInt(ETM_Type *pETM, uint8_t u8ETM_Channel); +void ETM_DisableOverflowInt(ETM_Type *pETM); +void ETM_EnableOverflowInt(ETM_Type *pETM); + +#ifdef __cplusplus +} +#endif +#endif /* ETM_H_ */ diff --git a/bsp/nv32f100x/lib/inc/flash.h b/bsp/nv32f100x/lib/inc/flash.h new file mode 100644 index 0000000000000000000000000000000000000000..9d6c52b79700c32aab7caef725350ab81bb9e2c2 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/flash.h @@ -0,0 +1,118 @@ +/****************************************************************************** +****************************************************************************** +* +* @file flash.h +* +* @brief application entry point which performs application specific tasks. +* +******************************************************************************* +* +* provide a demo for how to initialize the NV32, output messages via SCI, +* flash operations, etc. +* NOTE: +* printf call may occupy a lot of memory (around 1924 bytes), so please +* consider your code size before using printf. +****************************************************************************** +* +* provide FLASH driver +* +******************************************************************************/ + + + +#ifndef FLASH_H_ +#define FLASH_H_ + +/****************************************************************************** +* Includes +******************************************************************************/ +#include "common.h" +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ +/* Uncomment the following line to support programming flash while running code from flash */ +// #define FLASH_ENABLE_STALLING_FLASH_CONTROLLER + +#define ETMRH_FSTAT_MGSTAT0_MASK (1) +#define ETMRH_FSTAT_MGSTAT1_MASK (1<<1) + +#define FLASH_SECTOR_SIZE 512 // in bytes + +/* Flash driver errors */ +#define FLASH_ERR_BASE 0x3000 +#define FLASH_ERR_SUCCESS 0 +#define FLASH_ERR_INVALID_PARAM (FLASH_ERR_BASE+1) // invalid parameter error code +#define EEPROM_ERR_SINGLE_BIT_FAULT (FLASH_ERR_BASE+2) // EEPROM single bit fault error code +#define EEPROM_ERR_DOUBLE_BIT_FAULT (FLASH_ERR_BASE+4) // EEPROM double bits fault error code +#define FLASH_ERR_ACCESS (FLASH_ERR_BASE+8) // flash access error code +#define FLASH_ERR_PROTECTION (FLASH_ERR_BASE+0x10) // flash protection error code +#define FLASH_ERR_MGSTAT0 (FLASH_ERR_BASE+0x11) // flash verification error code +#define FLASH_ERR_MGSTAT1 (FLASH_ERR_BASE+0x12) // flash non-correctable error code +#define FLASH_ERR_INIT_CCIF (FLASH_ERR_BASE+0x14) // flash driver init error with CCIF = 1 +#define FLASH_ERR_INIT_FDIV (FLASH_ERR_BASE+0x18) // flash driver init error with wrong FDIV + +/* Flash and EEPROM commands */ + + +#define FLASH_CMD_PROGRAM 0x20000000 +#define FLASH_CMD_CLEAR 0x00005000 +#define FLASH_CMD_ERASE_ALL 0x41000000 +#define FLASH_CMD_ERASE_SECTOR 0x40000000 +#define FLASH_FACTORY_KEY 0x0065fe9a + +#define EFM_DONE_MASK 0x00006000 +#define EFM_STATUS_DONE 0x00006000 +#define EFM_STATUS_READY 0x00002000 + +#define FLASH_ACCERR_MASK 0x10 + +#define M8(adr) (*((volatile unsigned char *) (adr))) +#define M16(adr) (*((volatile unsigned short *) (adr))) +#define M32(adr) (*((volatile unsigned long *) (adr))) + + + +/****************************************************************************** +* Types +******************************************************************************/ +typedef uint16_t (*TFlash_Fun1)(uint32_t wNVMTargetAddress, uint8_t *pbData, uint8_t bByteCount); +typedef uint16_t (*TFlash_Fun2)(uint32_t wNVMTargetAddress, uint32_t dwData0, uint32_t dwData1); +typedef uint16_t (*TFlash_Fun3)(uint32_t wNVMTargetAddress, uint32_t dwData); + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ +uint16_t Flash_Program(uint32_t wNVMTargetAddress, uint8_t *pData, uint16_t sizeBytes); +uint16_t Flash_Program1LongWord(uint32_t wNVMTargetAddress, uint32_t dwData); +uint16_t Flash_Program2LongWords(uint32_t wNVMTargetAddress, uint32_t dwData0, uint32_t dwData1); + +uint16_t Flash_EraseSector(uint32_t wNVMTargetAddress); + +uint16_t Flash_VerifyBackdoorKey(void); + +uint16_t NVM_EraseAll(void); + +uint16_t NVM_Unsecure(void); + +uint16_t Flash_Init(void); + +#ifdef IAR +void __ramfunc EFM_LaunchCMD(uint32_t EFM_CMD); +#else +void EFM_LaunchCMD(uint32_t EFM_CMD); +#endif + + +void Flash_CopyInRAM(void); +void Flash_CopyRouinte2RAM(char *func, uint16_t sizeFunc); +/********************************************************************/ + +#endif /* FLASH_H_ */ diff --git a/bsp/nv32f100x/lib/inc/gpio.h b/bsp/nv32f100x/lib/inc/gpio.h new file mode 100644 index 0000000000000000000000000000000000000000..2fd7a3c3236ec1d69edf2eaebac0e2c06fd61d52 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/gpio.h @@ -0,0 +1,278 @@ +/****************************************************************************** +* +* @brief provide commond GPIO utilities. +* +*******************************************************************************/ +#ifndef _GPIO_H_ +#define _GPIO_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "common.h" +#include "stdint.h" + +/****************************************************************************** +*define gpio pin name +* +*//*! @addtogroup gpio_pin_name_list +* @{ +*******************************************************************************/ +typedef enum +{ + /* in GPIOA register */ + GPIO_PTA0 = 0, /*!< GPIO Pin PTA0 */ + GPIO_PTA1, /*!< GPIO Pin PTA1 */ + GPIO_PTA2, /*!< GPIO Pin PTA2 */ + GPIO_PTA3, /*!< GPIO Pin PTA3 */ + GPIO_PTA4, /*!< GPIO Pin PTA4 */ + GPIO_PTA5, /*!< GPIO Pin PTA5 */ + GPIO_PTA6, /*!< GPIO Pin PTA6 */ + GPIO_PTA7, /*!< GPIO Pin PTA7 */ + GPIO_PTB0, /*!< GPIO Pin PTB0 */ + GPIO_PTB1, /*!< GPIO Pin PTB1 */ + GPIO_PTB2, /*!< GPIO Pin PTB2 */ + GPIO_PTB3, /*!< GPIO Pin PTB3 */ + GPIO_PTB4, /*!< GPIO Pin PTB4 */ + GPIO_PTB5, /*!< GPIO Pin PTB5 */ + GPIO_PTB6, /*!< GPIO Pin PTB6 */ + GPIO_PTB7, /*!< GPIO Pin PTB7 */ + GPIO_PTC0, /*!< GPIO Pin PTC0 */ + GPIO_PTC1, /*!< GPIO Pin PTC1 */ + GPIO_PTC2, /*!< GPIO Pin PTC2 */ + GPIO_PTC3, /*!< GPIO Pin PTC3 */ + GPIO_PTC4, /*!< GPIO Pin PTC4 */ + GPIO_PTC5, /*!< GPIO Pin PTC5 */ + GPIO_PTC6, /*!< GPIO Pin PTC6 */ + GPIO_PTC7, /*!< GPIO Pin PTC7 */ + GPIO_PTD0, /*!< GPIO Pin PTD0 */ + GPIO_PTD1, /*!< GPIO Pin PTD1 */ + GPIO_PTD2, /*!< GPIO Pin PTD2 */ + GPIO_PTD3, /*!< GPIO Pin PTD3 */ + GPIO_PTD4, /*!< GPIO Pin PTD4 */ + GPIO_PTD5, /*!< GPIO Pin PTD5 */ + GPIO_PTD6, /*!< GPIO Pin PTD6 */ + GPIO_PTD7, /*!< GPIO Pin PTD7 */ + /* in GPIOB register */ + GPIO_PTE0, /*!< GPIO Pin PTE0 */ + GPIO_PTE1, /*!< GPIO Pin PTE1 */ + GPIO_PTE2, /*!< GPIO Pin PTE2 */ + GPIO_PTE3, /*!< GPIO Pin PTE3 */ + GPIO_PTE4, /*!< GPIO Pin PTE4 */ + GPIO_PTE5, /*!< GPIO Pin PTE5 */ + GPIO_PTE6, /*!< GPIO Pin PTE6 */ + GPIO_PTE7, /*!< GPIO Pin PTE7 */ + GPIO_PTF0, /*!< GPIO Pin PTF0 */ + GPIO_PTF1, /*!< GPIO Pin PTF1 */ + GPIO_PTF2, /*!< GPIO Pin PTF2 */ + GPIO_PTF3, /*!< GPIO Pin PTF3 */ + GPIO_PTF4, /*!< GPIO Pin PTF4 */ + GPIO_PTF5, /*!< GPIO Pin PTF5 */ + GPIO_PTF6, /*!< GPIO Pin PTF6 */ + GPIO_PTF7, /*!< GPIO Pin PTF7 */ + GPIO_PTG0, /*!< GPIO Pin PTG0 */ + GPIO_PTG1, /*!< GPIO Pin PTG1 */ + GPIO_PTG2, /*!< GPIO Pin PTG2 */ + GPIO_PTG3, /*!< GPIO Pin PTG3 */ + GPIO_PTG4, /*!< GPIO Pin PTG4 */ + GPIO_PTG5, /*!< GPIO Pin PTG5 */ + GPIO_PTG6, /*!< GPIO Pin PTG6 */ + GPIO_PTG7, /*!< GPIO Pin PTG7 */ + GPIO_PTH0, /*!< GPIO Pin PTH0 */ + GPIO_PTH1, /*!< GPIO Pin PTH1 */ + GPIO_PTH2, /*!< GPIO Pin PTH2 */ + GPIO_PTH3, /*!< GPIO Pin PTH3 */ + GPIO_PTH4, /*!< GPIO Pin PTH4 */ + GPIO_PTH5, /*!< GPIO Pin PTH5 */ + GPIO_PTH6, /*!< GPIO Pin PTH6 */ + GPIO_PTH7, /*!< GPIO Pin PTH7 */ + /* the following pins are not in NV322 */ + GPIO_PTI0, /*!< GPIO Pin PTI0 */ + GPIO_PTI1, /*!< GPIO Pin PTI1 */ + GPIO_PTI2, /*!< GPIO Pin PTI2 */ + GPIO_PTI3, /*!< GPIO Pin PTI3 */ + GPIO_PTI4, /*!< GPIO Pin PTI4 */ + GPIO_PTI5, /*!< GPIO Pin PTI5 */ + GPIO_PTI6, /*!< GPIO Pin PTI6 */ + GPIO_PTI7, /*!< GPIO Pin PTI7 */ + GPIO_PIN_MAX, +} GPIO_PinType; +/*! @} End of gpio_pin_name_list */ + +/****************************************************************************** +*define gpio pin mask +* +*//*! @addtogroup gpio_pin_mask_list +* @{ +*******************************************************************************/ +typedef enum +{ + /* in GPIOA register */ + GPIO_PTA0_MASK = (1<<0), /*!< GPIO Pin PTA0 bit mask */ + GPIO_PTA1_MASK = (1<<1), /*!< GPIO Pin PTA1 bit mask */ + GPIO_PTA2_MASK = (1<<2), /*!< GPIO Pin PTA2 bit mask */ + GPIO_PTA3_MASK = (1<<3), /*!< GPIO Pin PTA3 bit mask */ + GPIO_PTA4_MASK = (1<<4), /*!< GPIO Pin PTA4 bit mask */ + GPIO_PTA5_MASK = (1<<5), /*!< GPIO Pin PTA5 bit mask */ + GPIO_PTA6_MASK = (1<<6), /*!< GPIO Pin PTA6 bit mask */ + GPIO_PTA7_MASK = (1<<7), /*!< GPIO Pin PTA7 bit mask */ + GPIO_PTB0_MASK = (1<<8), /*!< GPIO Pin PTB0 bit mask */ + GPIO_PTB1_MASK = (1<<9), /*!< GPIO Pin PTB1 bit mask */ + GPIO_PTB2_MASK = (1<<10), /*!< GPIO Pin PTB2 bit mask */ + GPIO_PTB3_MASK = (1<<11), /*!< GPIO Pin PTB3 bit mask */ + GPIO_PTB4_MASK = (1<<12), /*!< GPIO Pin PTB4 bit mask */ + GPIO_PTB5_MASK = (1<<13), /*!< GPIO Pin PTB5 bit mask */ + GPIO_PTB6_MASK = (1<<14), /*!< GPIO Pin PTB6 bit mask */ + GPIO_PTB7_MASK = (1<<15), /*!< GPIO Pin PTB7 bit mask */ + GPIO_PTC0_MASK = (1<<16), /*!< GPIO Pin PTC0 bit mask */ + GPIO_PTC1_MASK = (1<<17), /*!< GPIO Pin PTC1 bit mask */ + GPIO_PTC2_MASK = (1<<18), /*!< GPIO Pin PTC2 bit mask */ + GPIO_PTC3_MASK = (1<<19), /*!< GPIO Pin PTC3 bit mask */ + GPIO_PTC4_MASK = (1<<20), /*!< GPIO Pin PTC4 bit mask */ + GPIO_PTC5_MASK = (1<<21), /*!< GPIO Pin PTC5 bit mask */ + GPIO_PTC6_MASK = (1<<22), /*!< GPIO Pin PTC6 bit mask */ + GPIO_PTC7_MASK = (1<<23), /*!< GPIO Pin PTC7 bit mask */ + GPIO_PTD0_MASK = (1<<24), /*!< GPIO Pin PTD0 bit mask */ + GPIO_PTD1_MASK = (1<<25), /*!< GPIO Pin PTD1 bit mask */ + GPIO_PTD2_MASK = (1<<26), /*!< GPIO Pin PTD2 bit mask */ + GPIO_PTD3_MASK = (1<<27), /*!< GPIO Pin PTD3 bit mask */ + GPIO_PTD4_MASK = (1<<28), /*!< GPIO Pin PTD4 bit mask */ + GPIO_PTD5_MASK = (1<<29), /*!< GPIO Pin PTD5 bit mask */ + GPIO_PTD6_MASK = (1<<30), /*!< GPIO Pin PTD6 bit mask */ + GPIO_PTD7_MASK = (1<<31), /*!< GPIO Pin PTD7 bit mask */ + /* in GPIOB register */ + GPIO_PTE0_MASK = (1<<0), /*!< GPIO Pin PTE0 bit mask */ + GPIO_PTE1_MASK = (1<<1), /*!< GPIO Pin PTE1 bit mask */ + GPIO_PTE2_MASK = (1<<2), /*!< GPIO Pin PTE2 bit mask */ + GPIO_PTE3_MASK = (1<<3), /*!< GPIO Pin PTE3 bit mask */ + GPIO_PTE4_MASK = (1<<4), /*!< GPIO Pin PTE4 bit mask */ + GPIO_PTE5_MASK = (1<<5), /*!< GPIO Pin PTE5 bit mask */ + GPIO_PTE6_MASK = (1<<6), /*!< GPIO Pin PTE6 bit mask */ + GPIO_PTE7_MASK = (1<<7), /*!< GPIO Pin PTE7 bit mask */ + GPIO_PTF0_MASK = (1<<8), /*!< GPIO Pin PTF0 bit mask */ + GPIO_PTF1_MASK = (1<<9), /*!< GPIO Pin PTF1 bit mask */ + GPIO_PTF2_MASK = (1<<10), /*!< GPIO Pin PTF2 bit mask */ + GPIO_PTF3_MASK = (1<<11), /*!< GPIO Pin PTF3 bit mask */ + GPIO_PTF4_MASK = (1<<12), /*!< GPIO Pin PTF4 bit mask */ + GPIO_PTF5_MASK = (1<<13), /*!< GPIO Pin PTF5 bit mask */ + GPIO_PTF6_MASK = (1<<14), /*!< GPIO Pin PTF6 bit mask */ + GPIO_PTF7_MASK = (1<<15), /*!< GPIO Pin PTF7 bit mask */ + GPIO_PTG0_MASK = (1<<16), /*!< GPIO Pin PTG0 bit mask */ + GPIO_PTG1_MASK = (1<<17), /*!< GPIO Pin PTG1 bit mask */ + GPIO_PTG2_MASK = (1<<18), /*!< GPIO Pin PTG2 bit mask */ + GPIO_PTG3_MASK = (1<<19), /*!< GPIO Pin PTG3 bit mask */ + GPIO_PTG4_MASK = (1<<20), /*!< GPIO Pin PTG4 bit mask */ + GPIO_PTG5_MASK = (1<<21), /*!< GPIO Pin PTG5 bit mask */ + GPIO_PTG6_MASK = (1<<22), /*!< GPIO Pin PTG6 bit mask */ + GPIO_PTG7_MASK = (1<<23), /*!< GPIO Pin PTG7 bit mask */ + GPIO_PTH0_MASK = (1<<24), /*!< GPIO Pin PTH0 bit mask */ + GPIO_PTH1_MASK = (1<<25), /*!< GPIO Pin PTH1 bit mask */ + GPIO_PTH2_MASK = (1<<26), /*!< GPIO Pin PTH2 bit mask */ + GPIO_PTH3_MASK = (1<<27), /*!< GPIO Pin PTH3 bit mask */ + GPIO_PTH4_MASK = (1<<28), /*!< GPIO Pin PTH4 bit mask */ + GPIO_PTH5_MASK = (1<<29), /*!< GPIO Pin PTH5 bit mask */ + GPIO_PTH6_MASK = (1<<30), /*!< GPIO Pin PTH6 bit mask */ + GPIO_PTH7_MASK = (1<<31), /*!< GPIO Pin PTH7 bit mask */ + /* in GPIOC register */ + GPIO_PTI0_MASK = (1<<0), /*!< GPIO Pin PTI0 bit mask */ + GPIO_PTI1_MASK = (1<<1), /*!< GPIO Pin PTI1 bit mask */ + GPIO_PTI2_MASK = (1<<2), /*!< GPIO Pin PTI2 bit mask */ + GPIO_PTI3_MASK = (1<<3), /*!< GPIO Pin PTI3 bit mask */ + GPIO_PTI4_MASK = (1<<4), /*!< GPIO Pin PTI4 bit mask */ + GPIO_PTI5_MASK = (1<<5), /*!< GPIO Pin PTI5 bit mask */ + GPIO_PTI6_MASK = (1<<6), /*!< GPIO Pin PTI6 bit mask */ + GPIO_PTI7_MASK = (1<<7), /*!< GPIO Pin PTI7 bit mask */ +} GPIO_PinMaskType; +/*! @} End of gpio_pin_mask_list */ + + +/****************************************************************************** +*define gpio pin config type +* +*//*! @addtogroup gpio_pin_config_type_list +* @{ +*******************************************************************************/ +/* +* . Internal pullup is disabled if the pin is configured as an output +* . High-current drive function is disabled, if the pin is configured as an input +* Only PTH1/0, PTE1/0, PTD1/0, PTB5/4 support Hight-current Drive. +*/ +typedef enum +{ + GPIO_PinOutput = 0, /*!< set pin as outout */ + GPIO_PinInput, /*!< set pin as input */ + GPIO_PinInput_InternalPullup, /*!< set internal pullup for input pin */ + GPIO_PinOutput_HighCurrent, /*!< set high drive for output pin */ +} GPIO_PinConfigType; +/*! @} End of gpio_pin_config_type_list */ + +/****************************************************************************** +* define GPIO APIs +* +*//*! @addtogroup gpio_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* @brief Toggle the pins which are specified by u32PinMask in single cycle. +* +* @param[in] pGPIO Pointer to GPIO module, can be FGPIOA/FGPIOB. +* @param[in] u32PinMask Specify GPIO pin need to be toggled +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void FGPIO_Toggle(FGPIO_Type *pFGPIO, uint32_t u32PinMask) +{ + pFGPIO->PTOR = u32PinMask; /* Toggle the pins specified by u32PinMask */ +} + +/*****************************************************************************//*! +* @brief Read input data from GPIO which is specified by pGPIO in single cycle. +* +* @param[in] pGPIO Pointer to GPIO module, can be FGPIOA/FGPIOB. +* +* @return GPIO input value unsigned int 32-bit +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + __STATIC_INLINE uint32_t FGPIO_Read(FGPIO_Type *pFGPIO) +{ + return (pFGPIO->PDIR); /* Read Port Data Input Register */ + +} + +/*****************************************************************************//*! +* @brief Write output data to GPIO which is specified by pGPIO in single cycle. +* +* @param[in] pGPIO Pointer to GPIO module, can be FGPIOA/FGPIOB. +* @param[in] u32Value value to output +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void FGPIO_Write(FGPIO_Type *pFGPIO, uint32_t u32Value) +{ + pFGPIO->PDOR = u32Value; /* Write Port Ouput Data Register */ +} + +void GPIO_DeInit(GPIO_Type *pGPIO); +void GPIO_Init(GPIO_Type *pGPIO, uint32_t u32PinMask, GPIO_PinConfigType sGpioType); +void GPIO_Toggle(GPIO_Type *pGPIO, uint32_t u32PinMask); +uint32_t GPIO_Read(GPIO_Type *pGPIO); +void GPIO_Write(GPIO_Type *pGPIO, uint32_t u32Value); +void GPIO_PinInit(GPIO_PinType GPIO_Pin, GPIO_PinConfigType GPIO_PinConfig); +void GPIO_PinToggle(GPIO_PinType GPIO_Pin); +void GPIO_PinSet(GPIO_PinType GPIO_Pin); +void GPIO_PinClear(GPIO_PinType GPIO_Pin); +uint8_t GPIO_BitRead(GPIO_PinType GPIO_Pin); + +/*! @} End of gpio_api_list */ + +#ifdef __cplusplus +} +#endif +#endif /* #ifndef _GPIO_H_ */ diff --git a/bsp/nv32f100x/lib/inc/i2c.h b/bsp/nv32f100x/lib/inc/i2c.h new file mode 100644 index 0000000000000000000000000000000000000000..2e4eced54338567ba65bb887b22f795c5e99c06f --- /dev/null +++ b/bsp/nv32f100x/lib/inc/i2c.h @@ -0,0 +1,524 @@ +/****************************************************************************** +* @brief header file for I2C module utilities (I2C). +* +******************************************************************************* +* +* provide APIs for accessing I2C module (I2C) +******************************************************************************/ +#ifndef _I2C_H__ +#define _I2C_H__ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ +/****************************************************************************** +* define I2C work read or write +* +*//*! @addtogroup i2c_read_write_list +* @{ +*******************************************************************************/ +#define I2C_READ 0x01 /*!< I2C read */ +#define I2C_WRITE 0x0 /*!< I2C write */ +/*! @} End of i2c_read_write_list */ + +#define I2C_SEND_ACK 0 /*!< I2C send ACK */ +#define I2C_SEND_NACK 1 /*!< I2C send NACK */ + +#define I2C_WAIT_STATUS_ETMEOUT 200000 + +/****************************************************************************** +* define I2C error state +* +*//*! @addtogroup i2c_error_state_list +* @{ +*******************************************************************************/ +#define I2C_ERROR_NULL 0x00 /*!< I2C sucess*/ +#define I2C_ERROR_NO_WAIT_TCF_FLAG 0x01 /*!< I2C wait TCF overETMe*/ +#define I2C_ERROR_NO_WAIT_IICIF_FLAG 0x02 /*!< I2C wait IICIF overETMe */ +#define I2C_ERROR_NO_GET_ACK 0x04 /*!< I2C no get ACK */ +#define I2C_ERROR_START_NO_BUSY_FLAG 0x10 /*!< I2C fail to send start signals */ +#define I2C_ERROR_STOP_BUSY_FLAG 0x20 /*!< I2C fail to send stop signal */ +#define I2C_ERROR_BUS_BUSY 0x80 /*!< I2C bus busy error */ +/*! @} End of i2c_error_state_list */ + +/****************************************************************************** +* define I2C bus state +* +*//*! @addtogroup i2c_bus_state_list +* @{ +*******************************************************************************/ +#define I2C_BUS_NORMAL 0x00 /*!< I2C bus normal */ +#define I2C_BUS_SLTF 0x01 /*!< I2C bus SLTF flag */ +#define I2C_BUS_SHTF2 0x02 /*!< I2C bus SHTF2 flag */ +/*! @} End of i2c_bus_state_list */ + + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ +#define I2C_MODE_MASTER 1 +#define I2C_MODE_SLAVE 0 +#define I2C_ADDRESS_7BIT 0 +#define I2C_ADDRESS_10BIT 1 +#define I2C_ETMEOUT_BUS_CLOCK_DIV64 0 +#define I2C_ETMEOUT_BUS_CLOCK 1 + +/****************************************************************************** +* +*//*! @addtogroup i2c_setting_type +* @{ +*******************************************************************************/ +/*! + * @brief I2C setting type. + * + */ +typedef struct +{ + uint16_t bI2CEn :1; /*!< enable I2C module */ + uint16_t bIntEn :1; /*!< enable I2C enable */ + uint16_t bWakeUpEn :1; /*!< I2C wake up enable */ + uint16_t bGCAEn :1; /*!< I2C General call address enable */ + uint16_t bAddressExt :1; /*!< I2C extertion address selection */ + uint16_t bRangeAddEn :1; /*!< enable range address */ + uint16_t bFackEn :1; /*!< enable fast ack */ + uint16_t bSMB_AlertEn :1; /*!< SMB Alert enable */ + uint16_t bSecondAddressEn:1; /*!< enable the second address */ + uint16_t bETMeoutCountClockSelect:1; /*!< ETMeoutCountClockSelect */ + uint16_t bSHTF2IntEn :1; /*!< SHTF2 interrupt enable */ + uint16_t Reserve :5; +}I2C_SettingType; +/*! @} End of i2c_setting_type */ + +/****************************************************************************** +* +*//*! @addtogroup i2c_config_type +* @{ +*******************************************************************************/ +/*! + * @brief I2C configure type. + * + */ +typedef struct +{ + I2C_SettingType sSetting; + uint16_t u16F; /*!< setting the band rate for I2C */ + uint16_t u16OwnA1; /*!< slave address */ + uint16_t u16OwnA2; /*!< the second slave address */ + uint16_t u16RangeA; /*!< range address */ + uint16_t u16Filt; /*!< Filter for I2C */ + uint16_t u16Slt; /*!< SCL Low ETMeout register low */ + +}I2C_ConfigType, *I2C_ConfigPtr; +/*! @} End of i2c_config_type */ + +/****************************************************************************** +* +*//*! @addtogroup i2c_callback +* @{ +*******************************************************************************/ +typedef void (*I2C_CallbackType)(void); /*!< I2C call back function */ +/*! @} End of i2c_callback */ + +/****************************************************************************** +* inline functions +******************************************************************************/ +/****************************************************************************** +* +*//*! @addtogroup i2c_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief enable I2C to transmit data. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_TxEnable(I2C_Type *pI2Cx) +{ + pI2Cx->C1 |= I2C_C1_TX_MASK; +} +/*****************************************************************************//*! + * + * @brief enable I2C to receive data. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE void I2C_RxEnable(I2C_Type *pI2Cx) +{ + pI2Cx->C1 &= ~I2C_C1_TX_MASK; +} + +/*****************************************************************************//*! + * + * @brief set IIC band rate. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_SetBaudRate(I2C_Type *pI2Cx,uint32_t u32Bps) +{ + pI2Cx->F = (uint8_t)u32Bps; +} +/*****************************************************************************//*! + * + * @brief enable general call. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE void I2C_GeneralCallEnable(I2C_Type *pI2Cx) +{ + pI2Cx->C2 |= I2C_C2_GCAEN_MASK; +} +/*****************************************************************************//*! + * + * @brief SMBus Alert Response Address Enable. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_SMBusAlertEnable(I2C_Type *pI2Cx) +{ + pI2Cx->SMB|= I2C_SMB_ALERTEN_MASK; +} +/*****************************************************************************//*! + * + * @brief Range Address Matching Enable. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_RangeAddressEnable(I2C_Type *pI2Cx) +{ + pI2Cx->C2 |= I2C_C2_RMEN_MASK; +} +/*****************************************************************************//*! + * + * @brief SHTF2 Interrupt Enable. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_SHTF2IntEnable(I2C_Type *pI2Cx) +{ + pI2Cx->SMB |= I2C_SMB_SHTF2IE_MASK; +} +/*****************************************************************************//*! + * + * @brief ETMeout Counter Clock Select. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_ETMeoutCounterClockSelect(I2C_Type *pI2Cx, uint8_t u8Clock) +{ + if( u8Clock ) + { + pI2Cx->SMB |= I2C_SMB_TCKSEL_MASK; + } + else + { + pI2Cx->SMB &= ~I2C_SMB_TCKSEL_MASK; + } +} +/*****************************************************************************//*! + * + * @brief get I2C status. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return I2C status + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_GetStatus(I2C_Type *pI2Cx) +{ + return pI2Cx->S; +} +/*****************************************************************************//*! + * + * @brief clear specified status. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_ClearStatus(I2C_Type *pI2Cx, uint8_t u8ClearFlag) +{ + pI2Cx->S |= u8ClearFlag; +} +/*****************************************************************************//*! + * + * @brief write data to data register. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_WriteDataReg(I2C_Type *pI2Cx, uint8_t u8DataBuff) +{ + pI2Cx->D = u8DataBuff; +} +/*****************************************************************************//*! + * + * @brief read data from data register. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return I2C data register value + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_ReadDataReg(I2C_Type *pI2Cx ) +{ + return pI2Cx->D; +} +/*****************************************************************************//*! + * + * @brief check if is Tx mode. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return result TRUE or FALSE + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_IsTxMode(I2C_Type *pI2Cx ) +{ + return(pI2Cx->C1 & I2C_C1_TX_MASK); +} +/*****************************************************************************//*! + * + * @brief check I2C if busy. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return result TRUE or FALSE + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_IsBusy(I2C_Type *pI2Cx ) +{ + return (pI2Cx->S & I2C_S_BUSY_MASK); +} +/*****************************************************************************//*! + * + * @brief check I2C receive ack or nack. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return result TRUE or FALSE + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_IsReceivedAck(I2C_Type *pI2Cx ) +{ + return (pI2Cx->S & I2C_S_RXAK_MASK); +} +/*****************************************************************************//*! + * + * @brief check I2C if is master mode. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return result TRUE or FALSE. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_IsMasterMode(I2C_Type *pI2Cx ) +{ + return(pI2Cx->C1 & I2C_C1_MST_MASK); +} +/*****************************************************************************//*! + * + * @brief check SCL Low ETMeout Flag. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return result TRUE or FALSE. + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_IsSMB_SLTF(I2C_Type *pI2Cx ) +{ + return (pI2Cx->SMB & I2C_SMB_SLTF_MASK); +} +/*****************************************************************************//*! + * + * @brief check SCL High ETMeout Flag is set or clear. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return result TRUE or FALSE. + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t I2C_IsSMB_SHTF2(I2C_Type *pI2Cx ) +{ + return(pI2Cx->SMB & I2C_SMB_SHTF2_MASK); +} +/*****************************************************************************//*! + * + * @brief clear SLTF flag. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE void I2C_ClearSLTF(I2C_Type *pI2Cx ) +{ + pI2Cx->SMB |= I2C_SMB_SLTF_MASK; +} +/*****************************************************************************//*! + * + * @brief clear SHTF2 flag. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void I2C_ClearSHTF2(I2C_Type *pI2Cx ) +{ + pI2Cx->SMB |= I2C_SMB_SHTF2_MASK; +} +/*****************************************************************************//*! + * + * @brief send out ACK. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE void I2C_SendAck(I2C_Type *pI2Cx ) +{ + pI2Cx->C1 &= ~I2C_C1_TXAK_MASK; +} +/*****************************************************************************//*! + * + * @brief send out NACK. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE void I2C_SendNack(I2C_Type *pI2Cx ) +{ + pI2Cx->C1 |= I2C_C1_TXAK_MASK; +} +/*****************************************************************************//*! + * + * @brief Second I2C Address Enable. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +__STATIC_INLINE void I2C_SecondAddressEnable(I2C_Type *pI2Cx) +{ + pI2Cx->SMB |= I2C_SMB_SIICAEN_MASK; +} +/****************************************************************************** +* Global functions +******************************************************************************/ +void I2C_Init(I2C_Type *pI2Cx,I2C_ConfigPtr pI2CConfig); +uint8_t I2C_Start(I2C_Type *pI2Cx); +uint8_t I2C_Stop(I2C_Type *pI2Cx); +uint8_t I2C_RepeatStart(I2C_Type *pI2Cx); +uint8_t I2C_IsTxMode(I2C_Type *pI2Cx ); +uint8_t I2C_IsBusy(I2C_Type *pI2Cx ); +uint8_t I2C_IsReceivedAck(I2C_Type *pI2Cx ); +uint8_t I2C_IsMasterMode(I2C_Type *pI2Cx ); +void I2C_ClearSHTF2(I2C_Type *pI2Cx ); +void I2C_ClearSLTF(I2C_Type *pI2Cx ); +uint8_t I2C_IsSMB_SHTF2(I2C_Type *pI2Cx ); +uint8_t I2C_IsSMB_SLTF(I2C_Type *pI2Cx ); +void I2C_TxEnable(I2C_Type *pI2Cx); +void I2C_RxEnable(I2C_Type *pI2Cx); +void I2C_IntEnable(I2C_Type *pI2Cx); +void I2C_IntDisable(I2C_Type *pI2Cx); +void I2C_SetBaudRate(I2C_Type *pI2Cx,uint32_t u32Bps); +void I2C_SetSlaveAddress(I2C_Type *pI2Cx,uint16_t u16SlaveAddress); +void I2C_GeneralCallEnable(I2C_Type *pI2Cx); +void I2C_SMBusAlertEnable(I2C_Type *pI2Cx); +void I2C_RangeAddressEnable(I2C_Type *pI2Cx); +void I2C_SHTF2IntEnable(I2C_Type *pI2Cx); +void I2C_ETMeoutCounterClockSelect(I2C_Type *pI2Cx, uint8_t u8Clock); +void I2C_SetSCLLowETMeout(I2C_Type *pI2Cx, uint16_t u16ETMeout); +uint8_t I2C_GetStatus(I2C_Type *pI2Cx); +void I2C_ClearStatus(I2C_Type *pI2Cx, uint8_t u8ClearFlag); +void I2C_SendAck(I2C_Type *pI2Cx ); +void I2C_SendNack(I2C_Type *pI2Cx ); +void I2C_SecondAddressEnable(I2C_Type *pI2Cx); +void I2C_ClearStatus(I2C_Type *pI2Cx, uint8_t u8ClearFlag); +void I2C_WriteDataReg(I2C_Type *pI2Cx, uint8_t u8DataBuff); +uint8_t I2C_ReadDataReg(I2C_Type *pI2Cx ); +void I2C_Deinit(I2C_Type *pI2Cx); +uint8_t I2C_WriteOneByte(I2C_Type *pI2Cx, uint8_t u8WrBuff); +uint8_t I2C_ReadOneByte(I2C_Type *pI2Cx, uint8_t *pRdBuff, uint8_t u8Ack); +uint8_t I2C_MasterSendWait(I2C_Type *pI2Cx,uint16_t u16SlaveAddress,uint8_t *pWrBuff,uint32_t u32Length); +uint8_t I2C_MasterReadWait(I2C_Type *pI2Cx,uint16_t u16SlaveAddress,uint8_t *pRdBuff,uint32_t u32Length); +void I2C0_SetCallBack( I2C_CallbackType pCallBack ); +void I2C1_SetCallBack( I2C_CallbackType pCallBack ); + +/*! @} End of i2c_bus_state_list */ + +#ifdef __cplusplus +} +#endif +#endif // + + diff --git a/bsp/nv32f100x/lib/inc/ics.h b/bsp/nv32f100x/lib/inc/ics.h new file mode 100644 index 0000000000000000000000000000000000000000..899775dcd8d7524ef4eb2fed78e391bc80eeaf86 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/ics.h @@ -0,0 +1,347 @@ +/****************************************************************************** +* +* @brief ICS Çý¶¯Í·Îļþ. +* +******************************************************************************/ +#ifndef ICS_H_ +#define ICS_H_ +#ifdef __cplusplus +extern "C" { +#endif + +#include "common.h" +/****************************************************************************! + * @brief ʱÖÓģʽ³£Á¿¶¨Òå + * + ***************************************************************************/ +enum +{ + ICS_CLK_MODE_FEI = 1, /*!< FEI ģʽ */ + ICS_CLK_MODE_FEE, /*!< FEE ģʽ */ + ICS_CLK_MODE_FEE_OSC, /*!< FEE ģʽ OSCÊä³öʱÖÓÔ´Ñ¡ÔñÀ´×ÔEXTALÒý½ÅµÄÍⲿʱÖÓÔ´ */ + ICS_CLK_MODE_FBE, /*!< FBE ģʽ */ + ICS_CLK_MODE_FBE_OSC, /*!< FBE ģʽ OSCÊä³öʱÖÓÔ´Ñ¡ÔñÀ´×ÔEXTALÒý½ÅµÄÍⲿʱÖÓÔ´ */ + ICS_CLK_MODE_FBI, /*!< FBI ģʽ */ + ICS_CLK_MODE_FBILP, /*!< FBILP ģʽ */ + ICS_CLK_MODE_FBELP, /*!< FBELP ģʽ */ +}; + +/*****************************************************************************//*! + * + * @brief ½«Ê±ÖÓģʽ´Óµ±Ç°Ä£Ê½Çл»µ½ÁíÒ»¸öʱÖÓģʽ. + * + * ʱÖÓģʽºê¹Û¶¨ÒåÈçÏÂ: + * FEI, FBI, FEE, FBE, FBILP, FBELP, FEE_OSC, FBE_OSC + * ×¢£ºFEE_OSC, FBE_OSC ²»ÄÜÓÃ×÷µ±Ç°Ê±ÖÓģʽ. µ±Ç°Ê±ÖÓģʽºÍÒªÇл»µ½µÄʱÖÓģʽ×éºÏÈçÏ£º + * < µ±Ç°Ê±ÖÓģʽ£¬ÒªÇл»µ½µÄʱÖÓģʽ> + * , , , , , , + * , , , , , , + * , , , , , . + * + * @param[in] CurMode µ±Ç°Ê±ÖÓģʽ + * @param[in] NewMode ÒªÇл»µ½µÄʱÖÓģʽ + * @param[in] clkFreq ²Î¿¼Ê±ÖÓƵÂÊ + * + * @return none + * @warning FEE_OSC, FBE_OSC ²»ÄÜÓÃ×÷µ±Ç°Ê±ÖÓģʽ. + * + *****************************************************************************/ + +#define ICS_SwitchMode(CurMode, NewMode, clkFreq) CurMode##_to_##NewMode(clkFreq) + + +/****************************************************************************** +* ¶¨Òå OSC ÅäÖýṹÌå +* +*******************************************************************************/ +typedef struct +{ + uint8_t bRange : 1; /*!< 1: ¸ßƵ·¶Î§, 0: µÍƵ·¶Î§ */ + uint8_t bGain : 1; /*!< 1: ¸ßÔöÒæ, 0:µÍÔöÒæ */ + uint8_t bEnable : 1; /*!< 1: ʹÄÜOSC, 0: ½ûÓÃOSC */ + uint8_t bStopEnable : 1; /*!< 1: ֹͣģʽÏÂOSCʹÄÜ, 0: ֹͣģʽÏÂOSC½ûÓà */ + uint8_t bIsCryst : 1; /*!< 1: OSCÊä³öÑ¡ÔñÕñµ´Æ÷ʱÖÓ, 0: OSCÊä³öÑ¡ÔñÀ´×ÔextalÒý½ÅµÄÍⲿʱÖÓ */ + uint8_t bWaitInit : 1; /*!< 1: µÈ´ýÕñµ´Æ÷³õʼ»¯Íê³É, 0: ²»µÈ´ý */ +} OSC_ConfigType, *OSC_ConfigPtr; + + + +/****************************************************************************** +* +* ICSÅäÖýṹÌå +* +*******************************************************************************/ +typedef struct +{ + uint8_t u8ClkMode; /*!< Ñ¡ÔñʱÖÓģʽ*/ + uint8_t bLPEnable; /*!< µÍ¹¦ºÄģʽÏÂʹÄÜ */ + uint32_t u32ClkFreq; /*!< ²Î¿¼Ê±ÖÓƵÂÊ */ + OSC_ConfigType oscConfig; /*!< OSC ÅäÖà */ +} ICS_ConfigType ; + +/*****************************************************************************//*! +* +* @brief ʹÄÜÖжÏ. +* +* @param none +* +* @return none +* +* @see ICS_DisableInt +*****************************************************************************/ +__STATIC_INLINE void ICS_EnableInt(void) +{ + ICS->C4 |= (ICS_C4_LOLIE_MASK); +} + +/*****************************************************************************//*! +* +* @brief ½ûÓÃÖÐ¶Ï +* +* @param none +* +* @return none +* +* @see ICS_EnableInt +*****************************************************************************/ +__STATIC_INLINE void ICS_DisableInt(void) +{ + ICS->C4 &= ~(ICS_C4_LOLIE_MASK); +} + +/*****************************************************************************//*! +* +* @brief ʹÄÜʱÖÓ¼à¿Ø +* +* @param none +* +* @return none +* +* @see ICS_DisableClockMonitor +*****************************************************************************/ +__STATIC_INLINE void ICS_EnableClockMonitor(void) +{ + ICS->C4 |= (ICS_C4_CME_MASK); +} + +/*****************************************************************************//*! +* +* @brief ½ûÓÃʱÖÓ¼à¿Ø +* +* @param none +* +* @return none +* +* @see ICS_EnableClockMonitor +*****************************************************************************/ +__STATIC_INLINE void ICS_DisableClockMonitor(void) +{ + ICS->C4 &= ~(ICS_C4_CME_MASK); +} + +/*****************************************************************************//*! + * + * @brief ÉèÖÃICSÊä³öʱÖÓÔ´·ÖƵ + * + * @param[in] busDivide -- ·ÖƵֵ + * + * @return depends on commands + *****************************************************************************/ +__STATIC_INLINE void ICS_SetBusDivider(uint8_t u8BusDivide) +{ + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(u8BusDivide); +} + + +/*****************************************************************************//*! +* +* @brief ʹÄÜOSC +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_Enable(void) +{ + OSC->CR |= (OSC_CR_OSCEN_MASK); +} + +/*****************************************************************************//*! +* +* @brief ½ûÓÃOSC +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_Disable(void) +{ + OSC->CR &= ~(OSC_CR_OSCEN_MASK); +} + +/*****************************************************************************//*! +* +* @brief ÉèÖÃOSCÄ£¿éµÄƵÂÊ·¶Î§ÎªµÍƵ·¶Î§ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_SetLowRange(void) +{ + OSC->CR &= ~(OSC_CR_RANGE_MASK); +} + +/*!***************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* +* @brief ÉèÖÃOSCÄ£¿éµÄƵÂÊ·¶Î§Îª¸ßƵ·¶Î§ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_SetHighRange(void) +{ + OSC->CR |= (OSC_CR_RANGE_MASK); +} + + +/*****************************************************************************//*! +* +* @brief ÉèÖÃOSCµÄ¹¤×÷ģʽΪ¸ßÔöÒæģʽ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_SetHighGain(void) +{ + OSC->CR |= (OSC_CR_HGO_MASK); +} + +/*****************************************************************************//*! +* +* @brief ÉèÖÃOSCµÄ¹¤×÷ģʽΪµÍ¹¦ºÄģʽ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_SetLowGain(void) +{ + OSC->CR &= ~(OSC_CR_HGO_MASK); +} + +/*****************************************************************************//*! +* +* @brief Ñ¡ÔñOSCÄ£¿éµÄÊä³öʱÖÓԴΪÕñµ´Æ÷ʱÖÓÔ´ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_SelectCrystal(void) +{ + OSC->CR |= (OSC_CR_OSCOS_MASK); +} + + +/*****************************************************************************//*! +* +* @brief OSCÊä³öÑ¡ÔñÀ´×ÔextalÒý½ÅµÄÍⲿʱÖÓ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_SelectClock(void) +{ + OSC->CR &= ~(OSC_CR_OSCOS_MASK); +} + +/*****************************************************************************//*! +* +* @brief ÔÚֹͣģʽÏÂOSCÄ£¿éʹÄÜ +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_ActiveInStop(void) +{ + OSC->CR |= (OSC_CR_OSCSTEN_MASK); +} + +/*****************************************************************************//*! +* +* @brief ÔÚֹͣģʽÏÂOSCÄ£¿é½ûÓà +* +* @param none +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void OSC_InactiveInStop(void) +{ + OSC->CR &= ~(OSC_CR_OSCSTEN_MASK); +} + +/******************************************************************************/ + +void ICS_Init(ICS_ConfigType *pConfig); +void ICS_DeInit(void); +void ICS_SetClkDivider(uint32_t u32ClkFreqKHz); +void ICS_Trim(uint16 u16TrimValue); +void OSC_Init(OSC_ConfigType *pConfig); +void OSC_DeInit(void); + +/************** ÄÚÁªº¯Êý ******************/ +void ICS_DisableClockMonitor(void); +void ICS_DisableInt(void); +void ICS_EnableClockMonitor(void); +void ICS_EnableInt(void); +void ICS_SetBusDivider(uint8_t u8BusDivide); +void OSC_ActiveInStop(void); +void OSC_Enable(void); +void OSC_Disable(void); +void OSC_InactiveInStop(void); +void OSC_SelectClock(void); +void OSC_SelectCrystal(void); +void OSC_SetHighGain(void); +void OSC_SetHighRange(void); +void OSC_SetLowGain(void); +void OSC_SetLowRange(void); + +/* do not touch the following functions */ +void FEI_to_FEE(ICS_ConfigType *pConfig); +void FEI_to_FBI(ICS_ConfigType *pConfig); +void FEI_to_FBE(ICS_ConfigType *pConfig); +void FEE_to_FBI(ICS_ConfigType *pConfig); +void FEE_to_FEI(ICS_ConfigType *pConfig); +void FEE_to_FBE(ICS_ConfigType *pConfig); +void FBE_to_FEE(ICS_ConfigType *pConfig); +void FBE_to_FEI(ICS_ConfigType *pConfig); +void FBE_to_FBI(ICS_ConfigType *pConfig); +void FBE_to_FBELP(ICS_ConfigType *pConfig); +void FBI_to_FEI(ICS_ConfigType *pConfig); +void FBI_to_FBE(ICS_ConfigType *pConfig); +void FBI_to_FEE(ICS_ConfigType *pConfig); +void FBI_to_FBILP(ICS_ConfigType *pConfig); +void FBILP_to_FBI(ICS_ConfigType *pConfig); +void FBELP_to_FBE(ICS_ConfigType *pConfig); +void FEI_to_FBE_OSC(ICS_ConfigType *pConfig); +void FEI_to_FEE_OSC(ICS_ConfigType *pConfig); +#ifdef __cplusplus +} +#endif +#endif diff --git a/bsp/nv32f100x/lib/inc/kbi.h b/bsp/nv32f100x/lib/inc/kbi.h new file mode 100644 index 0000000000000000000000000000000000000000..5a91d8a13f311d4c7f335856122780dc6fbf57da --- /dev/null +++ b/bsp/nv32f100x/lib/inc/kbi.h @@ -0,0 +1,428 @@ +/****************************************************************************** +** +* @brief header file for KBI. +* +******************************************************************************* +* +* provide APIs for accessing KBI +******************************************************************************/ +#ifndef _KBI_H_ +#define _KBI_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/*! +* @brief KBI MODE select enum. +* +*/ +typedef enum +{ + KBI_MODE_EDGE_ONLY = 0, /*!< select edge only mode */ + KBI_MODE_EDGE_LEVEL /*!< select both edge and level mode */ +}KBI_ModeType; + + + /*! + * @brief KBI Edge select enum. + * + */ +typedef enum +{ + KBI_FALLING_EDGE_LOW_LEVEL = 0, /*!< select falling edge and/or low level */ + KBI_RISING_EDGE_HIGH_LEVEL /*!< select rising edge and/or high level */ +}KBI_EdgeType; + + +/****************************************************************************** +* Macros +******************************************************************************/ + +/****************************************************************************** +* KBI module max number and port pins definition +* +*//*! @addtogroup kbi_macro +* @{ +*******************************************************************************/ +#define KBI_MAX_NO 2 /*!< max number of modules */ + +#if defined(CPU_NV32)|| defined(CPU_NV32M3) + #define KBI_MAX_PINS_PER_PORT 8 /*!< max number of pins */ +#elif defined(CPU_NV32M4) + #define KBI_MAX_PINS_PER_PORT 32 /*!< max number of pins */ +#endif +/*! @} End of kbi_macro */ + + +/****************************************************************************** +* Types +******************************************************************************/ + +/*! @brief KBI_CALLBACK function declaration */ +typedef void (*KBI_CallbackType)(void); +/*! @} End of kbi_callback */ + + + +/****************************************************************************** +* KBI pin config struct +* +*//*! @addtogroup kbi_pinconfigstruct +* @{ +*******************************************************************************/ +/*! +* @brief KBI pin enable and edge select struct. +* +*/ + +typedef struct +{ + uint8_t bEdge : 1; /*!< edge/level select bit */ + uint8_t bEn : 1; /*!< pin enable bit */ + uint8_t bRsvd : 6; /*!< reserved */ +} KBI_PinConfigType; +/*! @} End of kbi_pinconfigstruct */ + + +/****************************************************************************** +* KBI config struct +* +*//*! @addtogroup kbi_configstruct +* @{ +*******************************************************************************/ +/*! + * @brief KBI status and control struct. + * + */ + +typedef struct +{ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) + struct + { + uint8_t bMode : 1; /*!< KBI detection mode select */ + uint8_t bIntEn : 1; /*!< KBI interrupt enable bit */ + uint8_t bRsvd : 6; /*!< reserved */ + } sBits; +#elif defined(CPU_NV32M4) + struct + { + uint32_t bMode : 1; /*!< KBI detection mode select */ + uint32_t bIntEn : 1; /*!< KBI interrupt enable bit */ + uint32_t bRsvd2 : 2; /*!< reserved */ + uint32_t bKbspEn : 1; /*!SC &= ~KBI_SC_KBMOD_MASK; + pKBI->ES &= ~(PinMasks); +} + +/*****************************************************************************//*! +* +* @brief set detect falling edge only. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] PinMasks indicate pin numbers. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_DetectFallingEdge. +* +*****************************************************************************/ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) +__STATIC_INLINE void KBI_DetectRisingEdge(KBI_Type *pKBI, uint8_t PinMasks) +#elif defined(CPU_NV32M4) +__STATIC_INLINE void KBI_DetectRisingEdge(KBI_Type *pKBI, uint32_t PinMasks) +#endif +{ + pKBI->SC &= ~KBI_SC_KBMOD_MASK; + pKBI->ES |= (PinMasks); +} + +/*****************************************************************************//*! +* +* @brief set detect falling edge only. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] PinMasks indicate pin number/mask. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_DetectFallingEdgeLowLevel. +* +*****************************************************************************/ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) +__STATIC_INLINE void KBI_DetectRisingEdgeHighLevel(KBI_Type *pKBI, uint8_t PinMasks) +#elif defined(CPU_NV32M4) +__STATIC_INLINE void KBI_DetectRisingEdgeHighLevel(KBI_Type *pKBI, uint32_t PinMasks) +#endif +{ + pKBI->SC |= KBI_SC_KBMOD_MASK; + pKBI->ES |= (PinMasks); +} + +/*****************************************************************************//*! +* +* @brief set detect falling edge only. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] PinMasks indicate pin number/mask. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_DetectRisingEdgeHighLevel. +* +*****************************************************************************/ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) +__STATIC_INLINE void KBI_DetectFallingEdgeLowLevel(KBI_Type *pKBI, uint8_t PinMasks) +#elif defined(CPU_NV32M4) +__STATIC_INLINE void KBI_DetectFallingEdgeLowLevel(KBI_Type *pKBI, uint32_t PinMasks) +#endif +{ + pKBI->SC |= KBI_SC_KBMOD_MASK; + pKBI->ES &= ~(PinMasks); +} + +/*****************************************************************************//*! +* +* @brief enable the pin specified. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] PinMasks indicate pin number/mask. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_Disable. +* +*****************************************************************************/ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) +__STATIC_INLINE void KBI_Enable(KBI_Type *pKBI, uint8_t PinMasks) +#elif defined(CPU_NV32M4) +__STATIC_INLINE void KBI_Enable(KBI_Type *pKBI, uint32_t PinMasks) +#endif +{ + pKBI->PE |= (PinMasks); +} + +/*****************************************************************************//*! +* +* @brief disable the pin specified. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] PinMasks indicate pin number/mask. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_Enable. +* +*****************************************************************************/ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) +__STATIC_INLINE void KBI_Disable(KBI_Type *pKBI, uint8_t PinMasks) +#elif defined(CPU_NV32M4) +__STATIC_INLINE void KBI_Disable(KBI_Type *pKBI, uint32_t PinMasks) +#endif +{ + pKBI->PE &= ~(PinMasks); +} + +/*****************************************************************************//*! +* +* @brief enable the corresponding interrupt. +* +* @param[in] pKBI pointer to KBI module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_DisableInt. +* +*****************************************************************************/ +__STATIC_INLINE void KBI_EnableInt(KBI_Type *pKBI) +{ + pKBI->SC |= KBI_SC_KBIE_MASK; +} + + +/*****************************************************************************//*! +* +* @brief disable the corresponding interrupt. +* +* @param[in] pKBI pointer to KBI module. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see KBI_EnableInt. +* +*****************************************************************************/ +__STATIC_INLINE void KBI_DisableInt(KBI_Type *pKBI) +{ + pKBI->SC &= ~KBI_SC_KBIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief Get the corresponding status flag bits. +* +* @param[in] pKBI pointer to KBI module. +* +* @return uint8_t. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_ClrFlags. +* +*****************************************************************************/ +#if defined(CPU_NV32)|| defined(CPU_NV32M3) +__STATIC_INLINE uint8_t KBI_GetFlags(KBI_Type *pKBI) +#elif defined(CPU_NV32M4) +__STATIC_INLINE uint32_t KBI_GetFlags(KBI_Type *pKBI) +#endif +{ + return (pKBI->SC & KBI_SC_KBF_MASK); +} + +/*****************************************************************************//*! +* +* @brief clear the corresponding status flag bits. +* +* @param[in] pKBI pointer to KBI module +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see KBI_GetFlags. +* +*****************************************************************************/ +__STATIC_INLINE void KBI_ClrFlags(KBI_Type *pKBI) +{ + pKBI->SC |= KBI_SC_KBACK_MASK; +} + +#if defined(CPU_NV32M4) +/*****************************************************************************//*! +* +* @brief Real KBI_SP register enable. +* +* @param[in] pKBI pointer to KBI module +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see The real ETMe value of Keyboard source pin to be read. +* +*****************************************************************************/ +__STATIC_INLINE void KBI_SPEnable(KBI_Type *pKBI) +{ + pKBI->SC |= KBI_SC_KBSPEN_MASK; +} + +/*****************************************************************************//*! +* +* @brief Get KBI source pin register fields. +* +* @param[in] pKBI pointer to KBI module. +* +* @return uint32_t. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_GetSP. +* +*****************************************************************************/ +__STATIC_INLINE uint32_t KBI_GetSP(KBI_Type *pKBI) +{ + return (pKBI->SP & KBI_SP_SP_MASK); +} + +/*****************************************************************************//*! +* +* @brief Reset KBI_SP register. +* +* @param[in] pKBI pointer to KBI module +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see KBI_RstSP. +* +*****************************************************************************/ +__STATIC_INLINE void KBI_RstSP(KBI_Type *pKBI) +{ + pKBI->SC |= KBI_SC_RSTKBSP_MASK; +} +#endif + +/*! @} End of kbi_api_list */ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +void KBI_Init(KBI_Type *pKBI, KBI_ConfigType *pConfig); +void KBI_SetCallback(KBI_Type *pKBI, KBI_CallbackType pfnCallback); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/bsp/nv32f100x/lib/inc/pit.h b/bsp/nv32f100x/lib/inc/pit.h new file mode 100644 index 0000000000000000000000000000000000000000..99cbdeb7b3194318ecd50b53bca793475c6bea98 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/pit.h @@ -0,0 +1,317 @@ +/****************************************************************************** +* @brief Periodic Interrupt ETMer (PIT) driver head file. +* +******************************************************************************/ +#ifndef PIT_H_ +#define PIT_H_ +#include"common.h" +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* PIT channel number list +* +*//*! @addtogroup pit_channelnumber +* @{ +*******************************************************************************/ +enum +{ + PIT_CHANNEL0 = 0, /*!< PIT channel 0 */ + PIT_CHANNEL1 /*!< PIT channel 1 */ +}; + +/*! @} End of pit_channelnumber */ + +/****************************************************************************** +* Macros +******************************************************************************/ + +/****************************************************************************** +* Types +******************************************************************************/ + +/* + * Callback type + */ + +/****************************************************************************** +* PIT callback function declaration +* +*//*! @addtogroup pit_callback +* @{ +*******************************************************************************/ +typedef void (*PIT_CallbackType)(void); /*!< PIT callback type */ + +/*! @} End of pit_callback */ + +/* PIT configuration structure + */ +/*! + * @brief PIT configuration type. + * + */ +typedef struct +{ + uint8_t bFreeze : 1; /*!< 1: stop in debug mode, 0: run in debug mode */ + uint8_t bModuleDis : 1; /*!< 1: PIT module is disable, 0: PIT module is enable */ + uint8_t bReserved0 : 1; /*!< reserved bit */ + uint8_t bReserved1 : 5; /*!< reserved bit */ + uint8_t bETMerEn : 1; /*!< 1: channel ETMer is enable, 0: channel ETMer is disable */ + uint8_t bInterruptEn : 1; /*!< 1: channel ETMer interrupt is enable, 0: channel ETMer interrupt is disable */ + uint8_t bChainMode : 1; /*!< 1: chain mode is enable, 0: chain mode is disable */ + uint8_t bReserved2 : 5; /*!< reserved bit */ + uint8_t bFlag : 1; /*!< 1: flag is set,and write 1 to clear flag, 0: no flag is set */ + uint8_t bReserved3 : 7; /*!< reserved bit */ + uint32_t u32LoadValue ; /*!< 32-bit channel load value */ +} PIT_ConfigType, *PIT_ConfigPtr; + + +/****************************************************************************** +* Global variables +******************************************************************************/ + + +/*! + * inline functions + */ + +/****************************************************************************** +* PIT API list +* +*//*! @addtogroup pit_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief enable pit module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_Enable(void) +{ + + PIT->MCR &= ~PIT_MCR_MDIS_MASK; + +} + + +/*****************************************************************************//*! +* +* @brief disable pit module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_Disable(void) +{ + + PIT->MCR |= PIT_MCR_MDIS_MASK; +} + + +/*****************************************************************************//*! +* +* @brief pit ETMers are stopped in debug mode. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_SetDebugFreeze(void) +{ + + PIT->MCR |= PIT_MCR_FRZ_MASK; +} + + +/*****************************************************************************//*! +* +* @brief pit ETMers are running in debug mode. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_SetDebugOn(void) +{ + + PIT->MCR &= ~PIT_MCR_FRZ_MASK; +} + + +/*****************************************************************************//*! +* +* @brief enable pit channel ETMer. +* +* @param[in] u8Channel. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelEnable(uint8_t u8Channel) + +{ + + PIT->CHANNEL[u8Channel].TCTRL |= PIT_TCTRL_TEN_MASK; +} + + +/*****************************************************************************//*! +* +* @brief disable pit channel ETMer. +* +* @param[in] u8Channel. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelDisable(uint8_t u8Channel) +{ + + PIT->CHANNEL[u8Channel].TCTRL &= ~PIT_TCTRL_TEN_MASK; +} + + +/*****************************************************************************//*! +* +* @brief enable pit channel ETMer interrupt. +* +* @param[in] u8Channel. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelEnableInt(uint8_t u8Channel) + +{ + + PIT->CHANNEL[u8Channel].TCTRL |= PIT_TCTRL_TIE_MASK; +} + + +/*****************************************************************************//*! +* +* @brief disable pit channel ETMer interrupt . +* +* @param[in] u8Channel. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelDisableInt(uint8_t u8Channel) + +{ + + PIT->CHANNEL[u8Channel].TCTRL &= ~PIT_TCTRL_TIE_MASK; +} + + +/*****************************************************************************//*! +* +* @brief enable pit channel ETMer chain mode. +* +* @param[in] u8Channel. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelEnableChain(uint8_t u8Channel) +{ + PIT->CHANNEL[u8Channel].TCTRL |= PIT_TCTRL_CHN_MASK; +} + + +/*****************************************************************************//*! +* +* @brief disable pit channel ETMer chain mode. +* +* @param[in] u8Channel. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelDisableChain(uint8_t u8Channel) + +{ + PIT->CHANNEL[u8Channel].TCTRL &= ~PIT_TCTRL_CHN_MASK; +} + + +/*****************************************************************************//*! +* +* @brief get pit channel ETMer interrrupt flag. +* +* @param[in] u8Channel. +* +* @return bflag. +* +* @ Pass/ Fail criteria: none + +*****************************************************************************/ +__STATIC_INLINE uint8_t PIT_ChannelGetFlags(uint8_t u8Channel) + +{ + uint8_t bflag; + + bflag = (PIT->CHANNEL[u8Channel].TFLG & PIT_TFLG_TIF_MASK); + + return bflag; + +} + + +/*****************************************************************************//*! +* +* @brief clear pit channel ETMer interrrupt flag. +* +* @param[in] u8Channel +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void PIT_ChannelClrFlags(uint8_t u8Channel) +{ + PIT->CHANNEL[u8Channel].TFLG |= PIT_TFLG_TIF_MASK; +} + + +/****************************************************************************** +* Global functions +******************************************************************************/ +void PIT_Init(uint8_t u8Channel_No, PIT_ConfigType *pConfig); +void PIT_SetLoadVal(uint8_t u8Channel, uint32_t u32loadvalue); +void PIT_SetCallback(uint8_t u8Channel_No, PIT_CallbackType pfnCallback); +void PIT_DeInit(void); +/*! @} End of pit_api_list */ + +#ifdef __cplusplus +} +#endif +#endif /* PIT_H_ */ diff --git a/bsp/nv32f100x/lib/inc/pmc.h b/bsp/nv32f100x/lib/inc/pmc.h new file mode 100644 index 0000000000000000000000000000000000000000..f47b70b9a4f4e654e306fbb7f6f7bd59d204b70e --- /dev/null +++ b/bsp/nv32f100x/lib/inc/pmc.h @@ -0,0 +1,373 @@ +/****************************************************************************** +* +* @brief header file for PMC. +* +******************************************************************************* +* +* provide APIs for accessing PMC +******************************************************************************/ +#ifndef PMC_H_ +#define PMC_H_ +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ +/****************************************************************************** +* PMC system mode definition +* +*//*! @addtogroup pmc_sysmode +* @{ +*******************************************************************************/ +#define PmcModeRun 0 /*!< run mode */ +#define PmcModeWait 1 /*!< wait mode */ +#define PmcModeStop4 2 /*!< stop4 mode */ +#define PmcModeStop3 3 /*!< stop3 mode */ +/*! @} End of pmc_sysmode */ + +/****************************************************************************** +* PMC LVD and LVW voltage definition +* +*//*! @addtogroup pmc_voltageselect +* @{ +*******************************************************************************/ +#define PmcLVDTrip_Low 0 /*!< LVD low trip point */ +#define PmcLVDTrip_High 1 /*!< LVD high trip point */ + +#define PmcLVWTrip_Low 0 /*!< LVW low trip point */ +#define PmcLVWTrip_Mid1 1 /*!< LVW mid1 trip point */ +#define PmcLVWTrip_Mid2 2 /*!< LVW mid2 trip point */ +#define PmcLVWTrip_High 3 /*!< LVW high trip point */ +/*! @} End of pmc_voltageselect */ + + +/****************************************************************************** +* Types +******************************************************************************/ + +/****************************************************************************** +* PMC control struct +* +*//*! @addtogroup pmc_ctrlstruct +* @{ +*******************************************************************************/ +/*! + * @brief PMC Control Structure Type. + * + */ + +typedef union +{ + uint8_t byte; /*!< byte field of union type */ + struct + { + uint8_t bBandgapEn :1; /*!< bandgap enable */ + uint8_t bBandgapDrv :1; /*!< bandgap drive select */ + uint8_t bLvdEn :1; /*!< LVD enable */ + uint8_t bLvdStopEn :1; /*!< LVD enable in stop mode */ + uint8_t bLvdRstEn :1; /*!< reset enable when VLD evvent */ + uint8_t bLvwIrqEn :1; /*!< LVW int enable */ + uint8_t bLvwAck :1; /*!< LVW acknowledge */ + uint8_t bLvwFlag :1; /*!< LVW flag */ + }bits; /*!< bitfield of union type */ +}PMC_Ctrl1Type, *PMC_Ctrl1Ptr; /*!< PMC control1 reg structure */ +/*! @} End of pmc_ctrlstruct */ + +/****************************************************************************** +* PMC control-- voltage select type. +* +*//*! @addtogroup pmc_voltselectstruct +* @{ +*******************************************************************************/ +/*! + * @brief PMC control-- voltage select type. + * + */ +typedef union +{ + uint8_t byte; /*!< byte field of union type */ + struct + { + uint8_t :4; /*!< none */ + uint8_t bLVWV :2; /*!< LVW voltage select */ + uint8_t bLVDV :1; /*!< LVD voltage select */ + uint8_t :1; /*!< none */ + }bits; /*!< bitfield of union type */ +}PMC_Ctrl2Type, *PMC_Ctrl2Ptr; /*!< PMC control2 reg structure */ +/*! @} End of pmc_voltselectstruct */ + +/****************************************************************************** +* PMC configrue type. +* +*//*! @addtogroup pmc_configstruct +* @{ +*******************************************************************************/ +/*! + * @brief PMC configrue type. + * + */ + +typedef struct +{ + PMC_Ctrl1Type sCtrlstatus; /*!< PMC control and status */ + PMC_Ctrl2Type sDetectVoltSelect; /*!< LVW and LVW voltage select */ +}PMC_ConfigType, *PMC_ConfigPtr; /*!< PMC configuration structure */ +/*! @} End of pmc_configstruct */ + + + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/*! + * inline functions + */ +/****************************************************************************** +* PMC api list. +* +*//*! @addtogroup pmc_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! +* +* @brief enable LVD events during stop mode. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_DisableLVDInStopMode. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_EnableLVDInStopMode(PMC_Type *pPMC) +{ + pPMC->SPMSC1 |= PMC_SPMSC1_LVDSE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable LVD events during stop mode. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_EnableLVDInStopMode. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_DisableLVDInStopMode(PMC_Type *pPMC) +{ + pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDSE_MASK; +} + +/*****************************************************************************//*! +* +* @brief enable LVD events to generate a hardware reset, note: write once. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_DisableLVDRst. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_EnableLVDRst(PMC_Type *pPMC) +{ + pPMC->SPMSC1 |= PMC_SPMSC1_LVDRE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable LVD events to generate a hardware reset, note: write once. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_EnableLVDRst. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_DisableLVDRst(PMC_Type *pPMC) +{ + pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDRE_MASK; +} + +/*****************************************************************************//*! +* +* @brief enable low-voltage detect logic, note: write once. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_DisableLVD. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_EnableLVD(PMC_Type *pPMC) +{ + pPMC->SPMSC1 |= PMC_SPMSC1_LVDE_MASK; +} + +/*****************************************************************************//*! +* +* @brief disable low-voltage detect logic, note: write once +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +* @see PMC_EnableLVD. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_DisableLVD(PMC_Type *pPMC) +{ + pPMC->SPMSC1 &= ~PMC_SPMSC1_LVDE_MASK; +} + +/*****************************************************************************//*! +* +* @brief set the low-voltage detect trip point voltage, note: write once. +* +* @param[in] pPMC pointer to the PMC module. +* @param[in] Trippoint LVD trip point voltage,0~1. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_SetLVWTripVolt. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_SetLVDTripVolt(PMC_Type *pPMC, uint8_t Trippoint) +{ + if(Trippoint) + pPMC->SPMSC2 |= PMC_SPMSC2_LVDV_MASK; + else + pPMC->SPMSC2 &= ~PMC_SPMSC2_LVDV_MASK; +} + +/*****************************************************************************//*! +* +* @brief set the low-voltage warning (LVW) trip point voltage. +* +* @param[in] pPMC pointer to the PMC module. +* @param[in] Trippoint LVW trip point voltage,0~3. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_SetLVDTripVolt. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_SetLVWTripVolt(PMC_Type *pPMC, uint8_t Trippoint) +{ + pPMC->SPMSC2 &= ~PMC_SPMSC2_LVWV_MASK; + pPMC->SPMSC2 |= PMC_SPMSC2_LVWV(Trippoint); +} + +/*****************************************************************************//*! +* +* @brief Enable hardware interrupt requests for LVWF. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_DisableLVWInterrupt. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_EnableLVWInterrupt(PMC_Type *pPMC) +{ + pPMC->SPMSC1 |= PMC_SPMSC1_LVWIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief Disable hardware interrupt requests for LVWF. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_EnableLVWInterrupt. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_DisableLVWInterrupt(PMC_Type *pPMC) +{ + pPMC->SPMSC1 &= ~PMC_SPMSC1_LVWIE_MASK; +} + +/*****************************************************************************//*! +* +* @brief get the lvw warning flag. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return uint8_t lvw warning flag. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_ClrLVWFlag. +* +*****************************************************************************/ +__STATIC_INLINE uint8_t PMC_GetLVWFlag(PMC_Type *pPMC) +{ + return (pPMC->SPMSC1 & PMC_SPMSC1_LVWF_MASK); +} + +/*****************************************************************************//*! +* +* @brief clear the lvw warning flag. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_GetLVWFlag. +* +*****************************************************************************/ +__STATIC_INLINE void PMC_ClrLVWFlag(PMC_Type *pPMC) +{ + pPMC->SPMSC1 |= PMC_SPMSC1_LVWACK_MASK; +} + +/*! @} End of pmc_api_list */ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +void PMC_Init(PMC_Type *pPMC, PMC_ConfigType *pPMC_Config); +void PMC_DeInit(PMC_Type *pPMC); +void PMC_SetMode(PMC_Type *pPMC,uint8_t u8PmcMode); + +#ifdef __cplusplus +} +#endif +#endif /* PMC_H_ */ diff --git a/bsp/nv32f100x/lib/inc/rtc.h b/bsp/nv32f100x/lib/inc/rtc.h new file mode 100644 index 0000000000000000000000000000000000000000..ac72bec450bfe505bb5ecfa28c9807fb9964328a --- /dev/null +++ b/bsp/nv32f100x/lib/inc/rtc.h @@ -0,0 +1,224 @@ +/****************************************************************************** +* +* @brief Real-ETMe counter (RTC) driver head file. +* +******************************************************************************/ +#ifndef RTC_H_ +#define RTC_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ + +/****************************************************************************** +* RTC control bit definition +* +*//*! @addtogroup rtc_controlbit +* @{ +*******************************************************************************/ + +#define RTC_OUTPUT_ENABLE 1 /*!< enable RTCO pin */ +#define RTC_INTERRUPT_ENABLE 1 /*!< enable RTC interrupt */ +#define RTC_CLKSRC_EXTERNAL 0 /*!< select external clock as RTC clock source */ +#define RTC_CLKSRC_1KHZ 1 /*!< select LPO as RTC clock source */ +#define RTC_CLKSRC_IREF 2 /*!< select internal reference clock as RTC clock source */ +#define RTC_CLKSRC_BUS 3 /*!< select bus clock as RTC clock source */ +#define RTC_CLK_PRESCALER_128 1 /*!< presalcer is 1 or 128 according to RTCLKS bits */ +#define RTC_CLK_PRESCALER_256 2 /*!< presalcer is 2 or 256 according to RTCLKS bits */ +#define RTC_CLK_PRESCALER_512 3 /*!< presalcer is 4 or 512 according to RTCLKS bits */ +#define RTC_CLK_PRESCALER_1024 4 /*!< presalcer is 8 or 1024 according to RTCLKS bits */ +#define RTC_CLK_PRESCALER_2048 5 /*!< presalcer is 16 or 2048 according to RTCLKS bits */ +#define RTC_CLK_PRESCALER_100 6 /*!< presalcer is 32 or 100 according to RTCLKS bits */ +#define RTC_CLK_PRESCALER_1000 7 /*!< presalcer is 64 or 1000 according to RTCLKS bits */ + + +/*! @} End of rtc_controlbit */ + +/****************************************************************************** +* Types +******************************************************************************/ + +/* + * Callback type + */ + +/****************************************************************************** +* RTC callback function declaration +* +*//*! @addtogroup rtc_callback +* @{ +*******************************************************************************/ + +/*! + * @brief RTC Callback type. + * + */ + +typedef void (*RTC_CallbackType)(void); + +/*! @} End of rtc_callback */ + + +/* RTC configuration structure + */ +/*! + * @brief RTC configuration type. + * + */ +typedef struct +{ + uint16_t bReserved : 4; /*!< reserved */ + uint16_t bRTCOut : 1; /*!< 1: RTCO pin is enable, 0: RTCO pin is disable */ + uint16_t bReserved1 : 1; /*!< reserved */ + uint16_t bInterruptEn : 1; /*!< 1: RTC interrupt is enable, 0: RTC interrupt is disable */ + uint16_t bFlag : 1; /*!< 1: RTC flag is set, 0: RTC flag is not set */ + uint16_t bClockPresaler : 3; /*!< 1: RTC presclaer, from 0x0 to 0x7 */ + uint16_t bReserved2 : 3; /*!< reserved */ + uint16_t bClockSource : 2; /*!< RTC clock source selection from 0x0 to 0x3 */ + uint16_t u16ModuloValue ; /*!< 16-bit rtc modulo value */ +} RTC_ConfigType, *RTC_ConfigPtr; + + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/*! + * inline functions + */ + +/****************************************************************************** +* RTC API list +* +*//*! @addtogroup rtc_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief enable rtc interrupt. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void RTC_EnableInt(void) +{ + RTC->SC |= RTC_SC_RTIE_MASK; +} + + +/*****************************************************************************//*! +* +* @brief disable rtc interrupt. +* +* @param none +* +* @return non +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void RTC_DisableInt(void) +{ + RTC->SC &= ~RTC_SC_RTIE_MASK; +} + + +/*****************************************************************************//*! +* +* @brief set rtc modulo value. +* +* @param[in] u16Mod_Value +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void RTC_SetModulo(uint16_t u16Mod_Value) +{ + + RTC->MOD = u16Mod_Value; +} + +/*****************************************************************************//*! +* +* @brief set rtc clock source and presalcer. +* +* @param[in] u16Clock_Number clock source number +* @param[in] u16Presalcer prescaler value +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void RTC_SetClock(uint16_t u16Clock_Number, uint16_t u16Presalcer) +{ + uint32_t u32rtc_sc; + + u32rtc_sc = RTC->SC; + u32rtc_sc &= ~(RTC_SC_RTCLKS_MASK | RTC_SC_RTCPS_MASK); + u32rtc_sc |= RTC_SC_RTCLKS(u16Clock_Number) | RTC_SC_RTCPS(u16Presalcer); + RTC->SC = u32rtc_sc; +} + +/*****************************************************************************//*! +* +* @brief get rtc flag bit. +* +* @param none +* +* @return bflag. +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t RTC_GetFlags(void) +{ + uint8_t bflag; + + bflag = RTC->SC & RTC_SC_RTIF_MASK; + + return bflag; +} + + +/*****************************************************************************//*! +* +* @brief clear rtc flag bit. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void RTC_ClrFlags(void) +{ + RTC->SC |= RTC_SC_RTIF_MASK; +} + + +/****************************************************************************** +* Global functions +******************************************************************************/ +void RTC_Init(RTC_ConfigType *pConfig); +void RTC_SetCallback(RTC_CallbackType pfnCallback); +void RTC_DeInit(void); + +/*! @} End of rtc_api_list */ + +#ifdef __cplusplus +} +#endif +#endif /* RTC_H_ */ diff --git a/bsp/nv32f100x/lib/inc/sim.h b/bsp/nv32f100x/lib/inc/sim.h new file mode 100644 index 0000000000000000000000000000000000000000..5a6a2ec8d3836ef01625301e6ea1cc212c31c9f7 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/sim.h @@ -0,0 +1,2507 @@ +/****************************************************************************** +* +* @brief header file for SIM utilities. +* +******************************************************************************* +* +* provide APIs for accessing SIM +******************************************************************************/ + +#ifndef SIM_H_ +#define SIM_H_ + +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* define SIM device ID types +* +*//*! @addtogroup sim_id_types +* @{ +*******************************************************************************/ + +typedef enum { + ID_TYPE_FAMID, /*!< device Family ID */ + ID_TYPE_SUBFAMID, /*!< device Subfamily ID */ + ID_TYPE_REVID, /*!< device Revision ID */ + ID_TYPE_PINID /*!< device Pin ID (Pin count) */ +} IDType; +/*! @} End of sim_id_types */ + +/****************************************************************************** +* Macros +******************************************************************************/ + +/****************************************************************************** +* Types +******************************************************************************/ + +/* SIM configuration structure + */ + +/****************************************************************************** +* define SIM configuration structure +* +*//*! @addtogroup sim_config_type +* @{ +*******************************************************************************/ + +/*! + * @brief SIM configuration structure. + * + */ +#if defined(CPU_NV32) +typedef struct{ + struct{ + uint32_t bEnableCLKOUT : 1; /*!< 1: enable , 0: disable */ + uint32_t bTXDME : 1; /*!< 1: enable TXDME, 0: disable */ + uint32_t bETMSYNC : 1; /*!< 1: enable ETM SYNC, 0: no sync */ + uint32_t bRXDFE : 1; /*!< 1: enable RXD filter, 0: no filter */ + uint32_t bRXDCE : 1; /*!< 1: enable RXD capture, 0: no capture */ + uint32_t bACIC : 1; /*!< 1: ACMP0 to ETM1 channel0 connection, 0: no connection */ + uint32_t bRTCC : 1; /*!< 1: RTC overflow connected to ETM1 channel1, 0: no connection */ + uint32_t u8ADHWT : 2; /*!< ADC h/w trigger source selection */ + uint32_t bDisableSWD : 1; /*!< 1: disable SWD, 0: enable */ + uint32_t bDisableRESET : 1; /*!< 1: disable RESET pin, 0: enable */ + uint32_t bDisableNMI : 1; /*!< 1: disable NMI pin, 0: enable */ + uint32_t bBusDiv : 1; /*!< bus divider BUSDIV value */ + } sBits; + uint8_t u8Delay; /*!< delay value */ + uint8_t u8BusRef; /*!< bus reference */ + uint32_t u32PinSel; /*!< pin select reg value */ + uint32_t u32SCGC; /*!< clock gating value register */ +} SIM_ConfigType, *SIM_ConfigPtr; /*!< sim configuration structure type */ +#elif defined(CPU_NV32M3) +typedef struct{ + struct{ + uint32_t bEnableCLKOUT : 1; /*!< 1: enable , 0: disable */ + uint32_t bTXDME : 1; /*!< 1: enable TXDME, 0: disable */ + uint32_t bETMSYNC : 1; /*!< 1: enable ETM SYNC, 0: no sync */ + uint32_t bRXDCE : 1; /*!< 1: enable RXD capture, 0: no capture */ + uint32_t bRXDFE : 2; /*!< 1: enable RXD filter, 0: no filter */ + uint32_t u8ADHWT : 3; /*!< ADC h/w trigger source selection */ + uint32_t bETMIC : 2; /*!< ETM0CH0 input capture source selection */ + uint32_t bACTRG : 1; /*!< ACMP Trigger ETM2 selection*/ + uint32_t bDisableSWD : 1; /*!< 1: disable SWD, 0: enable */ + uint32_t bDisableRESET : 1; /*!< 1: disable RESET pin, 0: enable */ + uint32_t bDisableNMI : 1; /*!< 1: disable NMI pin, 0: enable */ + } sBits; + uint8_t u8Delay; /*!< delay value */ + uint8_t u8BusRef; /*!< bus reference */ + uint32_t u32PinSel; /*!< pin select reg value */ + uint32_t u32SCGC; /*!< clock gating value register */ + uint32_t u32CLKDIV; /*!< clock divider CLKDIV value */ +} SIM_ConfigType, *SIM_ConfigPtr; /*!< sim configuration structure type */ +#elif defined(CPU_NV32M4) +typedef struct{ + struct{ + uint32_t bEnableCLKOUT : 1; /*!< 1: enable , 0: disable */ + uint32_t bTXDME : 1; /*!< 1: enable TXDME, 0: disable */ + uint32_t bETMSYNC : 1; /*!< 1: enable ETM SYNC, 0: no sync */ + uint32_t bRXDCE : 1; /*!< 1: enable RXD capture, 0: no capture */ + uint32_t bRXDFE : 2; /*!< 1: enable RXD filter, 0: no filter */ + uint32_t u8ADHWT : 3; /*!< ADC h/w trigger source selection */ + uint32_t bACTRG : 1; /*!< ACMP Trigger ETM2 selection*/ + uint32_t bDisableSWD : 1; /*!< 1: disable SWD, 0: enable */ + uint32_t bDisableRESET : 1; /*!< 1: disable RESET pin, 0: enable */ + uint32_t bDisableNMI : 1; /*!< 1: disable NMI pin, 0: enable */ + } sBits; + uint8_t u8Delay; /*!< delay value */ + uint8_t u8BusRef; /*!< bus reference */ + uint32_t u32PinSel; /*!< pin select reg value */ + uint32_t u32SCGC; /*!< clock gating value register */ + uint32_t u32CLKDIV; /*!< clock divider CLKDIV value */ +} SIM_ConfigType, *SIM_ConfigPtr; /*!< sim configuration structure type */ +#endif +/*! @} End of sim_config_type */ + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ +/****************************************************************************** +* define SIM API list +* +*//*! @addtogroup sim_api_list +* @{ +*******************************************************************************/ +#if defined(CPU_NV32) +/*****************************************************************************//*! +* +* @brief delay ETM2 triggering ADC for u8Delay bus clock output divide. +* +* @param[in] u8Delay delay value of Bus clock output divide. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DelayETM2Trig2ADC(uint8_t u8Delay) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_DELAY_MASK)) | SIM_SOPT_DELAY(u8Delay); +} +/*****************************************************************************//*! +* +* @brief enable clock output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see SIM_DisableClockOutput +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableClockOutput(void) +{ + SIM->SOPT |= (SIM_SOPT_CLKOE_MASK); +} + +/*****************************************************************************//*! +* +* @brief disable clock output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see SIM_EnableClockOutput +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableClockOutput(void) +{ + SIM->SOPT &= ~(SIM_SOPT_CLKOE_MASK); +} +/*****************************************************************************//*! +* +* @brief set bus clock output divide. +* +* @param[in] u8Divide divide (3-bits) +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClockOutputDivide(uint8_t u8Divide) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_BUSREF_MASK)) | SIM_SOPT_BUSREF(u8Divide & 0x07); +} +/*****************************************************************************//*! +* +* @brief enable UART0 RXD connect with UART0 module and ETM0 channel 1.. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0RXDConnectETMOCH1(void) +{ + SIM->SOPT |= (SIM_SOPT_RXDCE_MASK); +} +/*****************************************************************************//*! +* +* @brief enable UART0 TX modulation. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0Modulation(void) +{ + SIM->SOPT |= (SIM_SOPT_TXDME_MASK); +} + +/*****************************************************************************//*! +* +* @brief disable UART0 TX modulation. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableUART0Modulation(void) +{ + SIM->SOPT &= ~(SIM_SOPT_TXDME_MASK); +} +/*****************************************************************************//*! +* +* @brief generate a softare sync trigger to ETM2 module (trigger). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_GenerateSoftwareTrig2ETM2(void) +{ + SIM->SOPT |= (SIM_SOPT_ETMSYNC_MASK); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH3 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH3Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2PS3_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap ETM2CH2 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH2Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2PS2_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH1 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH1Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_UART0PS_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap SPI0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapSPI0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_SPI0PS_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap I2C pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapI2CPin(void) +{ + SIM->PINSEL |= SIM_PINSEL_IICPS_MASK; +} +/*****************************************************************************//*! +* +* @brief enable UART0 RX filter. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0Filter(void) +{ + SIM->SOPT |= (SIM_SOPT_RXDFE_MASK); +} +/******************************************************************************! + +* @function name: SIM_DisableUART0Filter +* +* @brief disable UART0 RX filter. +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableUART0Filter(void) +{ + SIM->SOPT &= ~(SIM_SOPT_RXDFE_MASK); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to RTC overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByRTC(void) +{ + SIM->SOPT &= ~(SIM_SOPT_ADHWT_MASK); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to PIT . +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPIT(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(1); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM2 init trigger with 8-bit programmable delay. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByETM2Init(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(2); +} + +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM2 match trigger with 8-bit programmable delay. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByETM2Match(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(3); +} +/*****************************************************************************//*! +* +* @brief enable RTC capture to ETM1 input channel1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableRTCCapture(void) +{ + SIM->SOPT |= (SIM_SOPT_RTCC_MASK); +} +/*****************************************************************************//*! +* +* @brief disable RTC capture to ETM1 input channel1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableRTCCapture(void) +{ + SIM->SOPT &= ~(SIM_SOPT_RTCC_MASK); +} +/*****************************************************************************//*! +* +* @brief enable ACMP0 input capture to ETM1 input channel0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableACMP0InputCapture(void) +{ + SIM->SOPT |= (SIM_SOPT_ACIC_MASK); +} +/*****************************************************************************//*! +* +* @brief disable ACMP0 input capture to ETM1 input channel0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableACMP0InputCapture(void) +{ + SIM->SOPT &= ~(SIM_SOPT_ACIC_MASK); +} +/*****************************************************************************//*! +* +* @brief remap RTC pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapRTCPin(void) +{ + SIM->PINSEL |= SIM_PINSEL_RTCPS_MASK; +} +/*****************************************************************************//*! +* +* @brief set bus divide BUSDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetBusDivide(uint8_t u8Divide) +{ + SIM->BUSDIV = u8Divide; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH1 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH1Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2PS1_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap ETM2CH0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2PS0_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap ETM1CH1 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM1CH1Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM1PS1_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap ETM1CH0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM1CH0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM1PS0_MASK; +} +#elif defined(CPU_NV32M3) +/*****************************************************************************//*! +* +* @brief delay ETM2 triggering ADC for u8Delay bus clock output divide. +* +* @param[in] u8Delay delay value of Bus clock output divide. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DelayETM2Trig2ADC(uint8_t u8Delay) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_DELAY_MASK)) | SIM_SOPT_DELAY(u8Delay); +} +/*****************************************************************************//*! +* +* @brief enable clock output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see SIM_DisableClockOutput +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableClockOutput(void) +{ + SIM->SOPT |= (SIM_SOPT_CLKOE_MASK); +} + +/*****************************************************************************//*! +* +* @brief disable clock output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see SIM_EnableClockOutput +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableClockOutput(void) +{ + SIM->SOPT &= ~(SIM_SOPT_CLKOE_MASK); +} +/*****************************************************************************//*! +* +* @brief set bus clock output divide. +* +* @param[in] u8Divide divide (3-bits) +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClockOutputDivide(uint8_t u8Divide) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_BUSREF_MASK)) | SIM_SOPT_BUSREF(u8Divide & 0x07); +} +/*****************************************************************************//*! +* +* @brief enable UART0 RXD connect with UART0 module and ETM0 channel 1.. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0RXDConnectETMOCH1(void) +{ + SIM->SOPT |= (SIM_SOPT_RXDCE_MASK); +} +/*****************************************************************************//*! +* +* @brief enable UART0 TX modulation. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0Modulation(void) +{ + SIM->SOPT |= (SIM_SOPT_TXDME_MASK); +} + +/*****************************************************************************//*! +* +* @brief disable UART0 TX modulation. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableUART0Modulation(void) +{ + SIM->SOPT &= ~(SIM_SOPT_TXDME_MASK); +} +/*****************************************************************************//*! +* +* @brief generate a softare sync trigger to ETM2 module (trigger). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_GenerateSoftwareTrig2ETM2(void) +{ + SIM->SOPT |= (SIM_SOPT_ETMSYNC_MASK); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH3 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH3Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2PS3_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap ETM2CH2 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH2Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2PS2_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH1 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH1Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_UART0PS_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap SPI0 pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapSPI0Pin(void) +{ + SIM->PINSEL |= SIM_PINSEL_SPI0PS_MASK; +} + +/*****************************************************************************//*! +* +* @brief remap I2C pin from default to the other. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapI2CPin(void) +{ + SIM->PINSEL |= SIM_PINSEL_IICPS_MASK; +} +/*****************************************************************************//*! +* +* @brief UART0 RXD input signal is connected to UART0 module directly. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0Filter(void) +{ + SIM->SOPT &= ~(SIM_SOPT_RXDFE_MASK); +} +/*****************************************************************************//*! +* +* @brief UART0 RXD input signal is filtered by ACMP0, then injected to UART0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0FilterByACMP0(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_RXDFE_MASK)) | SIM_SOPT_RXDFE(1); +} +/*****************************************************************************//*! +* +* @brief UART0 RXD input signal is filtered by ACMP1, then injected to UART0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0FilterByACMP1(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_RXDFE_MASK)) | SIM_SOPT_RXDFE(2); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to RTC overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByRTC(void) +{ + SIM->SOPT &= ~(SIM_SOPT_ADHWT_MASK); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM0 init trigger . +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPIT(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(1); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM2 init trigger with 8-bit programmable delay. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByETM2Init(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(2); +} + +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM2 match trigger with 8-bit programmable delay. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByETM2Match(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(3); +} + +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to PIT channel0 overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPITCH0Overflow(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(4); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to PIT channel1 overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPITChannel1Overflow(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(5); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ACMP0 out. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByACMP0Out(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(6); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ACMP1 out. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByACMP1Out(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ADHWT_MASK)) | SIM_SOPT_ADHWT(7); +} +/*****************************************************************************//*! +* +* @brief Select ETM0CH0 as ETM0CH0 Input Capture Source. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelETM0CH0AsETM0CH0ICS(void) +{ + SIM->SOPT &= ~(SIM_SOPT_ETMIC_MASK); +} +/*****************************************************************************//*! +* +* @brief Select ACMP0 OUT as ETM0CH0 Input Capture Source. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelACMP0AsETM0CH0ICS(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ETMIC_MASK)) | SIM_SOPT_ETMIC(1); +} +/*****************************************************************************//*! +* +* @brief Select ACMP1 OUT as ETM0CH0 Input Capture Source. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelACMP1AsETM0CH0ICS(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ETMIC_MASK)) | SIM_SOPT_ETMIC(2); +} +/*****************************************************************************//*! +* +* @brief Select RTC overflow as ETM0CH0 Input Capture Source. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelRTCOverflowAsETM0CH0ICS(void) +{ + SIM->SOPT = (SIM->SOPT & ~(SIM_SOPT_ETMIC_MASK)) | SIM_SOPT_ETMIC(3); +} +/*****************************************************************************//*! +* +* @brief Select ACMP0 output as the trigger0 input of ETM2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelACMP0AsETM2Trigger0(void) +{ + SIM->SOPT &= ~(SIM_SOPT_ACTRG_MASK); +} +/*****************************************************************************//*! +* +* @brief Select ACMP1 output as the trigger0 input of ETM2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelACMP1AsETM2Trigger0(void) +{ + SIM->SOPT |= (SIM_SOPT_ACTRG_MASK); +} +/*****************************************************************************//*! +* +* @brief set clock3 divide CLKDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClock3Divide(void) +{ + SIM->CLKDIV |= SIM_CLKDIV_OUTDIV3_MASK; +} +/*****************************************************************************//*! +* +* @brief set clock2 divide CLKDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClock2Divide(void) +{ + SIM->CLKDIV |= SIM_CLKDIV_OUTDIV2_MASK; +} +/*****************************************************************************//*! +* +* @brief set clock1 divide CLKDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClock1Divide(uint8_t u8divide) +{ + SIM->CLKDIV |= SIM_CLKDIV_OUTDIV1(u8divide); +} +/*****************************************************************************//*! +* +* @brief select TCLK2 for PWT module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK2ForPWT(void) +{ + SIM->PINSEL |= SIM_PINSEL_PWTCLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for PWT module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForPWT(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_PWTCLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK2 for ETM2 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK2ForETM2(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM2CLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for ETM2 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForETM2(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_ETM2CLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK2 for ETM0 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK2ForETM0(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0CLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for ETM0 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForETM0(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_ETM0CLKPS_MASK; +} +#elif defined(CPU_NV32M4) +/*****************************************************************************//*! +* +* @brief delay ETM2 triggering ADC for u8Delay bus clock output divide. +* +* @param[in] u8Delay delay value of Bus clock output divide. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DelayETM2Trig2ADC(uint8_t u8Delay) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_DELAY_MASK)) | SIM_SOPT0_DELAY(u8Delay); +} +/*****************************************************************************//*! +* +* @brief enable clock output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see SIM_DisableClockOutput +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableClockOutput(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_CLKOE_MASK); +} + +/*****************************************************************************//*! +* +* @brief disable clock output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see SIM_EnableClockOutput +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableClockOutput(void) +{ + SIM->SOPT0 &= ~(SIM_SOPT0_CLKOE_MASK); +} +/*****************************************************************************//*! +* +* @brief set bus clock output divide. +* +* @param[in] u8Divide divide (3-bits) +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClockOutputDivide(uint8_t u8Divide) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_BUSREF_MASK)) | SIM_SOPT0_BUSREF(u8Divide & 0x07); +} +/*****************************************************************************//*! +* +* @brief enable UART0 RXD connect with UART0 module and ETM0 channel 1.. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0RXDConnectETMOCH1(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_RXDCE_MASK); +} +/*****************************************************************************//*! +* +* @brief enable UART0 TX modulation. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0Modulation(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_TXDME_MASK); +} + +/*****************************************************************************//*! +* +* @brief disable UART0 TX modulation. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableUART0Modulation(void) +{ + SIM->SOPT0 &= ~(SIM_SOPT0_TXDME_MASK); +} +/*****************************************************************************//*! +* +* @brief generate a softare sync trigger to ETM2 module (trigger). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_GenerateSoftwareTrig2ETM2(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_ETMSYNC_MASK); +} +/*****************************************************************************//*! +* +* @brief select PWTIN3 input signal from UART0RX. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +__STATIC_INLINE void SIM_SetPWTIN3InputFromUART0Rx(void) +{ + SIM->SOPT1 = (SIM->SOPT1 & (~SIM_SOPT1_UARTPWTS_MASK)) | SIM_SOPT1_UARTPWTS(0); +} +/*****************************************************************************//*! +* +* @brief select PWTIN3 input signal from UART1RX. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +__STATIC_INLINE void SIM_SetPWTIN3InputFromUART1Rx(void) +{ + SIM->SOPT1 = (SIM->SOPT1 & (~SIM_SOPT1_UARTPWTS_MASK)) | SIM_SOPT1_UARTPWTS(1); +} +/*****************************************************************************//*! +* +* @brief select PWTIN3 input signal from UART2RX. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +__STATIC_INLINE void SIM_SetPWTIN3InputFromUART2Rx(void) +{ + SIM->SOPT1 = (SIM->SOPT1 & (~SIM_SOPT1_UARTPWTS_MASK)) | SIM_SOPT1_UARTPWTS(2); +} +/*****************************************************************************//*! +* +* @brief select PWTIN2 input signal from ACMP0_OUT. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetPWTIN2InputFromACMP0(void) +{ + SIM->SOPT1 &= (~SIM_SOPT1_ACPWTS_MASK); +} +/*****************************************************************************//*! +* +* @brief select PWTIN2 input signal from ACMP1_OUT. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetPWTIN2InputFromACMP1(void) +{ + SIM->SOPT1 |= SIM_SOPT1_ACPWTS_MASK; +} +/*****************************************************************************//*! +* +* @brief enable invertion of the I2C output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableI2C0OuputInvertion(void) +{ + SIM->SOPT1 |= SIM_SOPT1_I2C0OINV_MASK; +} +/*****************************************************************************//*! +* +* @brief disable invertion of the I2C output. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_DisableI2C0OuputInvertion(void) +{ + SIM->SOPT1 &= ~SIM_SOPT1_I2C0OINV_MASK; +} + +/*****************************************************************************//*! +* +* @brief enable 4-wire I2C. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_Enable4WireI2C0(void) +{ + SIM->SOPT1 |= SIM_SOPT1_I2C04WEN_MASK; +} +/*****************************************************************************//*! +* +* @brief disable 4-wire I2C.. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_Disable4WireI2C0(void) +{ + SIM->SOPT1 &= ~SIM_SOPT1_I2C04WEN_MASK; +} +/*****************************************************************************//*! +* +* @brief UART0 RXD input signal is connected to UART0 module directly. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0Filter(void) +{ + SIM->SOPT0 &= ~(SIM_SOPT0_RXDFE_MASK); +} +/*****************************************************************************//*! +* +* @brief UART0 RXD input signal is filtered by ACMP0, then injected to UART0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0FilterByACMP0(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_RXDFE_MASK)) | SIM_SOPT0_RXDFE(1); +} +/*****************************************************************************//*! +* +* @brief UART0 RXD input signal is filtered by ACMP1, then injected to UART0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableUART0FilterByACMP1(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_RXDFE_MASK)) | SIM_SOPT0_RXDFE(2); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to RTC overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByRTC(void) +{ + SIM->SOPT0 &= ~(SIM_SOPT0_ADHWT_MASK); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to PIT . +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPIT(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(1); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM2 init trigger with 8-bit programmable delay. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByETM2Init(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(2); +} + +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ETM2 match trigger with 8-bit programmable delay. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByETM2Match(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(3); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to PIT channel0 overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPITCH0Overflow(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(4); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to PIT channel1 overflow. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByPITChannel1Overflow(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(5); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ACMP0 out. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByACMP0Out(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(6); +} +/*****************************************************************************//*! +* +* @brief set ADC hardware trigger source to ACMP1 out. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_TriggerADCByACMP1Out(void) +{ + SIM->SOPT0 = (SIM->SOPT0 & ~(SIM_SOPT0_ADHWT_MASK)) | SIM_SOPT0_ADHWT(7); +} +/*****************************************************************************//*! +* +* @brief Select ACMP0 output as the trigger0 input of ETM2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelACMP0AsETM2Trigger0(void) +{ + SIM->SOPT0 &= ~(SIM_SOPT0_ACTRG_MASK); +} +/*****************************************************************************//*! +* +* @brief Select ACMP1 output as the trigger0 input of ETM2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelACMP1AsETM2Trigger0(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_ACTRG_MASK); +} +/*****************************************************************************//*! +* +* @brief enable RTC capture to ETM1 input channel1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableRTCCapture(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_RTCC_MASK); +} +/*****************************************************************************//*! +* +* @brief enable ACMP0 input capture to ETM1 input channel0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_EnableACMP0InputCapture(void) +{ + SIM->SOPT0 |= (SIM_SOPT0_ACIC_MASK); +} +/*****************************************************************************//*! +* +* @brief select TCLK0 for PWT module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK0ForPWT(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_PWTCLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for PWT module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForPWT(void) +{ + SIM->PINSEL = (SIM->PINSEL&(~SIM_PINSEL_PWTCLKPS_MASK)) | SIM_PINSEL_PWTCLKPS(1) ; +} +/*****************************************************************************//*! +* +* @brief select TCLK2 for PWT module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK2ForPWT(void) +{ + SIM->PINSEL = (SIM->PINSEL&(~SIM_PINSEL_PWTCLKPS_MASK)) | SIM_PINSEL_PWTCLKPS(2) ; +} +/*****************************************************************************//*! +* +* @brief select TCLK0 for ETM2 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK0ForETM2(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_ETM2CLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for ETM2 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForETM2(void) +{ + SIM->PINSEL = (SIM->PINSEL & (~SIM_PINSEL_ETM2CLKPS_MASK)) | (((uint32_t)0x1)<PINSEL =(SIM->PINSEL & (~SIM_PINSEL_ETM2CLKPS_MASK)) | (((uint32_t)0x2)<PINSEL &= ~SIM_PINSEL_ETM1CLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for ETM1 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForETM1(void) +{ + SIM->PINSEL = (SIM->PINSEL & (~SIM_PINSEL_ETM1CLKPS_MASK)) | (((uint32_t)0x1)<PINSEL = (SIM->PINSEL & (~SIM_PINSEL_ETM1CLKPS_MASK)) | (((uint32_t)0x2)<PINSEL &= ~SIM_PINSEL_ETM0CLKPS_MASK; +} +/*****************************************************************************//*! +* +* @brief select TCLK1 for ETM0 module. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SelectTCLK1ForETM0(void) +{ + SIM->PINSEL = (SIM->PINSEL &(~SIM_PINSEL_ETM0CLKPS_MASK)) | (((uint32_t)0x1)<PINSEL = (SIM->PINSEL &(~SIM_PINSEL_ETM0CLKPS_MASK)) | (((uint32_t)0x2)<PINSEL &= ~SIM_PINSEL_ETM1PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM1CH1 to pin PTE7. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM1CH1ToPTE7(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM1PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM1CH0 to pin PTC4 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM1CH0ToPTC4(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_ETM1PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM1CH0 to pin PTH2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM1CH0ToPTH2(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM1PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH1 to pin PTA1 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH1ToPTA1(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH1 to pin PTB3. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH1ToPTB3(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_ETM0PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH0 to pin PTA0 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH0ToPTA1(void) +{ + SIM->PINSEL |= SIM_PINSEL_ETM0PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM0CH0 to pin PTB2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM0CH0ToPTB3(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_ETM0PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART0 to pin PTB0/1 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART0ToPTB_0_1(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_UART0PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART0 to pin PTA2/3. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART0ToPTA_2_3(void) +{ + SIM->PINSEL |= SIM_PINSEL_UART0PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap SPI0 to pin PTB2/3/4/5 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapSPI0ToPTB_2_3_4_5(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_SPI0PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap SPI0 to pin PTE01/2/3. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapSPI0ToPTE_0_12_3(void) +{ + SIM->PINSEL |= SIM_PINSEL_SPI0PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap I2C to pin PTA2/3 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapI2CToPTA_2_3(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_I2C0PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap I2C to pin PTB6/7 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapI2CToPTB_6_7(void) +{ + SIM->PINSEL |= SIM_PINSEL_I2C0PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap RTC to pin PTC4 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapRTCToPTC4(void) +{ + SIM->PINSEL &= ~SIM_PINSEL_RTCPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap RTC to pin PTC5. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapRTCToPTC5(void) +{ + SIM->PINSEL |= SIM_PINSEL_RTCPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap MSCAN to pin PTC6/7 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapMSCANToPTC_6_7(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_MSCANPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap MSCAN to pin PTH2/7. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapMSCANToPTH_2_7(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_MSCANPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap PWTIN1 to pin PTB0 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapPWTIN1ToPTB0(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_MSCANPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap PWTIN1 to pin PTH7. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapPWTIN1ToPTH7(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_MSCANPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap PWTIN0 to pin PTD5 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapPWTIN0ToPTD5(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_MSCANPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap PWTIN0 to pin PTE2. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapPWTIN0ToPTE2(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_MSCANPS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART2 to pin PTD6/7 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART2ToPTD_6_7(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_UART2PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART2 to pin PTI0/1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART2ToPTI_0_1(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_UART2PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART1 to pin PTC6/7 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART1ToPTC_6_7(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_UART1PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap UART1 to pin PTF2/3. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapUART1ToPTF_2_3(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_UART1PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap SPI1 to pin PTD0/1/2/3 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapSPI1ToPTD_0_1_2_3(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_SPI1PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap SPI1 to pin PTG4/5/6/7. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapSPI1ToPTG_4_5_6_7(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_SPI1PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap I2C1 to pin PTE0/1 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapI2C1ToPTE_0_1(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_I2C1PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap I2C1 to pin PTH3/4. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapI2C1ToPTH_3_4(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_I2C1PS_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH5 to pin PTB5 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH5ToPTB5(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_ETM2PS5_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH5 to pin PTG7. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH5ToPTG7(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_ETM2PS5_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH4 to pin PTB4 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH4ToPTB4(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_ETM2PS4_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH4 to pin PTG6. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH4ToPTG6(void) +{ + SIM->PINSEL1 |= SIM_PINSEL1_ETM2PS4_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH3 to pin PTC3 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH3ToPTC3(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_ETM2PS3_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH3 to pin PTD1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH3ToPTD1(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS3_MASK)) | SIM_PINSEL1_ETM2PS3(1); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH3 to pin PTG5. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH3ToPTG5(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS3_MASK)) | SIM_PINSEL1_ETM2PS3(2); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH2 to pin PTC2 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH2ToPTC2(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_ETM2PS2_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH2 to pin PTD0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH2ToPTD0(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS2_MASK)) | SIM_PINSEL1_ETM2PS2(1); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH2 to pin PTG4. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH2ToPTG4(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS2_MASK)) | SIM_PINSEL1_ETM2PS2(2); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH1 to pin PTC1 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH1ToPTC1(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_ETM2PS1_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH1 to pin PTH1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH1ToPTH1(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS1_MASK)) | SIM_PINSEL1_ETM2PS1(1); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH1 to pin PTF1. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH1ToPTF1(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS1_MASK)) | SIM_PINSEL1_ETM2PS1(2); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH0 to pin PTC0 (default). +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH0ToPTC0(void) +{ + SIM->PINSEL1 &= ~SIM_PINSEL1_ETM2PS0_MASK; +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH0 to pin PTH0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH0ToPTH0(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 & (~SIM_PINSEL1_ETM2PS0_MASK)) | SIM_PINSEL1_ETM2PS0(1); +} +/*****************************************************************************//*! +* +* @brief remap ETM2CH0 to pin PTF0. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_RemapETM2CH0ToPTF0(void) +{ + SIM->PINSEL1 = (SIM->PINSEL1 &(~SIM_PINSEL1_ETM2PS0_MASK)) | SIM_PINSEL1_ETM2PS0(2); +} +/*****************************************************************************//*! +* +* @brief set clock3 divide CLKDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClock3Divide(void) +{ + SIM->CLKDIV |= SIM_CLKDIV_OUTDIV3_MASK; +} +/*****************************************************************************//*! +* +* @brief set clock2 divide CLKDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClock2Divide(void) +{ + SIM->CLKDIV |= SIM_CLKDIV_OUTDIV2_MASK; +} +/*****************************************************************************//*! +* +* @brief set clock1 divide CLKDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetClock1Divide(uint8_t u8divide) +{ + SIM->CLKDIV |= SIM_CLKDIV_OUTDIV1(u8divide); +} +/*****************************************************************************//*! +* +* @brief set bus divide BUSDIV. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE void SIM_SetBusDivide(uint8_t u8Divide) +{ + SIM->CLKDIV = u8Divide; +} + +#endif + + +/*! @} End of sim_api_list */ + +void SIM_Init(SIM_ConfigType *pConfig); +void SIM_SetClockGating(uint32_t u32PeripheralMask, uint8_t u8GateOn); +uint32_t SIM_GetStatus(uint32_t u32StatusMask); +uint8_t SIM_ReadID(IDType sID); + +#endif /* SIM_H_ */ + + diff --git a/bsp/nv32f100x/lib/inc/spi.h b/bsp/nv32f100x/lib/inc/spi.h new file mode 100644 index 0000000000000000000000000000000000000000..8def944c794962e06a905fc8153c5a6fb58fc72d --- /dev/null +++ b/bsp/nv32f100x/lib/inc/spi.h @@ -0,0 +1,634 @@ +/****************************************************************************** +* +* @brief header file for SPI module utilities (SPI). +* +******************************************************************************* +* +* provide APIs for accessing SPI module (SPI) +******************************************************************************/ + +#ifndef SPI_H_ +#define SPI_H_ +#ifdef __cplusplus +extern "C" { +#endif +/****************************************************************************** +* Includes +******************************************************************************/ + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ +/* maximum number of SPIs */ +#define MAX_SPI_NO 2 + + + +/****************************************************************************** +* define SPI register default value +* +*//*! @addtogroup spi_default_value +* @{ +*******************************************************************************/ + +#define SPI_C1_DEFAULT 0x04 /*!< SPI C1 register */ +#define SPI_C2_DEFAULT 0x00 /*!< SPI C2 register */ +#define SPI_BR_DEFAULT 0x00 /*!< SPI BR register */ +#define SPI_S_DEFAULT 0x20 /*!< SPI S register */ +#define SPI_M_DEFAULT 0x00 /*!< SPI M register */ +/*! @} End of spi_default_value */ + +/****************************************************************************** +* define SPI error status +* +*//*! @addtogroup spi_error_list +* @{ +*******************************************************************************/ + +#define SPI_ERR_SUCCESS 0 /*!< success */ +#define SPI_ERR_CODE_BASE ((uint32)SPI0 - 0x40000000L) /*!< error code base for SPI */ +#define SPI_ERR_TXBUF_NOT_EMPTY (SPI_ERR_CODE_BASE+1) /*!< failure due to SPTEF (empty) not set */ +#define SPI_ERR_RXBUF_NOT_FULL (SPI_ERR_CODE_BASE+2) /*!< failure due to SPRF (full) not set */ +/*! @} End of spi_error_list */ + +/****************************************************************************** +* Types +******************************************************************************/ + +typedef uint8_t SPI_WidthType; /* SPI width type */ +typedef uint32_t ResultType; /* SPI routine Result code */ + +/****************************************************************************** +* define SPI call back funtion +* +*//*! @addtogroup spi_callback +* @{ +*******************************************************************************/ +typedef void (*SPI_CallbackType)(void); /*!< SPI call back function */ +/*! @} End of spi_callback */ + +/****************************************************************************** +* +*//*! @addtogroup spi_setting_type +* @{ +*******************************************************************************/ +/*! + * @brief SPI setting type. + * + */ +typedef struct +{ + uint32_t bIntEn : 1; /*!< 1: Interrupt Enable, 0: Interrupt disable */ + uint32_t bModuleEn : 1; /*!< 1: SPI module Enable, 0: SPI module disable */ + uint32_t bTxIntEn : 1; /*!< 1: Tx Interrupt Enable, 0: Tx Interrupt disable */ + uint32_t bMasterMode : 1; /*!< 1: Master mode, 0: Slave mode */ + uint32_t bClkPolarityLow : 1; /*!< 1: Active-low SPI clock, 0: Active-HIgh SPI clock */ + uint32_t bClkPhase1 : 1; /*!< Set clock phase */ + uint32_t bMasterAutoDriveSS : 1; /*!< Slave select output enable */ + uint32_t bShiftLSBFirst : 1; /*!< 1: LSB first, 0: MSB first */ + uint32_t bMatchIntEn : 1; /*!< 1: Match interrupt Enable, 0: Match interrupt disable */ + uint32_t bModeFaultEn : 1; /*!< Master mode-fault function enable */ + uint32_t bBidirectionModeEn : 1; /*!< Bidirectional mode output enable */ + uint32_t bPinAsOuput : 1; /*!< enables bidirectional pin configurations */ + uint32_t bStopInWaitMode : 1; /*!< SPI stop in wait mode */ + uint32_t bRsvd : 19; +} SPI_SettingType; +/*! @} End of spi_setting_type */ + +/****************************************************************************** +* +*//*! @addtogroup spi_config_type +* @{ +*******************************************************************************/ +/*! + * @brief SPI configuration type. + * + */ +typedef struct +{ + SPI_SettingType sSettings; /*!< SPI settings */ + uint32_t u32BitRate; /*!< set baud rate */ + uint32_t u32BusClkHz; /*!< input bus clock */ +} SPI_ConfigType; /*!< SPI configuration structure */ +/*! @} End of spi_config_type */ + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* inline function +******************************************************************************/ +/****************************************************************************** +* +*//*! @addtogroup spi_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief LSB first (shifter direction). + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + + __STATIC_INLINE void SPI_SetLSBFirst(SPI_Type *pSPI) +{ + pSPI->C1 |= SPI_C1_LSBFE_MASK; +} +/*****************************************************************************//*! + * + * @brief MSB first (shifter direction). + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + + __STATIC_INLINE void SPI_SetMSBFirst(SPI_Type *pSPI) +{ + pSPI->C1 &= ~SPI_C1_LSBFE_MASK; +} +/*****************************************************************************//*! + * + * @brief set SPI clock polarity. + * + * @param[in] pSPI point to SPI module type. + * @param[in] u8PolLow set clock polarity, 1 - Active-low SPI clock (idles high). + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + + __STATIC_INLINE void SPI_SetClockPol(SPI_Type *pSPI,uint8_t u8PolLow) +{ + if( u8PolLow ) + { + pSPI->C1 |= SPI_C1_CPOL_MASK; + } + else + { + pSPI->C1 &= ~SPI_C1_CPOL_MASK; + } +} +/*****************************************************************************//*! + * + * @brief set SPI clock phase. + * + * @param[in] pSPI point to SPI module type. + * @param[in] u8Phase set clock phase, 1 - First edge on SPSCK occurs at the start of the first cycle of a data transfer. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + + __STATIC_INLINE void SPI_SetClockPhase(SPI_Type *pSPI,uint8_t u8Phase) +{ + if( u8Phase ) + { + pSPI->C1 |= SPI_C1_CPHA_MASK; + } + else + { + pSPI->C1 &= ~SPI_C1_CPHA_MASK; + } +} +/*****************************************************************************//*! + * + * @brief enable SPI module. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + + __STATIC_INLINE void SPI_Enable(SPI_Type *pSPI) +{ + pSPI->C1 |= SPI_C1_SPE_MASK; +} +/*****************************************************************************//*! + * + * @brief disable SPI module. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + + __STATIC_INLINE void SPI_Disable(SPI_Type *pSPI) +{ + pSPI->C1 &= ~SPI_C1_SPE_MASK; +} +/*****************************************************************************//*! + * + * @brief enable SPI interrupt. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + + __STATIC_INLINE void SPI_IntEnable(SPI_Type *pSPI) +{ + pSPI->C1 |= SPI_C1_SPIE_MASK; +} +/*****************************************************************************//*! + * + * @brief disable SPI interrupt. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_IntDisable(SPI_Type *pSPI) +{ + pSPI->C1 &= ~SPI_C1_SPIE_MASK; +} +/*****************************************************************************//*! + * + * @brief set SPI to master mode. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_SetMasterMode(SPI_Type *pSPI) +{ + pSPI->C1 |= SPI_C1_MSTR_MASK; +} +/*****************************************************************************//*! + * + * @brief set SPI to slave mode. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_SetSlaveMode(SPI_Type *pSPI) +{ + pSPI->C1 &= ~SPI_C1_MSTR_MASK; +} +/*****************************************************************************//*! + * + * @brief SPI transmit interrupt enable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_TxIntEnable(SPI_Type *pSPI) +{ + pSPI->C1 |= SPI_C1_SPTIE_MASK; +} +/*****************************************************************************//*! + * + * @brief SPI transmit interrupt disable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_TxIntDisable(SPI_Type *pSPI) +{ + pSPI->C1 &= ~SPI_C1_SPTIE_MASK; +} +/*****************************************************************************//*! + * + * @brief Slave select output enable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_SSOutputEnable(SPI_Type *pSPI ) +{ + pSPI->C1 |= SPI_C1_SSOE_MASK; +} +/*****************************************************************************//*! + * + * @brief Slave select output disable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_SSOutputDisable(SPI_Type *pSPI ) +{ + pSPI->C1 &= ~SPI_C1_SSOE_MASK; +} +/*****************************************************************************//*! + * + * @brief SPI match interrupt enable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_MatchIntEnable(SPI_Type *pSPI ) +{ + pSPI->C2 |= SPI_C2_SPMIE_MASK; +} +/*****************************************************************************//*! + * + * @brief SPI match interrupt disable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_MatchIntDisable(SPI_Type *pSPI ) +{ + pSPI->C2 &= ~SPI_C2_SPMIE_MASK; +} +/*****************************************************************************//*! + * + * @brief Master mode-fault function disable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_ModfDisable(SPI_Type *pSPI ) +{ + pSPI->C2 &= ~SPI_C2_MODFEN_MASK; +} +/*****************************************************************************//*! + + * + * @brief Master mode-fault function enable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_ModfEnable(SPI_Type *pSPI ) +{ + pSPI->C2 |= SPI_C2_MODFEN_MASK; +} +/*****************************************************************************//*! + * + * @brief Bidirectional mode output enable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_BidirOutEnable(SPI_Type *pSPI ) +{ + pSPI->C2 |= SPI_C2_BIDIROE_MASK; +} +/*****************************************************************************//*! + * + * @brief Bidirectional mode output disable. + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_BidirOutDisable(SPI_Type *pSPI ) +{ + pSPI->C2 &= ~SPI_C2_BIDIROE_MASK; +} +/*****************************************************************************//*! + * + * @brief SPI stop in wait mode + * + * @param[in] pSPI point to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE void SPI_ClockStopDisable(SPI_Type *pSPI ) +{ + pSPI->C2 &= ~SPI_C2_SPISWAI_MASK; +} +/*****************************************************************************//*! + * + * @brief SPI stop in wait mode. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_ClockStopEnable(SPI_Type *pSPI ) +{ + pSPI->C2 |= SPI_C2_SPISWAI_MASK; +} +/*****************************************************************************//*! + * + * @brief enables bidirectional pin configurations. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_BidirPinEnable(SPI_Type *pSPI) +{ + pSPI->C2 |= SPI_C2_SPC0_MASK; +} +/*****************************************************************************//*! + * + * @brief enables bidirectional pin configurations. + * + * @param[in] pSPI point to SPI module type. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_BidirPinDisable(SPI_Type *pSPI) +{ + pSPI->C2 &= ~SPI_C2_SPC0_MASK; +} +/*****************************************************************************//*! + * + * @brief check SPI read buffer full flag. + * + * @param[in] pSPI point to SPI module type. + * + * @return TRUE or FALSE. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE uint8_t SPI_IsSPRF(SPI_Type *pSPI ) +{ + return(pSPI->S & SPI_S_SPRF_MASK); +} +/*****************************************************************************//*! + * + * @brief check SPI match flag. + * + * @param[in] pSPI point to SPI module type. + * + * @return TRUE or FALSE. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + __STATIC_INLINE uint8_t SPI_IsSPMF(SPI_Type *pSPI ) +{ + return(pSPI->S & SPI_S_SPMF_MASK); +} +/*****************************************************************************//*! + * + * @brief check SPI transmit buffer empty flag. + * + * @param[in] pSPI point to SPI module type. + * + * @return TRUE or FALSE. + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE uint8_t SPI_IsSPTEF(SPI_Type *pSPI ) +{ + return(pSPI->S & SPI_S_SPTEF_MASK); +} +/*****************************************************************************//*! + * + * @brief check master mode fault flag. + * + * @param[in] pSPI point to SPI module type. + * + * @return TRUE or FALSE. + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE uint8_t SPI_IsMODF(SPI_Type *pSPI ) +{ + return(pSPI->S & SPI_S_MODF_MASK); +} +/*****************************************************************************//*! + * + * @brief read SPI data register. + * + * @param[in] pSPI point to SPI module type. + * + * @return data register value + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE uint8_t SPI_ReadDataReg(SPI_Type *pSPI ) +{ + return pSPI->D; +} +/*****************************************************************************//*! + * + * @brief write SPI data register. + * + * @param[in] pSPI point to SPI module type. + * @param[in] u8WrBuff data buffer write to spi data register. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_WriteDataReg(SPI_Type *pSPI, uint8_t u8WrBuff ) +{ + pSPI->D = u8WrBuff; +} +/*****************************************************************************//*! + * + * @brief write SPI match register. + * + * @param[in] pSPI point to SPI module type. + * @param[in] u8WrBuff the data buffer write to match register. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + __STATIC_INLINE void SPI_WriteMatchValue(SPI_Type *pSPI, uint8_t u8WrBuff ) +{ + pSPI->M = u8WrBuff; +} +/****************************************************************************** +* Global functions +******************************************************************************/ +void SPI_Enable(SPI_Type *pSPI); +void SPI_Disable(SPI_Type *pSPI); +void SPI_SetLSBFirst(SPI_Type *pSPI); +void SPI_SetMSBFirst(SPI_Type *pSPI); +void SPI_IntEnable(SPI_Type *pSPI); +void SPI_IntDisable(SPI_Type *pSPI); +void SPI_SetMasterMode(SPI_Type *pSPI); +void SPI_SetSlaveMode(SPI_Type *pSPI); +void SPI_TxIntEnable(SPI_Type *pSPI); +void SPI_TxIntDisable(SPI_Type *pSPI); +void SPI_SSOutputEnable(SPI_Type *pSPI ); +void SPI_SSOutputDisable(SPI_Type *pSPI ); +void SPI_MatchIntEnable(SPI_Type *pSPI ); +void SPI_MatchIntDisable(SPI_Type *pSPI ); +void SPI_ModfDisable(SPI_Type *pSPI ); +void SPI_ModfEnable(SPI_Type *pSPI ); +void SPI_BidirOutEnable(SPI_Type *pSPI ); +void SPI_BidirOutDisable(SPI_Type *pSPI ); +void SPI_ClockStopDisable(SPI_Type *pSPI ); +void SPI_ClockStopEnable(SPI_Type *pSPI ); +void SPI_BidirPinEnable(SPI_Type *pSPI ); +void SPI_BidirPinDisable(SPI_Type *pSPI ); +void SPI_SetClockPol(SPI_Type *pSPI,uint8_t u8PolLow); +void SPI_SetClockPhase(SPI_Type *pSPI,uint8_t u8Phase); +void SPI_SetBaudRate(SPI_Type *pSPI,uint32_t u32BusClock,uint32_t u32Bps ); +uint8_t SPI_IsSPRF(SPI_Type *pSPI ); +uint8_t SPI_IsSPMF(SPI_Type *pSPI ); +uint8_t SPI_IsSPTEF(SPI_Type *pSPI ); +uint8_t SPI_IsMODF(SPI_Type *pSPI ); +uint8_t SPI_ReadDataReg(SPI_Type *pSPI ); +void SPI_WriteDataReg(SPI_Type *pSPI, uint8_t u8WrBuff ); +void SPI_WriteMatchValue(SPI_Type *pSPI, uint8_t u8WrBuff ); +void SPI_Init(SPI_Type *pSPI, SPI_ConfigType *pConfig); +void SPI_DeInit(SPI_Type *pSPI); +ResultType SPI_TransferWait(SPI_Type *pSPI, SPI_WidthType* pRdBuff, SPI_WidthType *pWrBuff,uint32 uiLength); +void SPI_SetCallback(SPI_Type *pSPI,SPI_CallbackType pfnCallback); + +/*! @} End of spi_api_list */ +#ifdef __cplusplus +} +#endif +#endif /* SPI_H_ */ diff --git a/bsp/nv32f100x/lib/inc/uart.h b/bsp/nv32f100x/lib/inc/uart.h new file mode 100644 index 0000000000000000000000000000000000000000..20354933d857b3dde1bcfa1293ff9f086fd67f37 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/uart.h @@ -0,0 +1,496 @@ +/****************************************************************************** +* +* @brief provide commond UART utilities. +* +*******************************************************************************/ +#ifndef _UART_H_ +#define _UART_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/****************************************************************************** +* Includes +******************************************************************************/ +#include "common.h" +#include "wdog.h" +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ +#define MAX_UART_NO 3 + +/****************************************************************************** +* Types +******************************************************************************/ + +/****************************************************************************** +*define uart setting type +* +*//*! @addtogroup uart_setting_type +* @{ +*******************************************************************************/ + +/*! +* @brief UART setting type. +* +*/ + +typedef struct +{ + uint32_t bEnable : 1; /*!< 1: enable, 0: disable */ + uint32_t resvd : 31; /*!< 1: reserved bit field */ +} UART_SettingType; +/*! @} End of uart_setting_type */ + +/****************************************************************************** +*define uart config type +* +*//*! @addtogroup uart_config_type +* @{ +******************************************************************************/ + /*! + * @brief UART Configuration structure. + * + */ +typedef struct +{ + UART_SettingType sSettings; /*!< UART settings */ + uint32_t u32SysClkHz; /*!< system clock */ + uint32_t u32Baudrate; /*!< UART baudrate */ +} UART_ConfigType; +/*! @} End of uart_config_type */ + +/****************************************************************************** +*define uart config baudrate type +* +*//*! @addtogroup uart_config_baudrate_type +* @{ +******************************************************************************/ + /*! + * @brief UART baudrate type structure. + * + */ +typedef struct +{ + uint32_t u32SysClkHz; /*!< system clock */ + uint32_t u32Baudrate; /*!< UART baudrate */ +} UART_ConfigBaudrateType; +/*! @} End of uart_config_baudrate_type */ + +/****************************************************************************** +*define uart config mode type list +* +*//*! @addtogroup uart_mode_type_list +* @{ +******************************************************************************/ +typedef enum +{ + UART_Mode8Bit, /*!< 8 bit mode */ + UART_Mode9Bit, /*!< 9 bit mode */ + UART_ModeEnableLoopback, /*!< enable looback mode */ + UART_ModeDisableLoopback, /*!< disable loopback mode*/ + UART_ModeEnableSingleWire, /*!< enable single wire mode */ + UART_ModeDisableSingleWire, /*!< disable single wire mode */ +} UART_ModeType; +/*! @} End of uart_mode_type_list */ + +/****************************************************************************** +*define uart interrupt type list +* +*//*! @addtogroup uart_interrupt_type_list +* @{ +******************************************************************************/ + +typedef enum +{ + UART_TxBuffEmptyInt, /*!< transmit buffer empty interrupt */ + UART_TxCompleteInt, /*!< transmit complete interrupt */ + UART_RxBuffFullInt, /*!< receive buffer full interrupt */ + + UART_IdleLineInt, /*!< idle line interrupt */ + + UART_RxOverrunInt, /*!< receive overrun interrupt */ + UART_NoiseErrorInt, /*!< noise error interrupt */ + UART_FramingErrorInt, /*!< framing error interrupt */ + UART_ParityErrorInt, /*!< parity error interrupt */ +} UART_InterruptType; +/*! @} End of uart_interrupt_type_list */ + +/****************************************************************************** +*define uart flag type list +* +*//*! @addtogroup uart_flag_type_list +* @{ +******************************************************************************/ +typedef enum +{ + UART_FlagPF = 0, /*!< Parity error flag */ + UART_FlagFE, /*!< Framing error flag */ + UART_FlagNF, /*!< Noise flag */ + UART_FlagOR, /*!< Receive overrun */ + UART_FlagIDLE, /*!< Idle line flag */ + UART_FlagRDRF, /*!< Receive data register full flag */ + UART_FlagTC, /*!< Transmission complete flag */ + UART_FlagTDRE, /*!< Transmit data register flag */ + + UART_FlagRAF, /*!< Receiver active flag */ + UART_FlagLBKDE, /*!< LIN break detection enable */ + UART_FlagBRK13, /*!< Break character generation length */ + UART_FlagRWUID, /*!< Receive wake up idle detect */ + UART_FlagRXINV, /*!< Receive data inversion */ + UART_FlagRev1, /*!< Reserved */ + UART_FlagRXEDGIF, /*!< RxD pin active edge interrupt flag */ + UART_FlagLBKDIF, /*!< LIN break detect interrupt flag */ +} UART_FlagType; +/*! @} End of uart_flag_type_list */ + +/* callback types */ +typedef void (*UART_CallbackType)(UART_Type *pUART); + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Inline functions +******************************************************************************/ + +/****************************************************************************** +* define UART APIs +* +*//*! @addtogroup uart_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief read receive buffer +* +* @param[in] pUART base of UART port +* +* @return unsign char received char +* +*****************************************************************************/ +__STATIC_INLINE uint8_t UART_ReadDataReg(UART_Type *pUART) +{ + /* Return the 8-bit data from the receiver */ + return pUART->D; +} +/*****************************************************************************//*! +* +* @brief write transmit buffer +* +* @param[in] pUART base of UART port +* @param[in] u8Char char to send +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_WriteDataReg(UART_Type *pUART, uint8_t u8Char) +{ + /* Send the character */ + pUART->D = (uint8_t)u8Char; +} + +/*****************************************************************************//*! +* +* @brief check if a character has been received +* +* @param[in] pUART base of UART port +* +* @return 0, No character received; no-zero, Character has been received +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE uint8_t UART_CharPresent(UART_Type *pUART) +{ + return (pUART->S1 & UART_S1_RDRF_MASK); +} +/*****************************************************************************//*! +* +* @brief enable transmit +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_EnableTx(UART_Type *pUART) +{ + + pUART->C2 |= UART_C2_TE_MASK; +} +/*****************************************************************************//*! +* +* @brief disable transmit +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_DisableTx(UART_Type *pUART) +{ + pUART->C2 &= (~UART_C2_TE_MASK); +} +/*****************************************************************************//*! +* +* @brief enable receive +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_EnableRx(UART_Type *pUART) +{ + pUART->C2 |= UART_C2_RE_MASK; +} +/*****************************************************************************//*! +* +* @brief disable receive +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_DisableRx(UART_Type *pUART) +{ + pUART->C2 &= (~UART_C2_RE_MASK); +} +/*****************************************************************************//*! +* +* @brief Enable loopback mode +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_EnableLoopback(UART_Type *pUART) +{ + pUART->C1 |= UART_C1_LOOPS_MASK; + pUART->C1 &= (~UART_C1_RSRC_MASK); +} +/*****************************************************************************//*! +* +* @brief enable single wire mode +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_EnableSingleWire(UART_Type *pUART) +{ + pUART->C1 |= UART_C1_LOOPS_MASK; + pUART->C1 |= UART_C1_RSRC_MASK; +} +/*****************************************************************************//*! +* +* @brief set 8-bit mode +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_Set8BitMode(UART_Type *pUART) +{ + pUART->C1 &= (~UART_C1_M_MASK); +} +/*****************************************************************************//*! +* +* @brief set 9-bit mode +* +* @param[in] pUART base of UART port +* +* @return none +* +*****************************************************************************/ +__STATIC_INLINE void UART_Set9BitMode(UART_Type *pUART) +{ + pUART->C1 |= UART_C1_M_MASK; +} +/*****************************************************************************//*! +* +* @brief enable transmit buffer empty interrupt +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_EnableTxBuffEmptyInt(UART_Type *pUART) +{ + pUART->C2 |= UART_C2_TIE_MASK; +} +/*****************************************************************************//*! +* +* @brief enable transmit complete interrupt +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_EnableTxCompleteInt(UART_Type *pUART) +{ + pUART->C2 |= UART_C2_TCIE_MASK; +} +/*****************************************************************************//*! +* +* @brief enable receive buffer full interrupt +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_EnableRxBuffFullInt(UART_Type *pUART) +{ + pUART->C2 |= UART_C2_RIE_MASK; +} +/*****************************************************************************//*! +* +* @brief disable transmit buffer empty interrupt +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_DisableTxBuffEmptyInt(UART_Type *pUART) +{ + pUART->C2 &= (~UART_C2_TIE_MASK); +} +/*****************************************************************************//*! +* +* @brief disable transmit complete interrupt +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_DisableTxCompleteInt(UART_Type *pUART) +{ + pUART->C2 &= (~UART_C2_TCIE_MASK); +} +/*****************************************************************************//*! +* +* @brief disable receive buffer full interrupt +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_DisableRxBuffFullInt(UART_Type *pUART) +{ + pUART->C2 &= (~UART_C2_RIE_MASK); +} +/*****************************************************************************//*! +* +* @brief print out break character +* +* @param[in] pUART base of UART port +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +__STATIC_INLINE void UART_PutBreak(UART_Type *pUART) +{ + /* Write 1 then write 0 to UART_C2[SBK] bit, will put break character */ + pUART->C2 |= UART_C2_SBK_MASK; + pUART->C2 &= (~UART_C2_SBK_MASK); +} + +/*****************************************************************************//*! +* +* @brief check whether tx is complete,i.e. data has been sent out. +* +* @param[in] pUART base of UART port +* +* @return +* 1, Tx complete flag is set +* 0, Tx complete flag is clear +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t UART_IsTxComplete(UART_Type *pUART) +{ + return (pUART->S1 & UART_S1_TC_MASK); +} +/*****************************************************************************//*! +* +* @brief check whether Tx buffer is empty +* +* @param[in] pUART base of UART port +* +* @return +* 1, Tx buffer is empty +* 0, Tx buffer is not empty +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t UART_IsTxBuffEmpty(UART_Type *pUART) +{ + return (pUART->S1 & UART_S1_TDRE_MASK); +} +/*****************************************************************************//*! +* +* @brief check whether Rx buffer is full, i.e. receive a character +* +* @param[in] pUART base of UART port +* +* @return +* 1, Rx buffer is full +* 0, Rx buffer is not full +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +__STATIC_INLINE uint8_t UART_IsRxBuffFull(UART_Type *pUART) +{ + return (pUART->S1 & UART_S1_RDRF_MASK); +} +/*! @} End of uart_api_list */ + + +/****************************************************************************** +* Global functions declaration +******************************************************************************/ +void UART_Init(UART_Type *pUART, UART_ConfigType *pConfig); +uint8_t UART_GetChar(UART_Type *pUART); +void UART_PutChar(UART_Type *pUART, uint8_t u8Char); +void UART_SetBaudrate(UART_Type *pUART, UART_ConfigBaudrateType *pConfig); +void UART_EnableInterrupt(UART_Type *pUART, UART_InterruptType InterruptType); +void UART_DisableInterrupt(UART_Type *pUART, UART_InterruptType InterruptType); +uint16_t UART_GetFlags(UART_Type *pUART); +uint8_t UART_CheckFlag(UART_Type *pUART, UART_FlagType FlagType); +void UART_SendWait(UART_Type *pUART, uint8_t *pSendBuff, uint32_t u32Length); +void UART_ReceiveWait(UART_Type *pUART, uint8_t *pReceiveBuff, uint32_t u32Length); +void UART_WaitTxComplete(UART_Type *pUART); +void UART_SetCallback(UART_CallbackType pfnCallback); +void UART0_Isr(void); +void UART1_Isr(void); +void UART2_Isr(void); + + +#ifdef __cplusplus +} +#endif +#endif /* #ifndef _UART_H_ */ diff --git a/bsp/nv32f100x/lib/inc/wdog.h b/bsp/nv32f100x/lib/inc/wdog.h new file mode 100644 index 0000000000000000000000000000000000000000..75b79ca417e825283f354d9a7d38a92a0ee84362 --- /dev/null +++ b/bsp/nv32f100x/lib/inc/wdog.h @@ -0,0 +1,203 @@ + +/****************************************************************************** +* @brief provide commond watch dog utilities. +* +******************************************************************************* +* +* provide APIs for accessing watch dog +******************************************************************************/ + +#ifndef __WDOG_H__ +#define __WDOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +/****************************************************************************** +* Includes +******************************************************************************/ +#include "sim.h" + +/****************************************************************************** +* Constants +******************************************************************************/ + +/****************************************************************************** +* Macros +******************************************************************************/ +/* wdog_unlock sequence must be performed within 16 bus clock cycles without + * any interrupt + */ + + +/* WDOG clock sources option */ +/****************************************************************************** +* define watchdog clock source selection +* +*//*! @addtogroup wdog_clock_sources +* @{ +*******************************************************************************/ + +#define WDOG_CLK_BUS 0 /*!< clock source is bus clock */ +#define WDOG_CLK_INTERNAL_32KHZ 2 /*!< clock source is internal oscillator 32 kHz (ICSIRCLK) */ +#define WDOG_CLK_INTERNAL_1KHZ 1 /*!< clock source is internal LPO 1 KHz */ +#define WDOG_CLK_EXTERNAL 3 /*!< clock source is external clock */ +/*! @} End of wdog_clock_sources */ + +/* WDOG clock source selection */ +#define WDOG_CLK (WDOG_CLK_INTERNAL_1KHZ) + +/* WDOG default values */ +#define WDOG_CS1_DEFAULT_VALUE 0x80 +#define WDOG_CS2_DEFAULT_VALUE 0x01 +#define WDOG_TOVAL_DEFAULT_VALUE 0x0400 +#define WDOG_WIN_DEFAULT_VALUE 0x0000 + +/* WDOG utilities */ + +/****************************************************************************** +* define watchdog API list +* +*//*! @addtogroup wdog_api_list +* @{ +*******************************************************************************/ +/*! + * @brief watchdog unlock routine. + */ +#define WDOG_Unlock() WDOG->CNT = 0x20C5; WDOG->CNT = 0x28D9 +//#define WDOG_Unlock() DisableInterrupts; WDOG->CNT = 0x20C5; WDOG->CNT = 0x28D9; EnableInterrupts +/*! @} End of wdog_api_list */ + +/****************************************************************************** +* Types +******************************************************************************/ + +/****************************************************************************** +* define watchdog configuration structure +* +*//*! @addtogroup wdog_config_type +* @{ +*******************************************************************************/ + +/*! + * @brief watchdog configuration structure. + * + */ +typedef struct { + struct { + uint16_t bIntEnable : 1; /*!< watchdog interrupt enable */ + uint16_t bDisable : 1; /*!< disable watchdog */ + uint16_t bWaitEnable : 1; /*!< enable watchdog in wait mode */ + uint16_t bStopEnable : 1; /*!< enable watchdog in stop mode */ + uint16_t bDbgEnable : 1; /*!< enable watchdog in debug mode */ + uint16_t bWinEnable : 1; /*!< enable watchdog window mode */ + uint16_t bUpdateEnable : 1; /*!< enable update of watchdog control */ + uint16_t bClkSrc : 2; /*!< watchdog clock source selection */ + uint16_t bPrescaler : 1; /*!< prescaler */ + }sBits; /*!< bitfield structure */ + uint16_t u16ETMeOut; /*!< watchdog ETMeout value */ + uint16_t u16WinETMe; /*!< watchdog window value */ +} WDOG_ConfigType, *WDOG_ConfigPtr; /*!< watchdog configuration structure type */ +/*! @} End of wdog_config_type */ + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define watchdog API list +* +*//*! @addtogroup wdog_api_list +* @{ +*******************************************************************************/ + + +/*****************************************************************************//*! +* +* @brief set ETMe out value for WDOG. +* +* @param[in] u16ETMeOut ETMeout value to TOVAL register. +* +* @return none +* +* @ Pass/ Fail criteria: none +* +*****************************************************************************/ + +__STATIC_INLINE void WDOG_SetETMeOut(uint16_t u16ETMeOut) +{ + WDOG->CNT = 0x20C5; + WDOG->CNT = 0x28D9; + WDOG->TOVAL8B.TOVALL = u16ETMeOut; + WDOG->TOVAL8B.TOVALH = u16ETMeOut >> 8; +} + + +/*****************************************************************************//*! +* +* @brief set window value for WDOG. +* +* @param[in] u16WinETMe window value to WIN register. +* +* @return none +* +* @ Pass/ Fail criteria: none +* +*****************************************************************************/ + +__STATIC_INLINE void WDOG_SetWindow(uint16_t u16WinETMe) +{ + WDOG->CNT = 0x20C5; + WDOG->CNT = 0x28D9; + WDOG->WIN8B.WINL = u16WinETMe; + WDOG->WIN8B.WINH = u16WinETMe >> 8; +} + +/*****************************************************************************//*! +* +* @brief check if watchdog reset occurs. +* +* @param none. +* +* @return TRUE if watchdog reset occurs, FALSE otherwise. +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +__STATIC_INLINE uint8_t WDOG_IsReset(void) +{ + if(SIM_GetStatus(SIM_SRSID_WDOG_MASK)) + { + return (TRUE); + } + return (FALSE); +} + +/*! @} End of wdog_api_list */ + + +void WDOG_Init(WDOG_ConfigPtr pConfig); +void WDOG_DeInit(void); +void WDOG_Disable(void); +void WDOG_DisableWDOGEnableUpdate(void); +void WDOG_Enable(void); +void WDOG_Feed(void); +void WDOG_SetETMeOut(uint16_t u16ETMeOut); +void WDOG_SetWindow(uint16_t u16WinETMe); +void WDOG_EnableUpdate(void); +void WDOG_DisableUpdate(void); +uint8_t WDOG_IsReset(void); + +#ifdef __cplusplus +} +#endif + +/********************************************************************/ +#endif /* __WDOG_H__ */ + diff --git a/bsp/nv32f100x/lib/src/acmp.c b/bsp/nv32f100x/lib/src/acmp.c new file mode 100644 index 0000000000000000000000000000000000000000..5739f767bb6ce05467a434f74a84b48ef82c9e81 --- /dev/null +++ b/bsp/nv32f100x/lib/src/acmp.c @@ -0,0 +1,215 @@ + +/****************************************************************************** +* +* @brief providing APIs for configuring ACMP. +* +******************************************************************************* +* +* provide APIs for configuring ACMP +******************************************************************************/ +#include "common.h" +#include "acmp.h" +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +ACMP_CallbackPtr ACMP_Callback[2] = {(ACMP_CallbackPtr)NULL}; + +/****************************************************************************** +* Local functions +******************************************************************************/ +/****************************************************************************** +* Global functions +******************************************************************************/ +void ACMP0_Isr(void); +void ACMP1_Isr(void); + +/****************************************************************************** +* ACMP api list. +* +*//*! @addtogroup acmp_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief initialize ACMP as per control field. +* +* @param pACMPx pointer to an ACMP register base. +* @param pConfig control parameters. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_DeInit. +* +*****************************************************************************/ +void ACMP_Init(ACMP_Type *pACMPx, ACMP_ConfigType *pConfig) +{ + if(ACMP0 == pACMPx) + { + /* enable clock to ACMP */ + SIM->SCGC |= SIM_SCGC_ACMP0_MASK; + + /* enable ACMP interrupt */ + if(pConfig->sCtrlStatus.bits.bIntEn) + NVIC_EnableIRQ(ACMP0_IRQn); + } + else + { + SIM->SCGC |= SIM_SCGC_ACMP1_MASK; + if(pConfig->sCtrlStatus.bits.bIntEn) + NVIC_EnableIRQ(ACMP1_IRQn); + } + /* neg and pos pin are not equal */ + pACMPx->C0 = pConfig->sPinSelect.byte; + ACMP_ConfigDAC(pACMPx, &pConfig->sDacSet ); + //pACMPx->C1 = pConfig->sDacSet.byte; + pACMPx->C2 = pConfig->sPinEnable.byte; + pACMPx->CS = pConfig->sCtrlStatus.byte; +} + + +/*****************************************************************************//*! +* +* @brief write ACMP register bits. +* +* @param pACMPx pointer to an ACMP register base. +* @param pDACConfig pointer to an ACMP DAC control structure. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +void ACMP_ConfigDAC(ACMP_Type *pACMPx, ACMP_DACType *pDACConfig) +{ + pACMPx->C1 = pDACConfig->byte; +} + +/*****************************************************************************//*! +* +* @brief deinit ACMP module. +* +* @param pACMPx pointer to an ACMP register base. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see ACMP_Init. +* +*****************************************************************************/ +void ACMP_DeInit(ACMP_Type *pACMPx) +{ + if(ACMP0 == pACMPx) + { + if(pACMPx->CS & ACMP_CS_ACIE_MASK) + NVIC_DisableIRQ(ACMP0_IRQn); + } + else + { + if(pACMPx->CS & ACMP_CS_ACIE_MASK) + NVIC_DisableIRQ(ACMP1_IRQn); + } + + pACMPx->CS = 0; + pACMPx->C0 = 0; + pACMPx->C1 = 0; + pACMPx->C2 = 0; + + if(ACMP0 == pACMPx) + { + SIM->SCGC &= ~SIM_SCGC_ACMP0_MASK; + } + else + { + SIM->SCGC &= ~SIM_SCGC_ACMP1_MASK; + } +} + +/*****************************************************************************//*! +* +* @brief set up ACMP callback routines to be called by interrupt service routine. +* +* @param pACMPx pointer to an ACMP register base. +* @param pfnCallback callback routine. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +void ACMP_SetCallback(ACMP_Type *pACMPx, ACMP_CallbackPtr pfnCallback) +{ + if(ACMP0 == pACMPx) + { + ACMP_Callback[0] = pfnCallback; + } + else + { + ACMP_Callback[1] = pfnCallback; + } +} + +/*! @} End of acmp_api_list */ + + +/*****************************************************************************//*! +* +* @brief ACMP0 interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +void ACMP0_Isr(void) +{ + + if(ACMP_Callback[0]) + { + ACMP_Callback[0](); /* call callback routine */ + } +} + +/*****************************************************************************//*! +* +* @brief ACMP1 interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +void ACMP1_Isr(void) +{ + + if(ACMP_Callback[1]) + { + ACMP_Callback[1](); /* call callback routine */ + } +} + + diff --git a/bsp/nv32f100x/lib/src/adc.c b/bsp/nv32f100x/lib/src/adc.c new file mode 100644 index 0000000000000000000000000000000000000000..b9ec2ff151484c082bee1d7366c2754b836ec5fa --- /dev/null +++ b/bsp/nv32f100x/lib/src/adc.c @@ -0,0 +1,336 @@ +/****************************************************************************** +* @brief providing APIs for configuring ADC module (ADC). +* +******************************************************************************* +* +* provide APIs for configuring ADC module (ADC) +******************************************************************************/ +#include "common.h" +#include "adc.h" +/****************************************************************************** +* Local function +******************************************************************************/ +ADC_CallbackType ADC_Callback[1] = {NULL}; +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* define ADC APIs +* +*//*! @addtogroup adc_api_list +* @{ +*******************************************************************************/ + + +/*****************************************************************************//** + * + * @brief initialize ADC module. + * + * @param[in] pADC point to ADC module type. + * @param[in] pADC_Config point to ADC configuration structure. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_Init(ADC_Type *pADC, ADC_ConfigTypePtr pADC_Config) +{ + if( pADC == ADC) + { + SIM->SCGC |= SIM_SCGC_ADC_MASK; + } + + /* set clock cource for ADC */ + ADC_SelectClock(pADC,pADC_Config->u8ClockSource); + + /* set clock divide */ + ADC_SelectClockDivide(pADC,pADC_Config->u8ClockDiv); + + /* set ADC mode */ + ADC_SetMode(pADC,pADC_Config->u8Mode); + + /* set FIFO level */ + ADC_SetFifoLevel(pADC,pADC_Config->u8FiFoLevel); + + /* set pin control */ + pADC->APCTL1 = pADC_Config->u16PinControl; + + if( pADC_Config->sSetting.bCompareEn ) + { + ADC_CompareEnable(pADC); + } + + if( pADC_Config->sSetting.bCompareGreaterEn ) + { + ADC_CompareGreaterFunction(pADC); + } + + if( pADC_Config->sSetting.bContinuousEn ) + { + ADC_ContinuousConversion(pADC); + } + + if( pADC_Config->sSetting.bCompareAndEn ) + { + ADC_CompareFifoAnd(pADC); + } + + if( pADC_Config->sSetting.bFiFoScanModeEn ) + { + ADC_FifoScanModeEnable(pADC); + } + + if( pADC_Config->sSetting.bHardwareTriggerEn ) + { + ADC_SetHardwareTrigger(pADC); + } + + if( pADC_Config->sSetting.bIntEn ) + { + ADC_IntEnable(pADC); + NVIC_EnableIRQ( ADC0_IRQn ); + } + + if( pADC_Config->sSetting.bLongSampleEn ) + { + ADC_SetLongSample(pADC); + } + + if( pADC_Config->sSetting.bLowPowerEn ) + { + ADC_SetLowPower(pADC); + } + +#if !defined(CPU_NV32) + + if( pADC_Config->sSetting.bHTRGMEn ) + { + ADC_HardwareTriggerMultiple(pADC); + } + else + { + ADC_HardwareTriggerSingle(pADC); + } + if( pADC_Config->sSetting.bHTRGMASKEn ) + { + ADC_HardwareTriggerMaskEnable(pADC); + } + else + { + ADC_HardwareTriggerMaskDisable(pADC); + } + if( pADC_Config->sSetting.bHTRGMASKSEL ) + { + ADC_HardwareTriggerMaskAuto(pADC); + } + else + { + ADC_HardwareTriggerMaskNonAuto(pADC); + } +#endif +} + +/*****************************************************************************//*! + * + * @brief disable ADC module. + * + * @param[in] pADC point to ADC module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +void ADC_DeInit( ADC_Type *pADC ) +{ + ADC_SetChannel(pADC,ADC_CHANNEL_DISABLE); + + SIM->SCGC &= ~SIM_SCGC_ADC_MASK; +} + +/*****************************************************************************//*! + * + * @brief start a conversion and get conversion result + * + * @param[in] pADC point to ADC module type. + * @param[in] u8Channel adc channel to conversion. + * + * @return ADC conversion result. + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +unsigned int ADC_PollRead( ADC_Type *pADC, uint8_t u8Channel ) +{ + ADC_SetChannel(pADC,u8Channel); + while( !ADC_IsCOCOFlag(pADC) ); + return ADC_ReadResultReg(pADC); +} + + +/*****************************************************************************//*! + * + * @brief install ADC call back function. + * + * @param[in] pADC_CallBack point to address of adc call back function. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +void ADC_SetCallBack(ADC_CallbackType pADC_CallBack) +{ + ADC_Callback[0] = pADC_CallBack; +} + +/*****************************************************************************//*! + * + * @brief set ADC channel. + * + * @param[in] pADC point to ADC module type. + * @param[in] u8Channel adc channel to conversion. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_SetChannel( ADC_Type *pADC, uint8_t u8Channel ) +{ + uint32_t u32temp; + u32temp = pADC->SC1; + u32temp &= ~ADC_SC1_ADCH_MASK; + pADC->SC1 = u32temp|ADC_SC1_ADCH(u8Channel); +} +/*****************************************************************************//*! + * + * @brief Voltage Reference Selection. + * + * @param[in] pADC point to ADC module type. + * @param[in] u8Vref adc reference voltage selection. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_VrefSelect( ADC_Type *pADC, uint8_t u8Vref ) +{ + uint32_t u32Temp; + u32Temp = pADC->SC2; + u32Temp &= ~ADC_SC2_REFSEL_MASK; + pADC->SC2 = u32Temp|ADC_SC2_REFSEL(u8Vref); +} + +/*****************************************************************************//*! + * + * @brief select clock divide + * + * @param[in] pADC point to ADC module type. + * @param[in] u8Div Clock Divide Select. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_SelectClockDivide( ADC_Type *pADC, uint8_t u8Div ) +{ + uint32_t u32Temp; + u32Temp = pADC->SC3; + u32Temp &= ~ADC_SC3_ADIV_MASK; + pADC->SC3 = u32Temp|ADC_SC3_ADIV(u8Div); +} + +/*****************************************************************************//*! + * + * @brief set ADC mode. + * + * @param[in] pADC point to ADC module type. + * @param[in] u8Mode Conversion Mode Selection. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_SetMode( ADC_Type *pADC, uint8_t u8Mode ) +{ + uint32_t u32Temp; + u32Temp = pADC->SC3; + u32Temp &= ~ADC_SC3_MODE_MASK; + pADC->SC3 = u32Temp|ADC_SC3_MODE(u8Mode); +} +/*****************************************************************************//*! + * + * @brief Input Clock Select. + * + * @param[in] pADC point to ADC module type. + * @param[in] u8Clock Input Clock Select. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_SelectClock( ADC_Type *pADC, uint8_t u8Clock ) +{ + uint32_t u32Temp; + u32Temp = pADC->SC3; + u32Temp &= ~ADC_SC3_ADICLK_MASK; + pADC->SC3 = u32Temp|ADC_SC3_ADICLK(u8Clock); +} + +/*****************************************************************************//*! + * + * @brief FIFO Depth enables + * + * @param[in] pADC point to ADC module type. + * @param[in] u8FifoLevel set FIFO level. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +void ADC_SetFifoLevel( ADC_Type *pADC, uint8_t u8FifoLevel ) +{ + uint32_t u32Temp; + u32Temp = pADC->SC4; + u32Temp &= ~ADC_SC4_AFDEP_MASK; + pADC->SC4 = u32Temp|ADC_SC4_AFDEP(u8FifoLevel); +} + +/*! @} End of adc_api_list */ + + +/*****************************************************************************//*! + * + * @brief ADC interrupt service routine. + * + * @param none. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +void ADC_Isr(void) +{ +// printf("input any character to start a new conversion!\n"); + if( ADC_Callback[0] ) + { + ADC_Callback[0](); + } +} + + + + + + + + + + + + + + + diff --git a/bsp/nv32f100x/lib/src/arm_cm0.c b/bsp/nv32f100x/lib/src/arm_cm0.c new file mode 100644 index 0000000000000000000000000000000000000000..bc42a7c6cb945bad5c000e9f86509977975b588c --- /dev/null +++ b/bsp/nv32f100x/lib/src/arm_cm0.c @@ -0,0 +1,77 @@ +/****************************************************************************** +* @brief provide generic high-level routines for ARM Cortex M0/M0+ processors. +* +*******************************************************************************/ + +#include "common.h" + +/***********************************************************************/ +/* + * Configures the ARM system control register for STOP (deep sleep) mode + * and then executes the WFI instruction to enter the mode. + * + * Parameters: + * none + * + * Note: Might want to change this later to allow for passing in a parameter + * to optionally set the sleep on exit bit. + */ + +void stop (void) +{ + /* Set the SLEEPDEEP bit to enable deep sleep mode (STOP) */ + SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk; + + /* WFI instruction will start entry into STOP mode */ +#ifndef KEIL + // If not using KEIL's uVision use the standard assembly command + asm("WFI"); +#else + // If using KEIL's uVision, use the CMSIS intrinsic + __wfi(); +#endif +} +/***********************************************************************/ +/* + * Configures the ARM system control register for WAIT (sleep) mode + * and then executes the WFI instruction to enter the mode. + * + * Parameters: + * none + * + * Note: Might want to change this later to allow for passing in a parameter + * to optionally set the sleep on exit bit. + */ + +void wait (void) +{ + /* Clear the SLEEPDEEP bit to make sure we go into WAIT (sleep) mode instead + * of deep sleep. + */ + SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk; + + /* WFI instruction will start entry into WAIT mode */ +#ifndef KEIL + // If not using KEIL's uVision use the standard assembly command + asm("WFI"); +#else + // If using KEIL's uVision, use the CMSIS intrinsic + __wfi(); +#endif +} +/***********************************************************************/ +/* + * Change the value of the vector table offset register to the specified value. + * + * Parameters: + * vtor new value to write to the VTOR + */ + +void write_vtor (int vtor) +{ + /* Write the VTOR with the new value */ + SCB->VTOR = vtor; +} + +/***********************************************************************/ + diff --git a/bsp/nv32f100x/lib/src/crc.c b/bsp/nv32f100x/lib/src/crc.c new file mode 100644 index 0000000000000000000000000000000000000000..7b5766b5b204094a35bf00592a0624ef83318bcb --- /dev/null +++ b/bsp/nv32f100x/lib/src/crc.c @@ -0,0 +1,256 @@ +/****************************************************************************** +* @brief Cyclic redundancy check (CRC) source code. +* +******************************************************************************/ +#include "common.h" +#include "crc.h" + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define CRC APIs +* +*//*! @addtogroup crc_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief initialize CRC with poly per control parameters +* +* @param[in] pConfig point to configuration. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void CRC_Init(CRC_ConfigType *pConfig) +{ + uint32_t u32Sc ; + + u32Sc = 0; + + SIM->SCGC |= SIM_SCGC_CRC_MASK; + + u32Sc |= ((pConfig->bWidth & 0x01)<<24); + u32Sc |= CRC_CTRL_TOTR(pConfig->bTransposeReadType & 0x03); + u32Sc |= CRC_CTRL_TOT(pConfig->bTransposeWriteType & 0x03); + + if (pConfig->bFinalXOR) + { + u32Sc |= CRC_CTRL_FXOR_MASK; + } + + CRC0->CTRL = u32Sc; + + if ( pConfig->bWidth ) + { + CRC0->GPOLY = pConfig->u32PolyData; + } + else + { + CRC0->GPOLY_ACCESS16BIT.GPOLYL = pConfig->u32PolyData; /*!< only 16-bit write allowed */ + } + +} + + +/*****************************************************************************//*! +* +* @brief crc module 16-bit mode calculation. +* +* @param[in] seed +* @param[in] msg poiont to message buffer +* @param[in] sizeBytes size of message +* +* @return data_out convertion result +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint32_t CRC_Cal16(uint32_t seed, uint8_t *msg, uint32_t sizeBytes) +{ + uint32_t ctrl_reg,data_out,data_in; + uint8_t *pCRCBytes; + uint32_t sizeWords; + uint32_t i,j; + + /* Input seed, Set WaS=1 */ + ctrl_reg = CRC0->CTRL; + CRC0->CTRL = ctrl_reg | CRC_CTRL_WAS_MASK; + CRC0->ACCESS16BIT.DATAL = seed; + + /*Input data, Set WaS=0*/ + CRC0->CTRL = ctrl_reg & 0xFD000000; + + /*Wait for calculation completion*/ + sizeWords = sizeBytes>>1; + j = 0; + for(i=0;iACCESS16BIT.DATAL =data_in; + } + if (jACCESS8BIT.DATALL; + *pCRCBytes++ = msg[j]; + } + data_out=CRC0->ACCESS16BIT.DATAL; + + return(data_out); +} + + +/*****************************************************************************//*! +* +* @brief crc module 32-bit mode calculation. +* +* @param[in] seed +* @param[in] msg poiont to message buffer +* @param[in] sizeBytes size of message +* +* @return data_out convertion result +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint32_t CRC_Cal32(uint32_t seed, uint8_t *msg, uint32_t sizeBytes) +{ + uint32_t ctrl_reg,data_out,data_in; + uint32_t sizeDwords; + uint8_t *pCRCBytes; + uint32_t i,j; + + /*Input seed, Set WaS=1*/ + ctrl_reg = CRC0->CTRL; + CRC0->CTRL = ctrl_reg | 0x02000000; + CRC0->DATA = seed; + + /*Input data, Set WaS=0*/ + CRC0->CTRL = ctrl_reg & 0xFD000000; + + /*Wait for calculation completion*/ + sizeDwords = sizeBytes>>2; + j = 0; + for(i=0;iDATA = data_in; + } + if (jACCESS8BIT.DATALL; + +#if defined(BYTE_ENABLES_1_2_4_8) + + /*write single byte*/ + for(;jACCESS16BIT.DATAL = data_in; + } + } + if (i==1) + { + CRC0->ACCESS8BIT.DATALL = data_in; /*!< write last byte */ + } +#elif defined(BYTE_ENABLES_7_E) + /*!< write three bytes */ + data_in = 0; + i = 0; + for(;jACCESS8BIT.DATAHL = (data_in>>16) & 0xff; /*!< write low byte of high word */ + /*write last two chars*/ + CRC0->ACCESS16BIT.DATAL = data_in & 0x00ffff; /*!< write low word */ + } + } + if ( i == 2) + { + CRC0->ACCESS16BIT.DATAL = (data_in); /*!< write last 2 bytes */ + } + else if (i == 1) + { + CRC0->ACCESS8BIT.DATALL = data_in; /*!< write last byte */ + } +#else /*!< write low byte only */ + for(;jDATA; + + return(data_out); +} + + +/*****************************************************************************//*! +* +* @brief de-initialize crc module, reset crc register. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void CRC_DeInit(void) +{ + CRC0->CTRL = 0x3000000; /*!< prepare for write 32-bit seed*/ + CRC0->DATA = 0xFFFFFFFF;/*!< write 32-bit seed to data register*/ + while(!(CRC0->DATA == 0xFFFFFFFF)); + CRC0->GPOLY = 0x00001021; + CRC0->CTRL = 0; /*!< reset ctrl register*/ + SIM->SCGC &= ~SIM_SCGC_CRC_MASK; +} + +/*! @} End of crc_api_list */ + + diff --git a/bsp/nv32f100x/lib/src/eeprom.c b/bsp/nv32f100x/lib/src/eeprom.c new file mode 100644 index 0000000000000000000000000000000000000000..22c0b9196e97e3adf361f8063becc71b4c12b724 --- /dev/null +++ b/bsp/nv32f100x/lib/src/eeprom.c @@ -0,0 +1,345 @@ +#include "flash.h" +#include "eeprom.h" +#include + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ + + +/****************************************************************************** +* +* EEPROM ²Á³ýÃüÁ²Áµôeeprom +*ÊäÈë²ÎÊý£ºµØÖ·£¬º¯Êý½«»á²Á³ýadrËùÔÚµÄ512bytes eeprom +* +******************************************************************************/ +uint16_t Adress_Js(uint32_t adr) +{ + uint16_t err = EEPROM_ERR_SUCCESS; + + + if(adr & 0x03) + { + err = EEPROM_ERR_INVALID_PARAM; + return (err); + } + + if(adr >1024) + { + err=EEPROM_ADR_OverFlow; + return(err); + } + return(err); +} + +/****************************************************************************** +* +* EEPROM ²Á³ýÃüÁ²Áµôeeprom +*ÊäÈë²ÎÊý£ºµØÖ·£¬º¯Êý½«»á²Á³ýadrËùÔÚµÄ512bytes eeprom +* +******************************************************************************/ + + +uint16_t EEPROM_Erase(uint32_t adr) +{ + uint16_t err = EEPROM_ERR_SUCCESS; + uint32_t e_adr; + + if(adr & 0x03) + { + err = EEPROM_ERR_INVALID_PARAM; + return (err); + } + + if(adr >1024) + { + err=EEPROM_ADR_OverFlow; + + return(err); + } + + e_adr=adr+EEPROM_START_ADR; + err = Flash_EraseSector(e_adr); + return(err); +} + +/****************************************************************************** +* +* EEPROM ¶ÁÈ¡º¯Êý£¬¶ÁÈ¡µØÖ·ËùÔÚµÄeeprom +*ÊäÈë²ÎÊý£ºµØÖ· +* +******************************************************************************/ +uint32_t EEPROM_Read(uint32_t adr) +{ + uint16_t err = EEPROM_ERR_SUCCESS; + uint32_t e_adr; + uint32_t data; + + if(adr & 0x03) + { + err = EEPROM_ERR_INVALID_PARAM; + return (err); + } + + if(adr >1024) + { + err=EEPROM_ADR_OverFlow; + return(err); + } + + e_adr=adr+EEPROM_START_ADR; + data = M32(e_adr); + return(data); + +} +/****************************************************************************** +* +* EEPROM дº¯Êý£¬Ð´µØÖ·ËùÔÚµÄeeprom +*д֮ǰ¶ÁÈ¡³öÀ´£¬ÅжÏeepromÊÇ·ñΪ¿Õ£¬Èç¹ûΪ¿Õ£¬ÔòÖ±½Óд +*Èç¹û·Ç¿Õ£¬ÔòÏÈ°ÑÕû¸ö512bytes sector¶ÁÈ¡µ½sram£¬ÐÞ¸ÄҪдµÄλÖà +*È»ºóÔÙдÈëµ½flash£¬Ä£ÄâÒ»¸öeepromµÄд¹ý³Ì +*ÊäÈë²ÎÊý£ºµØÖ· +* +******************************************************************************/ +uint16_t EEPROM_Write(uint32_t adr, uint32_t Data) +{ + + uint32_t err = EEPROM_ERR_SUCCESS; + uint32_t e_adr; + uint32_t r_data; + uint16_t i; + uint32_t start_adr; + // uint32_t modify_adr; + uint32_t EEPROM_DATA[128]; + + if(adr & 0x03) + { + err = EEPROM_ERR_INVALID_PARAM; + return (err); + } + + if(adr >1024) + { + err=EEPROM_ADR_OverFlow; + return(err); + } + + + r_data = EEPROM_Read(adr); + + e_adr=adr+EEPROM_START_ADR; + + if(r_data== EEPROM_BLANK) //Èç¹ûҪдµÄλÖÃÊǿյģ¬ÔòÖ±½Óд + { + err= Flash_Program1LongWord(e_adr,Data); + } + else if((r_data&Data) == Data)//Èç¹ûҪдµÄλÖöÔÓ¦µÄbit£¬ºÍҪдµÄÊý¾ÝÒ»Ö£¬»òÕßÊÇ1£¬Ò²ÊÇ¿ÉÒÔÖ±½Óд + { + err= Flash_Program1LongWord(e_adr,Data); + } + else if(r_data == Data) //Èç¹ûҪдµÄÊý¾ÝºÍÏÖÓеÄÊý¾ÝÒ»Ö£¬¾Í²»½øÐÐÈκβÙ×÷£¬Ö±½Ó·µ»Ø + { + return(err); + } + else + { + start_adr = e_adr & EEPROM_SECTOR_MASK; //¼ÆËã³ösectorµÄÍ·µØÖ· + + for( i=0;i<128;i++ ) //Èç¹ûҪдµÄλÖò»Îª¿Õ£¬ÔòÏÈ°ÑflashÄÚÈݶÁÈ¡³öÀ´£¬·ÅÔÚsramÖУ¬ÐÞ¸Ä + { + EEPROM_DATA[i] = M32(start_adr + 4*i); + } + + EEPROM_DATA[(adr&EEPROM_ARRAY_ADR_MASK)>>2] = Data; //ÐÞ¸ÄSRAM ÖеÄÊý¾Ý + + err=EEPROM_Erase(adr); + + err=Flash_Program(start_adr,(uint8_t*)EEPROM_DATA,512);//È»ºóдÈëflash + } + return(err); + +} + +/****************************************************************************** +* +*Byte дº¯Êý +* +******************************************************************************/ +uint16_t EEPROM_WriteByte(uint32_t adr, uint8_t Data) +{ + uint32_t err = EEPROM_ERR_SUCCESS; + uint32_t data_mask; + uint32_t r_data; + uint32_t data_m0; + uint32_t data_m1; + uint32_t word_adr = adr &0x3fc; + uint32_t b_sit= adr & 0x3; + + + //ÏÈÈøßλΪFF + data_m0 = Data << b_sit*8; + data_mask = 0xFFFFFFFF<<(b_sit+1)*8; +// printf("datam0:=0x%x \n",data_m0); +//È»ºóÈõÍλΪFF + data_m1 = 0xFFFFFFFF >> (32-b_sit*8); + data_m1 = data_m1 | data_m0 | data_mask ; + +// printf("datam1:=0x%x \n",data_m1); + + r_data = EEPROM_Read(word_adr); +// printf("r_data:=0x%x \n",r_data); +//»òÉÏÔ­À´µÄÊý¾Ý + data_m1 = data_m1 & r_data; + + +// printf("data_m1:=0x%x \n",data_m1); ; + err = EEPROM_Write(word_adr , data_m1); + + return(err); + +} + +/****************************************************************************** +* +*Byte ¶Áº¯Êý +* +******************************************************************************/ +uint8_t EEPROM_ReadByte(uint32_t adr) +{ + uint32_t r_data; + uint32_t word_adr = adr &0x3fc; + uint32_t b_sit= adr & 0x3; + uint8_t data; + + r_data = EEPROM_Read(word_adr); + data = (r_data>>b_sit*8)& 0xff; + return(data); + + +} + + +/****************************************************************************** +* +*дº¯Êý£¬Ð´Ò»¸ö³¤¶ÈΪbytesize£¬µ½eeprom +*ÏÈ°Ñ1kµÄeeprom¶ÁÈ¡·ÅÈësram£¬È»ºóÐÞ¸ÄҪдµÄλÖ㬠+*Õâ¸öº¯ÊýÊÇ»¹¿ÉÒÔÔÙÓÅ»¯µÄ +*ÕâÑù¸ü¸Äºó£¬Ã»Óп¼ÂÇ2K eeprom ¡£³¬¹ý2K Ò²ÊÇÍêÈ«¿ÉÒԵġ£ +******************************************************************************/ +uint16_t EERPOM_Writeup4byte(uint32_t adr,uint8_t *pData,uint32_t length) +{ + uint8_t buf[512]; + uint8_t *pbuf; + uint32_t e_adr; + uint32_t e_sec; + uint32_t e_offset; + uint32_t a; + uint32_t err = EEPROM_ERR_SUCCESS; + + #ifdef IAR + if(adr & 0x03) + { + err = EEPROM_ERR_INVALID_PARAM; + return (err); + } + #endif + + if((adr + length )>1024) + { + err=EEPROM_ADR_OverFlow; + return(err); + } + + e_adr=adr+EEPROM_START_ADR; + e_sec=e_adr & EEPROM_SECTOR_MASK; + e_offset=e_adr & 0x1ff; + + + while (length>0){ + //Èç¹ûÆðʼµØÖ·²»µÈÓÚ0£¬»òÕß³¤¶ÈСÓÚ512 ¶¼½øÈëÕâ¸öÑ­»· + if (e_offset||(length<512)){ + pbuf=buf; + a=512-e_offset; + a=(length>a?a:length); + + memcpy(buf,(uint8_t*)e_sec,512); + memcpy(&buf[e_offset],pData,a); + pData+=a; + length-=a; + e_offset=0; + + }else{ //Èç¹ûÆðʼµØÖ·µÈÓÚ0ÇÒ³¤¶È´óÓÚ512 Ôò¼òµ¥ÁË + pbuf=pData; + pData+=512; + length-=512; + } + err=Flash_EraseSector(e_sec); + err=Flash_Program(e_sec,(uint8_t*)pbuf,512);//È»ºóдÈëflash + e_sec+=0x200; + } + return err; +} + + +/* +uint16_t EERPOM_Writeup4byte(uint32_t adr,uint8_t *pData,uint32_t bytesize) +{ + uint32_t err = EEPROM_ERR_SUCCESS; + uint32_t e_adr; + uint16_t i; + uint32_t start_adr; + uint32_t EEPROM_DATA[256]; + uint32_t longword = bytesize >>2; + uint32_t *pwData = (uint32_t*)pData ; + + err=Adress_Js(adr); + + if(adr+bytesize >1024) //Èç¹ûдÈëµÄµØÖ·,¼ÓÉÏҪдµÄÊý¾ÝµÄ¸öÊý´óÓÚ1024£¬Ôò±¨´í + { + err = EEPROM_ADR_OverFlow; + return(err); + } + + e_adr=adr+EEPROM_START_ADR; + + start_adr = e_adr & EEPROM_SECTOR_MASK; //¼ÆËã³ösector Í·µØÖ· + + for( i=0;i<256;i++ ) //ÏÈ°ÑÊý¾Ý¶ÁÈ¡µ½sram + { + EEPROM_DATA[i] = M32(start_adr + 4*i); + } + for( i=0 ;i>2)+i] = *pwData++; + } + //ÏÈeraseµô2¸öeeprom secoter + err=EEPROM_Erase(0x000); + err=EEPROM_Erase(0x200); + + err=Flash_Program(start_adr,(uint8_t*)EEPROM_DATA,1024);//È»ºóдÈëflash + + return(err); +} +*/ + diff --git a/bsp/nv32f100x/lib/src/etm.c b/bsp/nv32f100x/lib/src/etm.c new file mode 100644 index 0000000000000000000000000000000000000000..6fe474e61988480016ef0d9065407493bdb0551b --- /dev/null +++ b/bsp/nv32f100x/lib/src/etm.c @@ -0,0 +1,1207 @@ + +/****************************************************************************** +* @brief providing APIs for configuring ETM. +* +******************************************************************************* +* +* provide APIs for configuring ETM +******************************************************************************/ +#include "common.h" +#include "ETM.h" + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ +ETM_CallbackPtr ETM_Callback[3] = {(ETM_CallbackPtr)NULL}; + + +/****************************************************************************** +* ETM api lists +* +*//*! @addtogroup ETM_api_list +* @{ +*******************************************************************************/ +/*******************************************************************************//*! +* +* @brief set the ETM moule clock source and prescale. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] ClockSource ETM clock source. +* @param[in] ClockPrescale prescale factor. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*******************************************************************************//*! +* +* @设置时钟资æºåŠåˆ†é¢‘系数 +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 ClockSource ETM æ—¶é’Ÿèµ„æº +* @输入 ClockPrescale 分频系数 +* +* @无返回 +* +*********************************************************************************/ +void ETM_ClockSet(ETM_Type *pETM, uint8_t u8ClockSource, uint8_t u8ClockPrescale) +{ + uint8_t u8Temp; + //pETM指å‘çš„SC寄存器低5ä½æ¸…0,å³æœªé€‰æ‹©æ—¶é’Ÿï¼Œæ—¶é’Ÿè¾“入采å–1分频 + u8Temp = (pETM->SC & 0xE0); + //时钟选择,åŠé¢„分频因å­é€‰æ‹© + u8Temp |= (ETM_SC_CLKS(u8ClockSource & 0x3) | ETM_SC_PS(u8ClockPrescale & 0x7)); + //é…置该ETM的状æ€ä¸ŽæŽ§åˆ¶å¯„存器ETMx_SC + pETM->SC = u8Temp; +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM_No to high ture EPWM mode, clock soure is the +* system clock, MOD, CnV are the initial value. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] PWMModeSelect select CPWM , EPWM or combine pwm mode. +* @param[in] PWMEdgeSelect select high true or low true pulse. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/****************************************************************************************** +* +* @ETM中PWMçš„åˆå§‹åŒ–函数 +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 PWMModeSelect 居中对é½CPWM(10)ã€è¾¹æ²¿å¯¹é½EPWM(01)以åŠçº§è”模å¼PWM(11) +* @输入 PWMEdgeSelect 高真脉冲(01)ã€ä½ŽçœŸè„‰å†²ï¼ˆ10) +* +* @无返回 +* +******************************************************************************************/ +void ETM_PWMInit(ETM_Type *pETM, uint8_t u8PWMModeSelect, uint8_t u8PWMEdgeSelect) +{ + uint8_t channels, i; + + ASSERT((ETM0== pETM) || (ETM1== pETM) || (ETM2== pETM));//断言检测通é“åˆæ³•æ€§ + + /* open the clock gate */ + //使能ETM的时钟 + if (ETM0 == pETM) + { + channels = 2; + SIM->SCGC |= SIM_SCGC_ETM0_MASK; + } + else if(ETM1 == pETM) + { + channels = 2; +#if !defined(CPU_NV32M3) + SIM->SCGC |= SIM_SCGC_ETM1_MASK; +#endif + } + else + { + channels = 6; + SIM->SCGC |= SIM_SCGC_ETM2_MASK; + } + + pETM->SC = 0x0; //关闭计数器 /* disable counter */ + pETM->MOD = ETM_MOD_INIT; + + if(ETM_PWMMODE_CENTERALLIGNED == u8PWMModeSelect) //使能CPWM /* enable CPWM */ + { + pETM->SC |= ETM_SC_CPWMS_MASK; + } + else if(ETM_PWMMODE_COMBINE == u8PWMModeSelect) // 打开级è”PWMæ¨¡å¼ /* enable combine pwm mode */ + { + ASSERT(ETM2 == pETM); + pETM->MODE |= ETM_MODE_WPDIS_MASK | ETM_MODE_ETMEN_MASK; + pETM->COMBINE = ETM_COMBINE_COMBINE0_MASK | ETM_COMBINE_COMP0_MASK | ETM_COMBINE_SYNCEN0_MASK | ETM_COMBINE_DTEN0_MASK | + ETM_COMBINE_COMBINE1_MASK | ETM_COMBINE_COMP1_MASK | ETM_COMBINE_SYNCEN1_MASK | ETM_COMBINE_DTEN1_MASK | + ETM_COMBINE_COMBINE2_MASK | ETM_COMBINE_COMP2_MASK | ETM_COMBINE_SYNCEN2_MASK | ETM_COMBINE_DTEN2_MASK + ; + pETM->SC &= ~ETM_SC_CPWMS_MASK; + } + if(ETM_PWM_HIGHTRUEPULSE == u8PWMEdgeSelect) + { + /* Configure ETMers PWM High True Pulses */ + /* é…置通é“寄存器,设置通é“状æ€åŠé€šé“计数值 */ + for(i=0; iCONTROLS[i].CnSC = ETM_CnSC_MSB_MASK | ETM_CnSC_ELSB_MASK; + pETM->CONTROLS[i].CnV = ETM_C0V_INIT + i*100; + } + } + else if(ETM_PWM_LOWTRUEPULSE == u8PWMEdgeSelect) + { + /* Configure ETMers for PWM Low True Pulses */ + for(i=0; iCONTROLS[i].CnSC = ETM_CnSC_MSB_MASK | ETM_CnSC_ELSA_MASK; + pETM->CONTROLS[i].CnV = ETM_C0V_INIT + i*100 ; + } + } +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM_No to input capture mode, enable interrupt. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] Channel channel number to be configured. +* @param[in] CaptureMode select capture edge: rising, falling or both. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/********************************************************************************* +* +* @输入æ•æ‰åˆå§‹åŒ–函数 +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 Channel é…置通é“å· +* @输入 CaptureMode 选择æ•æ‰æ–¹å¼:上å‡æ²¿, 下é™æ²¿æˆ–è·³å˜æ²¿. +* +* @无返回 +* +*********************************************************************************/ +void ETM_InputCaptureInit(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8CaptureMode) +{ + ASSERT(((ETM0 == pETM) && (u8ETM_Channel < 2)) || + ((ETM1 == pETM) && (u8ETM_Channel < 2)) || + ((ETM2 == pETM) && (u8ETM_Channel < 6)) + ); + + + /* open the clock gate */ + /* 使能ETM的时钟 */ + if ((ETM0 == pETM) && (u8ETM_Channel < 2)) + { + SIM->SCGC |= SIM_SCGC_ETM0_MASK; + NVIC_EnableIRQ(ETM0_IRQn); + } + else if((ETM1 == pETM) && (u8ETM_Channel < 2)) + { +#if !defined(CPU_NV32M3) + SIM->SCGC |= SIM_SCGC_ETM1_MASK; + NVIC_EnableIRQ(ETM1_IRQn); +#endif + } + else + { + SIM->SCGC |= SIM_SCGC_ETM2_MASK; + NVIC_EnableIRQ(ETM2_IRQn); + } + + pETM->SC = 0x0; //关闭计数器 /* diable counter */ + pETM->MOD = 0xFFFF; /* free running */ + + if(ETM_INPUTCAPTURE_RISINGEDGE == u8CaptureMode) //使能中断,在上å‡æ²¿æ•æ‰ /* enable interrupt, Capture on rising edge */ + { + pETM->CONTROLS[u8ETM_Channel].CnSC = ETM_CnSC_CHIE_MASK | ETM_CnSC_ELSA_MASK; + } + else if(ETM_INPUTCAPTURE_FALLINGEDGE == u8CaptureMode) //在下é™æ²¿æ•æ‰ /* Capture on falling edge */ + { + pETM->CONTROLS[u8ETM_Channel].CnSC = ETM_CnSC_CHIE_MASK | ETM_CnSC_ELSB_MASK; + } + else if(ETM_INPUTCAPTURE_BOTHEDGE == u8CaptureMode) //在上å‡æ²¿æˆ–下é™æ²¿æ•æ‰ /* Capture on rising or falling edge */ + { + pETM->CONTROLS[u8ETM_Channel].CnSC = ETM_CnSC_CHIE_MASK | ETM_CnSC_ELSA_MASK | ETM_CnSC_ELSB_MASK; + } +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM_No to Dual Edge Capture mode to measure the +* width or the period of a pulse. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] ChannelPair ChannelPair number to be configured: 0, 2, 4. +* @param[in] CaptureMode select capture edge: one shot and continuous mode. +* @param[in] Channel_N_Edge channel N detect edge. +* @param[in] Channel_Np1_Edge channel N+1 detect edge. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @对ETMé…ç½®åŒè¾¹æ•èŽ·æ¨¡å¼æ¥æµ‹é‡ä¸€ä¸ªè„‰å†²çš„宽度或周期 +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 ChannelPair 频é“é…对数的é…置为: 0, 2, 4. +* @输入 CaptureMode 选择å•å‘¨æœŸæ•æ‰ï¼Œå’Œè¿žç»­æ•æ‰æ–¹å¼ +* @输入 Channel_N_Edge 频é“N边沿检测 +* @输入 Channel_Np1_Edge 频é“N+1边沿检测. +* +* @无返回 +* +*********************************************************************************/ +void ETM_DualEdgeCaptureInit(ETM_Type *pETM, uint8_t u8ChannelPair, uint8_t u8CaptureMode, + uint8_t u8Channel_N_Edge, uint8_t u8Channel_Np1_Edge) +{ + ASSERT((ETM2 == pETM) && (u8ChannelPair < 6) && !(u8ChannelPair & 1) ); + + SIM->SCGC |= SIM_SCGC_ETM2_MASK; + if((0 == u8ChannelPair) || (2== u8ChannelPair)) + { + //通é“滤波 /* channel filter is active */ + } + + pETM->SC = 0x0; //关闭计数器 /* diable counter */ + pETM->MOD = 0xFFFF; + pETM->MODE |= ETM_MODE_ETMEN_MASK; /* ETMEN = 1 */ + /* DECAPEN = 1, ChannelPair/2 * 8 */ + pETM->COMBINE |= ((ETM_COMBINE_DECAPEN0_MASK) << (u8ChannelPair * 4)); + + pETM->CONTROLS[u8ChannelPair].CnSC &= ~ETM_CnSC_CHF_MASK; //æ¸…é™¤ç›¸å…³ä½ /* CH(n)F and CH(n+1)F bits must be cleared first */ + pETM->CONTROLS[u8ChannelPair + 1].CnSC &= ~ETM_CnSC_CHF_MASK; + + if(ETM_INPUTCAPTURE_DUALEDGE_ONESHOT == u8CaptureMode) //å•å‘¨æœŸæ¨¡å¼ /* oneshot mode */ + { + pETM->CONTROLS[u8ChannelPair].CnSC &= ~ETM_CnSC_MSA_MASK; + pETM->CONTROLS[u8ChannelPair+1].CnSC &= ~ETM_CnSC_MSA_MASK; + } + else if(ETM_INPUTCAPTURE_DUALEDGE_CONTINUOUS == u8CaptureMode) //è¿žç»­æ¨¡å¼ /* continuouse mode */ + { + pETM->CONTROLS[u8ChannelPair].CnSC |= ETM_CnSC_MSA_MASK; + pETM->CONTROLS[u8ChannelPair+1].CnSC |= ETM_CnSC_MSA_MASK; + } + + pETM->CONTROLS[u8ChannelPair].CnSC |= (u8Channel_N_Edge << 2); //选择检测边沿 /* select detec edge */ + pETM->CONTROLS[u8ChannelPair + 1].CnSC |= (u8Channel_Np1_Edge << 2); + + pETM->COMBINE |= (ETM_COMBINE_DECAP0_MASK << (u8ChannelPair * 4)); +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM_No to input capture mode. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] Channel channel number to be configured. +* @param[in] CompareMode select compare edge: toggle, set and clear. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @输出对比åˆå§‹åŒ– +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 Channel 必须完æˆé…置通é“å³é€šé“å· +* @输入 CompareMode 选择模å¼ï¼šç¿»è½¬ï¼ˆ01)ã€ç½®ä½ï¼ˆ11)ã€æ¸…0(10) +* +* @无返回 +* +*********************************************************************************/ +void ETM_OutputCompareInit(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8CompareMode) +{ + ASSERT(((ETM0 == pETM) && (u8ETM_Channel < 2)) || + ((ETM1 == pETM) && (u8ETM_Channel < 2)) || + ((ETM2 == pETM) && (u8ETM_Channel < 6)) + ); + + /* open the clock gate */ + /* 使能ETM的时钟 */ + if(ETM0 == pETM) + { + SIM->SCGC |= SIM_SCGC_ETM0_MASK; + } + else if(ETM1 == pETM) + { +#if !defined(CPU_NV32M3) + SIM->SCGC |= SIM_SCGC_ETM1_MASK; +#endif + } + else + { + SIM->SCGC |= SIM_SCGC_ETM2_MASK; + } + + pETM->SC = 0x0; //关闭计数器 /* diable counter */ + pETM->MOD = ETM_MOD_INIT; + pETM->CONTROLS[u8ETM_Channel].CnSC = (ETM_CnSC_MSA_MASK | (u8CompareMode << 2)); //选择检测边沿 /* select detec edge */ + pETM->CONTROLS[u8ETM_Channel].CnV = ETM_C0V_INIT; +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM2 to start software synchronization. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @è¿ç”¨ETM2æ¥å®žçŽ°è½¯ä»¶åŒæ­¥ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* +* @无返回 +* +*********************************************************************************/ +void ETM_SoftwareSync(ETM_Type *pETM) +{ + ASSERT(ETM2 == pETM); + + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; // 选择增强PWMåŒæ­¥ /* recommend enhanced sync mode */ + pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM to enable hardware synchronization. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8TriggerN select the hardware trigger source. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/******************************************************************** +* @ETM中é…ç½®ETMx_SYNC 寄存器æ¥ä¿è¯è½¯ä»¶åŒæ­¥ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 u8TriggerN 选择硬件触å‘èµ„æº +* +* @无返回 +* +*********************************************************************************/ +void ETM_HardwareSync(ETM_Type *pETM, uint8_t u8TriggerN) +{ + ASSERT(ETM2 == pETM); + + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; //选择增强PWMåŒæ­¥ /* recommend enhanced sync mode */ + + switch(u8TriggerN) + { + case ETM_SYNC_TRIGGER_TRIGGER2: + pETM->SYNC |= ETM_SYNC_TRIG2_MASK; + break; + case ETM_SYNC_TRIGGER_TRIGGER1: + pETM->SYNC |= ETM_SYNC_TRIG1_MASK; + break; //首先é…ç½®ETM0CH0 /* need configure ETM0CH0 first */ + case ETM_SYNC_TRIGGER_TRIGGER0: + pETM->SYNC |= ETM_SYNC_TRIG0_MASK; + break; //首先é…ç½®CMP0 /* need configure CMP0 first */ + default: + break; + } +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM to enable hardware synchronization, more then 1 trigger. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8TriggerMask select the hardware trigger source. combine TRIG0~TREG2.(x000xxxx~x111xxxx) +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @通过é…ç½®ETMä¿è¯ç¡¬ä»¶åŒæ­¥ï¼Œäº§ç”Ÿè§¦å‘ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 u8TriggerMask 选择硬件触å‘资æº. +* +* @无返回. +* +*********************************************************************************/ +void ETM_HardwareSyncCombine(ETM_Type *pETM, uint8_t u8TriggerMask) +{ + ASSERT(ETM2 == pETM); + + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; //选择增强PWMåŒæ­¥ /* recommend enhanced sync mode */ + pETM->SYNC &= 0x8F; + pETM->SYNC |= (u8TriggerMask & 0x70); +} + +/*********************************************************************************//*! +* +* @brief generate ETM2 hardware trigger 2,Note: please call ETM_HardwareSyncCombine first. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @产生ETM2ç¡¬ä»¶è§¦å‘ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* +* @无返回 +* +*********************************************************************************/ +void ETM_GenerateTrig2(ETM_Type *pETM) +{ + ASSERT(ETM2 == pETM); + + if(pETM->SYNC & ETM_SYNC_TRIG2_MASK) + { +#if defined(CPU_NV32) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; +#elif defined(CPU_NV32M3) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; +#elif defined(CPU_NV32M4) + SIM->SOPT0 |= SIM_SOPT0_ETMSYNC_MASK; +#endif + } +} + + +/*********************************************************************************//*! +* +* @brief general configuration to ETM_No to start software synchronization. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] PrescalerValue system clock divide value, 0 to 3. +* @param[in] DeadETMeValue n count clock is inserted, 0 to 63. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @ETM死区时间æ’入设置. +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 PrescalerValue 系统时钟分频值 +* @输入 DeadETMeValue 死去æ’入时间值,0-63å¯é€‰ +* +* @无返回 +* +*********************************************************************************/ +void ETM_PWMDeadETMeSet(ETM_Type *pETM, uint8_t u8PrescalerValue, uint8_t u8DeadETMeValue) +{ + ASSERT(ETM2 == pETM); + + pETM->COMBINE |= 0x101010; //使能死区时间æ’å…¥ /* enable dead ETMe insertion */ + + if(!(pETM->MODE & ETM_MODE_WPDIS_MASK)) //如果开å¯äº†å†™ä¿æŠ¤/* if write protection is enabled */ + { + pETM->MODE |= ETM_MODE_WPDIS_MASK; //ç¦ç”¨å†™ä¿æŠ¤ /* disable the write protection */ + pETM->DEADETME = (ETM_DEADETME_DTVAL(u8DeadETMeValue & 0x3F) | ETM_DEADETME_DTPS(u8PrescalerValue & 0x3)); + pETM->MODE &= ~ETM_MODE_WPDIS_MASK;//使能写ä¿æŠ¤ /* enable the write protection */ + } + else + { + //如果没有开å¯å†™ä¿æŠ¤ /* if no protection */ + pETM->DEADETME = (ETM_DEADETME_DTVAL(u8DeadETMeValue & 0x3F) | ETM_DEADETME_DTPS(u8PrescalerValue & 0x3)); + } + pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; //软件åŒæ­¥ /* software sync */ +} + +/*********************************************************************************//*! +* +* @brief set output mask. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] Channel pwm channel needed to be masked. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @è®¾ç½®è¾“å‡ºæ ‡å¿—ä½ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 Channel PWM通é“ä½éœ€è¦è¢«ç½®æ ‡å¿— +* +* @无返回 +* +*********************************************************************************/ +void ETM_OutputMaskSet(ETM_Type *pETM, uint8_t u8ETM_Channel) +{ + ASSERT((ETM2 == pETM) && (u8ETM_Channel < 6)); + + pETM->OUTMASK |= (1 << u8ETM_Channel); + + if(pETM->SYNC & ETM_SYNC_SYNCHOM_MASK) //如果需è¦PWMåŒæ­¥æ›´æ–° /* if PWM sync is needed */ + { + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; //选择增强PWMåŒæ­¥ /* recommend enhanced sync mode */ + if(pETM->SYNCONF & ETM_SYNCONF_SWOM_MASK) //如果需è¦è½¯ä»¶åŒæ­¥ /* if software sync is needed*/ + { + pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; + } + else if(pETM->SYNCONF & ETM_SYNCONF_HWOM_MASK)//如果需è¦ç¡¬ä»¶åŒæ­¥ /* if hardware sync is needed*/ + { + pETM->SYNC |= ETM_SYNC_TRIG2_MASK; + +#if defined(CPU_NV32) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; //硬件åŒæ­¥ /* hardware sync */ +#elif defined(CPU_NV32M3) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */ +#elif defined(CPU_NV32M4) + SIM->SOPT0 |= SIM_SOPT0_ETMSYNC_MASK; /* hardware sync */ +#endif + } + else + { + } + } + else /* no need to sync, update on the next rising edge of system clock */ + { + } +} + +/*********************************************************************************//*! +* +* @brief general configuration to ETM_No to start software synchronization. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] Channel pwm channel needed to be controlled by software. +* @param[in] ChannelValue the value to be set, 0 or 1. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @é…置软件输出控制SWOCTRL寄存器的åŒæ­¥æ˜¯å¦ç”±è½¯ä»¶è§¦å‘ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 Channel PWM波的通é“选择 +* @输入 ChannelValue 0或1,0ä¸è§¦å‘;1è§¦å‘ +* +* @无返回 +* +*********************************************************************************/ +void ETM_SWOutputControlSet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8ChannelValue) +{ + ASSERT((ETM2 == pETM) && (u8ETM_Channel < 6)); + + if(ETM_SWOCTRL_HIGH == u8ChannelValue) + { + pETM->SWOCTRL |= (0x0101 << u8ETM_Channel); + } + else if(ETM_SWOCTRL_LOW == u8ChannelValue) + { + pETM->SWOCTRL |= (1 << u8ETM_Channel); + pETM->SWOCTRL &= ~(0x100 << u8ETM_Channel); + } + if(pETM->SYNCONF & ETM_SYNCONF_SWOC_MASK) /* if PWM sync is needed */ + { + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; /* recommend enhanced sync mode */ + if(pETM->SYNCONF & ETM_SYNCONF_SWSOC_MASK) /* if software sync is needed*/ + { + pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; /* software sync */ + } + else if(pETM->SYNCONF & ETM_SYNCONF_HWSOC_MASK) /* if hardware sync is needed*/ + { + pETM->SYNC |= ETM_SYNC_TRIG2_MASK; + +#if defined(CPU_NV32) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */ +#elif defined(CPU_NV32M3) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */ +#elif defined(CPU_NV32M4) + SIM->SOPT0 |= SIM_SOPT0_ETMSYNC_MASK; /* hardware sync */ +#endif + } + } + else /* no need to sync, update on the next rising edge of system clock */ + { + } +} + +/*********************************************************************************//*! +* +* @brief set PWM polarity. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] Channel pwm channel needed to be controlled by software. +* @param[in] ActiveValue the value to be set, 0 or 1. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/********************************************************************************* +* +* @设置通é“输出æžæ€§çš„功能函数 +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 Channel PWM波的通é“选择 +* @输入 ActiveValue æžæ€§çš„选择,0为高电平,1为低电平 +* +* @无返回 +* +*********************************************************************************/ +void ETM_PolaritySet(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8ActiveValue) +{ + ASSERT((ETM2 == pETM) && (u8ETM_Channel < 6)); + + if(ETM_POLARITY_HIGHACTIVE == u8ActiveValue) + { + pETM->POL &= ~(1 << u8ETM_Channel); + } + else if(ETM_POLARITY_LOWACTIVE == u8ActiveValue) + { + pETM->POL |= (1 << u8ETM_Channel); + } +} + +/*********************************************************************************//*! +* +* @brief set ETM behavior in debug mode. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8DebugMode debug mode select from 00 to 11. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/********************************************************************************* +* +* @选择BDM模å¼ä¸‹çš„ETM行为 +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 u8DebugMode debug 的模å¼ä»Ž00-11之间选择 +* +* @无返回 +* +*********************************************************************************/ +void ETM_SetDebugModeBehavior(ETM_Type *pETM, uint8_t u8DebugMode) +{ + ASSERT((ETM2 == pETM)); + pETM->CONF &= ~ETM_CONF_BDMMODE_MASK; + pETM->CONF |= ETM_CONF_BDMMODE(u8DebugMode); +} + +/*********************************************************************************//*! +* +* @brief Selects the ratio between the number of counter overflows to the number of ETMes the TOF bit is set. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u8TOFNUM TOF numbers before setting TOF bit, 0~31. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/*********************************************************************************//*! +* +* @ETM中TOF频率大å°çš„设置功能函数 +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 u8TOFNUM TOF频率数,大å°0å’Œ31之间 +* +* @无返回 +* +*********************************************************************************/ +void ETM_SetTOFFrequency(ETM_Type *pETM, uint8_t u8TOFNUM) +{ + ASSERT((ETM2 == pETM)); + pETM->CONF &= ~ETM_CONF_NUMTOF_MASK; + pETM->CONF |= ETM_CONF_NUMTOF(u8TOFNUM); +} + +/*********************************************************************************//*! +* +* @brief swap the output of CH(n) and CH(n+1). +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] ChannelPair the pair to be swapped, 0,1,2. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*********************************************************************************/ +/********************************************************************************* +* +* @交æ¢é€šé“CH(n)和通é“CH(n+1)的输出结果 +* +* @输入 pETM 其中一个ETMå®šæ—¶å™¨çš„åŸºå€ +* @输入 ChannelPair è¦è¢«äº¤æ¢çš„通é“æ•°å·ï¼Œå³nå¯ä¸º0,1,2, +* +*********************************************************************************/ +void ETM_InvertChannel(ETM_Type *pETM, uint8_t u8ChannelPair) +{ + ASSERT((ETM2 == pETM) && u8ChannelPair <= 2); + + pETM->INVCTRL |= 1<SYNCONF & ETM_SYNCONF_INVC_MASK) //如果需è¦PWMåŒæ­¥ /* if PWM sync is needed */ + { + pETM->SYNCONF |= ETM_SYNCONF_SYNCMODE_MASK; //选择增强PWMåŒæ­¥ /* recommend enhanced sync mode */ + if(pETM->SYNCONF & ETM_SYNCONF_SWINVC_MASK)//如果需è¦è½¯ä»¶åŒæ­¥ /* if software sync is needed*/ + { + pETM->SYNC |= ETM_SYNC_SWSYNC_MASK; //å¼€å¯è½¯ä»¶åŒæ­¥ /* software sync */ + } + else if(pETM->SYNCONF & ETM_SYNCONF_HWINVC_MASK) //如果需è¦ç¡¬ä»¶åŒæ­¥ /* if hardware sync is needed*/ + { + pETM->SYNC |= ETM_SYNC_TRIG2_MASK; + +#if defined(CPU_NV32) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; //硬件åŒæ­¥ /* hardware sync */ +#elif defined(CPU_NV32M3) + SIM->SOPT |= SIM_SOPT_ETMSYNC_MASK; /* hardware sync */ +#elif defined(CPU_NV32M4) + SIM->SOPT0 |= SIM_SOPT0_ETMSYNC_MASK; /* hardware sync */ +#endif + } + } + else + { + } +} + +/*****************************************************************************//*! +* +* @brief configure the ETM as specified control parameters, CnSC and CnV not +* included. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] pConfig pointer to ETM general parameters. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/*****************************************************************************//*! +* +* @ETMåˆå§‹åŒ–函数 +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 pConfig 指å‘ETM的一些基本å‚æ•° +* @无返回值 +* +*****************************************************************************/ +void ETM_Init(ETM_Type *pETM, ETM_ConfigType *pConfig) +{ + ASSERT((ETM0 == pETM) || (ETM1 == pETM) || (ETM2 == pETM)); + if(ETM0 == pETM) + { + SIM->SCGC |= SIM_SCGC_ETM0_MASK; + } +#if !defined(CPU_NV32M3) + else if(ETM1 == pETM) + { + SIM->SCGC |= SIM_SCGC_ETM1_MASK; + } +#endif + else + { + SIM->SCGC |= SIM_SCGC_ETM2_MASK; + } + + /* diable counter */ + pETM->SC = 0; + pETM->MODE = pConfig->mode; + pETM->MOD = pConfig->modulo; + pETM->CNT = pConfig->cnt; + + if( pETM->MODE & ETM_MODE_ETMEN_MASK ) + { + /* when ETMEN = 1, all other registers can be written */ + /* 当 ETMEN = 1, 所有寄存器都å¯ä»¥è¢«å†™å…¥ */ + pETM->COMBINE = pConfig->combine; + pETM->CNTIN = pConfig->cntin; + pETM->SYNC = pConfig->sync; + pETM->OUTINIT = pConfig->outinit; + pETM->OUTMASK = pConfig->outmask; + pETM->DEADETME = pConfig->deadETMe; + pETM->EXTTRIG = pConfig->exttrig; + pETM->POL = pConfig->pol; + pETM->FMS = pConfig->fms; + pETM->FILTER = pConfig->filter; + pETM->FLTCTRL = pConfig->fltctrl; /* fault control */ + pETM->FLTPOL = pConfig->fltpol; + pETM->CONF = pConfig->conf; + pETM->SYNCONF = pConfig->synconf; + pETM->SWOCTRL = pConfig->swoctrl; + pETM->PWMLOAD = pConfig->pwmload; + } + /* write SC to enable clock */ + /*通过写入状æ€æŽ§åˆ¶å¯„存器SCæ¥ä½¿èƒ½ETM时钟 */ + pETM->SC = pConfig->sc; +} + + +/*****************************************************************************//*! +* +* @brief close the ETM moudle. +* +* @param[in] pETM pointer to one of three ETM base register address. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/***************************************************************************** +* +*关闭相应的ETM功能组件函数 +* +*****************************************************************************/ +void ETM_DeInit(ETM_Type *pETM) +{ + ASSERT((ETM0 == pETM) || (ETM1 == pETM) || (ETM2 == pETM)); + pETM->SC = 0; + pETM->MOD = 0; + pETM->CNT = 0; + if(ETM2 == pETM) + { + pETM->MODE = 0x4; + pETM->COMBINE = 0; + pETM->CNTIN = 0; + pETM->SYNC = 0; + pETM->OUTINIT = 0; + pETM->OUTMASK = 0; + pETM->DEADETME = 0; + pETM->EXTTRIG = 0; + pETM->POL = 0; + pETM->FMS = 0; + pETM->FILTER = 0; + pETM->FLTCTRL = 0; + pETM->FLTPOL = 0; + pETM->CONF = 0; + pETM->SYNCONF = 0; + pETM->SWOCTRL = 0; + pETM->PWMLOAD = 0; + } + /* close the clock gate */ + /* ç¦ç”¨æ—¶é’Ÿ */ + if (ETM0 == pETM) + { + SIM->SCGC &= ~SIM_SCGC_ETM0_MASK; + NVIC_DisableIRQ(ETM0_IRQn); + } +#if !defined(CPU_NV32M3) + else if(ETM1 == pETM) + { + SIM->SCGC &= ~SIM_SCGC_ETM1_MASK; + NVIC_DisableIRQ(ETM1_IRQn); + } +#endif + else if (ETM2 == pETM) + { + SIM->SCGC &= ~SIM_SCGC_ETM2_MASK; + NVIC_DisableIRQ(ETM2_IRQn); + } +} + +/*****************************************************************************//*! +* +* @brief configure the ETM channels, CnSC and CnV are included. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] ETM_Channel ETM channel number. +* @param[in] pTETMCH_Params pointer to ETM channel general parameters. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/*****************************************************************************//*! +* +* @本函数用æ¥é…ç½®ETM通é“, 包括通é“状æ€åŠæŽ§åˆ¶å¯„存器CnSC和通é“计数值寄存器CnV +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 ETM_Channel ETM的通é“å· +* @输入 pTETMCH_Params 指å‘ETM通é“一般å‚数的指针 +* +* @无返回值 +* +*****************************************************************************/ +void ETM_ChannelInit(ETM_Type *pETM, uint8_t u8ETM_Channel, ETM_ChParamsType *pTETMCH_Params) +{ + ASSERT((ETM0 == pETM) || (ETM1 == pETM) || (ETM2 == pETM)); + + if (ETM0 == pETM) + { + ASSERT(u8ETM_Channel < 2); + SIM->SCGC |= SIM_SCGC_ETM0_MASK; + } + #if !defined(CPU_NV32M3) + else if(ETM1 == pETM) + { + ASSERT(u8ETM_Channel < 2); + SIM->SCGC |= SIM_SCGC_ETM1_MASK; + } +#endif + else + { + ASSERT(u8ETM_Channel < 6); + SIM->SCGC |= SIM_SCGC_ETM2_MASK; + } + + pETM->CONTROLS[u8ETM_Channel].CnSC = pTETMCH_Params->u8CnSC; + pETM->CONTROLS[u8ETM_Channel].CnV = pTETMCH_Params->u16CnV; + + return; +} + +/*****************************************************************************//*! +* +* @brief set the ETM channel value register per duty cycle and modulo for combine mode +* odd channel no must be provided and even channel value register is not changed. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] ETM_Channel odd channel no:1,3,5. +* @param[in] dutyCycle duty cycle in percentage. e.g. 10, means 10%. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/*****************************************************************************//*! +* +* 必须设置奇数通é“数,且å¶æ•°é€šé“的值ä¸å˜ +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 ETM_Channel 奇通é“数:1ã€3ã€5 +* @输入 dutyCycle 设置å ç©ºæ¯”,若DutyCycle为10,那么å ç©ºæ¯”就为10% +* +* @return none. +* +*****************************************************************************/ +void ETM_SetDutyCycleCombine(ETM_Type *pETM, uint8_t u8ETM_Channel, uint8_t u8DutyCycle) +{ + uint16_t cnv = pETM->CONTROLS[u8ETM_Channel-1].CnV; + uint16_t modulo = pETM->MOD; + + ASSERT((1 == u8ETM_Channel) || (3 == u8ETM_Channel) || (5 == u8ETM_Channel)); + + cnv += (u8DutyCycle * (modulo+1)) / 100; + if(cnv > modulo) + { + cnv = modulo - 1; + } + pETM->CONTROLS[u8ETM_Channel].CnV = cnv ; + + pETM->PWMLOAD |= ETM_PWMLOAD_LDOK_MASK | (1<SYNCONF |= u32ConfigValue; +} + +/*****************************************************************************//*! + +* +* @brief configure the ETMx_SYNCONF register including SW and HW Sync selection. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] u32ConfigValue ETMx_SYNCONF register config value. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/***************************************************************************** +* +* @æ¢å¤é…置寄存器 ETMx_SYNCONF,其中里é¢åŒ…å«äº†è½¯ä»¶è¾“出的控制是å¦ç”±ç¡¬ä»¶è§¦å‘HW或是å¦æœ‰è½¯ä»¶å‡ºå‘SW +* +* @输入 pETM 指å‘三个ETMå®šæ—¶å™¨å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 u32ConfigValue ETMx_SYNCONF这个寄存器的值 +* +* @无返回 +* +*****************************************************************************/ +void ETM_SyncConfigDeactivate(ETM_Type *pETM, uint32_t u32ConfigValue) +{ + ASSERT((ETM2 == pETM)); + pETM->SYNCONF &= ~u32ConfigValue; +} + +/*****************************************************************************//*! +* +* @brief This function sets the callback function. +* +* @param[in] pETM pointer to one of three ETM base register address. +* @param[in] pfnCallback functon address. +* +* @return none. +* +* @ Pass/ Fail criteria: none +* +*****************************************************************************/ +/*****************************************************************************//*! +* +* @è®¾ç½®ä¸­æ–­å›žè°ƒå‡½æ•°å…¥å£ +* +* @输入 pETM 指å‘三个ETMä¸­å…¶ä¸­ä¸€ä¸ªçš„åŸºå€ +* @输入 pfnCallback åŠŸèƒ½å‡½æ•°çš„åœ°å€ +* +* @无返回. +* +*****************************************************************************/ +void ETM_SetCallback(ETM_Type *pETM, ETM_CallbackPtr pfnCallback) +{ + ETM_Callback[((uint32_t)pETM - (uint32_t)ETM0_BASE)>>12] = pfnCallback; +} + +/*! @} End of ETM_api_list */ + + +/*****************************************************************************//*! +* +* @brief ETM0_Isr interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/*********************************************************************************//*! +* +* @ETM0中断æœåŠ¡å‡½æ•° +* +* @无输入 +* +* @无返回 +* +*********************************************************************************/ +void ETM0_Isr(void) +{ + if(ETM_Callback[0]) + { + ETM_Callback[0](); + } +} + +/*****************************************************************************//*! +* +* @brief ETM1_Isr interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/*********************************************************************************//*! +* +* @ETM1中断æœåŠ¡å‡½æ•° +* +* @无输入 +* +* @无返回 +* +*********************************************************************************/ +void ETM1_Isr(void) +{ + if(ETM_Callback[1]) + { + ETM_Callback[1](); + } +} + +/*****************************************************************************//*! +* +* @brief ETM2_Isr interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +/*********************************************************************************//*! +* +* @ETM2中断æœåŠ¡å‡½æ•° +* +* @无输入 +* +* @无返回 +* +*********************************************************************************/ +void ETM2_Isr(void) +{ + if(ETM_Callback[2]) + { + ETM_Callback[2](); + } +} + + + diff --git a/bsp/nv32f100x/lib/src/flash.c b/bsp/nv32f100x/lib/src/flash.c new file mode 100644 index 0000000000000000000000000000000000000000..b1b10145b99b9b471d6727b7b77ca3ec0caf2997 --- /dev/null +++ b/bsp/nv32f100x/lib/src/flash.c @@ -0,0 +1,351 @@ +/****************************************************************************** +****************************************************************************** +* +* @file flash.c +* +* @brief application entry point which performs application specific tasks. +* +******************************************************************************* +* +* provide a demo for how to initialize the NV32, output messages via SCI, +* flash operations, etc. +* NOTE: +* printf call may occupy a lot of memory (around 1924 bytes), so please +* consider your code size before using printf. +****************************************************************************** +* +* provide FLASH driver +* +******************************************************************************/ + +#include "flash.h" +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: Flash_CopyInRAM +* +* @brief This section of the code is the one that copies the routine into RAM. +* It is following the steps documented in Technical Note 228 +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +#define FLASH_ENABLE_STALLING_FLASH_CONTROLLER + + +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: Flash_Init +* +* @brief initialize flash driver +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +uint16_t Flash_Init(void) +{ + uint16_t err = FLASH_ERR_SUCCESS; + uint32_t clkDIV = BUS_CLK_HZ/1000000L - 1; + uint32_t Tpgs =(285 *(BUS_CLK_HZ/100))/1000000L; //update 2016.8.4 by ¹â½Å°å¤ÎGG + uint32_t Tprog =(675*(BUS_CLK_HZ/100))/1000000L; //by ¹â½Å°å¤ÎGG +// printf("Tpgs= %x \n" , Tpgs); +// printf("Tprog= %x \n" , Tprog); + + EFMCR=(clkDIV<<24) + 0x00001103; //divide to 1M hz + EFMETM0=(Tpgs<<16) + 0x00001194; //0x00281194; // + EFMETM1=(Tprog<<16) + 0x000088B8; // +// printf("EFMCR= %x \n" , EFMCR); +// printf("EFMETM0= %x \n" , EFMETM0); +// printf("EFMETM1= %x \n" , EFMETM1); + return(err); +} + +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: FlashProgram +* +* @brief program flash routine, each program operation supports up to 2 longwords +* programming +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +uint16_t Flash_Program(uint32_t wNVMTargetAddress, uint8_t *pData, uint16_t sizeBytes) +{ + uint16_t err = FLASH_ERR_SUCCESS; + uint16_t w2LongWordCount = sizeBytes>>3; + uint8_t wLeftBytes = (sizeBytes & 0x07); + uint16_t wLeftLongWords = wLeftBytes>>2; + uint32_t wTargetAddress = wNVMTargetAddress; + uint32_t dwData0,dwData1; + uint32_t *pdwData = (uint32_t*)pData; + int i; + //printf("\n adr : 0x%x ,data = 0x%x\n",w2LongWordCount,wLeftLongWords ); + // Check address to see if it is aligned to 4 bytes + // Global address [1:0] must be 00. + if(wNVMTargetAddress & 0x03) + { + err = FLASH_ERR_INVALID_PARAM; + return (err); + } + // Loop for the two longwords (8 bytes) programming + for(i = 0; i < w2LongWordCount; i++) + { + dwData0 = *pdwData++; + dwData1 = *pdwData++; + err = Flash_Program2LongWords(wTargetAddress, dwData0, dwData1); + if(err) + { + goto EndP; + //break; + } + wTargetAddress += 8; + } + // Loop for the single longword (4 bytes) programming + for(i = 0; i < wLeftLongWords; i++) + { + dwData0 = *pdwData++; + //printf("\n adr : 0x%x ,data = 0x%x\n",i,dwData0 ); + err = Flash_Program1LongWord(wTargetAddress, dwData0); + //printf("\n adr : 0x%x ,data = 0x%x\n",i,dwData0 ); + if(err) + { + goto EndP; + //break; + } + wTargetAddress += 4; + } + wLeftBytes = (wLeftBytes-(wLeftLongWords<<2)); // calculate the # of bytes that are not programmed + if(!wLeftBytes){ + return (err); + } + +#if defined(BIG_ENDIAN) + dwData0 = 0; + pData = (uint8_t*)pdwData; // pointer to the left bytes + for(i = wLeftBytes; i >0; i--) + { + dwData0 <<= 8; + dwData0 |= *pData++; // MSB byte first + } + // Calculate how many bytes need to be filled with 0xFFs + // in order to form a single longword for the left bytes of data + wLeftBytes = 4 - wLeftBytes; + // + for(i = wLeftBytes; i >0; i--) + { + dwData0 <<= 8; + dwData0 |= 0xFF; // MSB byte first + } +#else + dwData0 = 0xFFFFFFFFL; + pData = (uint8_t*)pdwData+wLeftBytes-1; // pointer to the left bytes + for(i = wLeftBytes; i >0; i--) + { + dwData0 <<= 8; + dwData0 |= *pData--; // MSB byte first + } +#endif + // Now program the last longword + err = Flash_Program1LongWord(wTargetAddress, dwData0); +EndP: + return (err); +} + +uint16_t Flash_Program1LongWord(uint32_t wNVMTargetAddress, uint32_t dwData) +{ + uint16_t err = FLASH_ERR_SUCCESS; + + // Check address to see if it is aligned to 4 bytes + // Global address [1:0] must be 00. + if(wNVMTargetAddress & 0x03) + { + err = FLASH_ERR_INVALID_PARAM; + return (err); + } + // Clear error flags + EFMCMD = FLASH_CMD_CLEAR; + // Write index to specify the command code to be loaded + M32(wNVMTargetAddress) = dwData; + // Write command code and memory address bits[23:16] + EFM_LaunchCMD(FLASH_CMD_PROGRAM); + return (err); +} + + +uint16_t Flash_Program2LongWords(uint32_t wNVMTargetAddress, uint32_t dwData0, uint32_t dwData1) +{ + uint16_t err = FLASH_ERR_SUCCESS; + + + // Check address to see if it is aligned to 4 bytes + // Global address [1:0] must be 00. + if(wNVMTargetAddress & 0x03) + { + err = FLASH_ERR_INVALID_PARAM; + return (err); + } + // Clear error flags + + EFMCMD = FLASH_CMD_CLEAR; + +// printf("\n write data adr : 0x%x ,data = 0x%x\n",dwData0,dwData1 ); + // Write index to specify the command code to be loaded + M32(wNVMTargetAddress) = dwData0; + // Write command code and memory address bits[23:16] + EFM_LaunchCMD(FLASH_CMD_PROGRAM); + wNVMTargetAddress = wNVMTargetAddress +4; + + // printf("\n write data adr : 0x%x ,data = 0x%x\n",wNVMTargetAddress,dwData1 ); + // Clear error flags + EFMCMD = FLASH_CMD_CLEAR; + // Write index to specify the command code to be loaded + M32(wNVMTargetAddress) = dwData1; + // Write command code and memory address bits[23:16] + EFM_LaunchCMD(FLASH_CMD_PROGRAM); +// printf("\n write data adr : 0x%x ,data = 0x%x\n",wNVMTargetAddress,dwData1 ); + return (err); +} + + + + + +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: Flash_EraseSector +* +* @brief erase flash sector, each flash sector is of 512 bytes long, +* global address [1:0] = 00. +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint16_t Flash_EraseSector(uint32_t wNVMTargetAddress) +{ + uint16_t err = FLASH_ERR_SUCCESS; + // Check address to see if it is aligned to 4 bytes + // Global address [1:0] must be 00. + if(wNVMTargetAddress & 0x03) + { + err = FLASH_ERR_INVALID_PARAM; + return (err); + } + // Clear error flags + EFMCMD = FLASH_CMD_CLEAR; + M32(wNVMTargetAddress) = 0xffffffff; + EFM_LaunchCMD(FLASH_CMD_ERASE_SECTOR); + return (err); +} + +uint16_t Flash_VerifyBackdoorKey() +{ + uint16_t err = FLASH_ERR_SUCCESS; +// int i; + + // Clear error flags + EFMCMD = FLASH_CMD_CLEAR; + // Write index to specify the command code to be loaded + Custombkd = FLASH_FACTORY_KEY; + return (err); +} + +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: NVM_EraseAll +* +* @brief erase all block,both flash and EEPROM +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint16_t NVM_EraseAll(void) +{ + uint16_t err = FLASH_ERR_SUCCESS; + EFMCMD = FLASH_CMD_CLEAR; + EFM_LaunchCMD(FLASH_CMD_ERASE_ALL); + // Clear error flags + return err; +} + +/*****************************************************************************//*! ++FUNCTION---------------------------------------------------------------- +* @function name: NVM_Unsecure +* +* @brief unsecure +* +* @param +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint16_t NVM_Unsecure(void) +{ + uint16_t err = FLASH_ERR_SUCCESS; + + return err; +} + +#ifdef IAR +void __ramfunc EFM_LaunchCMD(uint32_t EFM_CMD) +#else +void EFM_LaunchCMD(uint32_t EFM_CMD) +#endif +{ + DisableInterrupts; + if((EFMCMD&EFM_DONE_MASK)== EFM_STATUS_READY) + { + EFMCMD = EFM_CMD; + } + while(1) + { + if((EFMCMD&EFM_DONE_MASK) == EFM_STATUS_DONE) break; + } + EnableInterrupts; +} diff --git a/bsp/nv32f100x/lib/src/gpio.c b/bsp/nv32f100x/lib/src/gpio.c new file mode 100644 index 0000000000000000000000000000000000000000..5cc10d05a9cf132143bc52ac562721a8390a04c8 --- /dev/null +++ b/bsp/nv32f100x/lib/src/gpio.c @@ -0,0 +1,688 @@ +/****************************************************************************** +* @brief providing common gpio API. +* +******************************************************************************/ +#include "gpio.h" + +/****************************************************************************** +* Local variables +******************************************************************************/ + + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local functions +*****************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define GPIO APIs +* +*//*! @addtogroup gpio_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* @brief Initialize the GPIO registers to the default reset values. +* +* @param[in] pGPIO Pointer to GPIO module, can be GPIOA/GPIOB. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void GPIO_DeInit(GPIO_Type *pGPIO) +{ + /* Sanity check */ +#if defined(CPU_NV32) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB)); +#endif +#if defined(CPU_NV32M3) + ASSERT(pGPIO == GPIOA); +#endif +#if defined(CPU_NV32M4) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB) || (pGPIO == GPIOC)); +#endif + + pGPIO->PCOR = 0x00000000; /* Port Clear Output Register */ + pGPIO->PDDR = 0x00000000; /* Port Data Direction */ + //pGPIO->PDIR = 0x00000000; /* Port Data Input Register */ + pGPIO->PDOR = 0x00000000; /* Port Data Output Register */ + pGPIO->PIDR = 0xFFFFFFFF; /* Port Input Disable Register */ + pGPIO->PSOR = 0x00000000; /* Port Set Output Register */ + pGPIO->PTOR = 0x00000000; /* Port Toggle Output Register */ +} + +/*****************************************************************************//*! +* @brief Initialize GPIO pins which are specified by u32PinMask +* +* @param[in] pGPIO Pointer to GPIO module, can be GPIOA/GPIOB. +* @param[in] u32PinMask GPIO pin mask need to be set +* @param[in] sGpioType pin attribute +* +* @return none +* +* @Note +* . High-current drive function is disabled, if the pin is configured as an input +* . Internal pullup is disabled if the pin is configured as an output +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void GPIO_Init(GPIO_Type *pGPIO, uint32_t u32PinMask, GPIO_PinConfigType sGpioType) +{ + /* Sanity check */ +#if defined(CPU_NV32) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB)); +#endif +#if defined(CPU_NV32M3) + ASSERT(pGPIO == GPIOA); +#endif +#if defined(CPU_NV32M4) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB) || (pGPIO == GPIOC)); +#endif + + /* Config GPIO for Input or Output */ + if ((sGpioType == GPIO_PinOutput) || (sGpioType == GPIO_PinOutput_HighCurrent)) + { + pGPIO->PDDR |= u32PinMask; /* Enable Port Data Direction Register */ + pGPIO->PIDR |= u32PinMask; /* Set Port Input Disable Register */ + } + else if ((sGpioType == GPIO_PinInput) || (sGpioType == GPIO_PinInput_InternalPullup)) + { + pGPIO->PDDR &= ~u32PinMask; /* Disable Port Data Direction Register */ + pGPIO->PIDR &= ~u32PinMask; /* Clear Port Input Disable Register */ + } + /* Config PORT Pull select for GPIO */ +#if defined(CPU_NV32) + switch((uint32_t)pGPIO) + { + case GPIOA_BASE: + (sGpioType == GPIO_PinInput_InternalPullup)?(PORT->PUEL |= u32PinMask):(PORT->PUEL &= ~u32PinMask); + break; + case GPIOB_BASE: + (sGpioType == GPIO_PinInput_InternalPullup)?(PORT->PUEH |= u32PinMask):(PORT->PUEH &= ~u32PinMask); + break; + default: + break; + } +#endif + +#if defined(CPU_NV32M3) + switch((uint32_t)pGPIO) + { + case GPIOA_BASE: + (sGpioType == GPIO_PinInput_InternalPullup)?(PORT->PUEL |= u32PinMask):(PORT->PUEL &= ~u32PinMask); + break; + default: + break; + } +#endif + +#if defined(CPU_NV32M4) + switch((uint32_t)pGPIO) + { + case GPIOA_BASE: + (sGpioType == GPIO_PinInput_InternalPullup)?(PORT->PUE0 |= u32PinMask):(PORT->PUE0 &= ~u32PinMask); + break; + case GPIOB_BASE: + (sGpioType == GPIO_PinInput_InternalPullup)?(PORT->PUE1 |= u32PinMask):(PORT->PUE1 &= ~u32PinMask); + break; + case GPIOC_BASE: + (sGpioType == GPIO_PinInput_InternalPullup)?(PORT->PUE2 |= u32PinMask):(PORT->PUE2 &= ~u32PinMask); + break; + default: + break; + } +#endif + + /* Config PORT GPIO_PinOutput_HighCurrent for GPIO */ +#if defined(CPU_NV32M3) + if (u32PinMask & GPIO_PTC5_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTC5_MASK; + } + if (u32PinMask & GPIO_PTC1_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTC1_MASK; + } + if (u32PinMask & GPIO_PTB5_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTB5_MASK; + } +#endif + +#if defined(CPU_NV32) | defined(CPU_NV32M4) + if (pGPIO == GPIOA) + { + if (u32PinMask & GPIO_PTB4_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTB4_MASK; + } + if (u32PinMask & GPIO_PTB5_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTB5_MASK; + } + if (u32PinMask & GPIO_PTD0_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTD0_MASK; + } + if (u32PinMask & GPIO_PTD1_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTD1_MASK; + } + } + if (pGPIO == GPIOB) + { + if (u32PinMask & GPIO_PTE0_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTE0_MASK; + } + if (u32PinMask & GPIO_PTE1_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTE1_MASK; + } + if (u32PinMask & GPIO_PTH0_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTH0_MASK; + } + if (u32PinMask & GPIO_PTH1_MASK) + { + PORT->HDRVE |= PORT_HDRVE_PTH1_MASK; + } + } + +#endif + +} + + + +/*****************************************************************************//*! +* @brief Toggle the pins which are specified by u32PinMask +* +* @param[in] pGPIO Pointer to GPIO module, can be GPIOA/GPIOB. +* @param[in] u32PinMask Specify GPIO pin need to be toggled +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void GPIO_Toggle(GPIO_Type *pGPIO, uint32_t u32PinMask) +{ + /* Sanity check */ +#if defined(CPU_NV32) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB)); +#endif +#if defined(CPU_NV32M3) + ASSERT(pGPIO == GPIOA); +#endif +#if defined(CPU_NV32M4) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB) || (pGPIO == GPIOC)); +#endif + + pGPIO->PTOR = u32PinMask; /* Toggle the pins specified by u32PinMask */ +} + +/*****************************************************************************//*! +* @brief Read input data from GPIO which is specified by pGPIO +* +* @param[in] pGPIO Pointer to GPIO module, can be GPIOA/GPIOB. +* +* @return GPIO input value unsigned int 32-bit +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint32_t GPIO_Read(GPIO_Type *pGPIO) +{ + /* Sanity check */ +#if defined(CPU_NV32) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB)); +#endif +#if defined(CPU_NV32M3) + ASSERT(pGPIO == GPIOA); +#endif +#if defined(CPU_NV32M4) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB) || (pGPIO == GPIOC)); +#endif + + return (pGPIO->PDIR); /* Read Port Data Input Register */ + +} + +/*****************************************************************************//*! +* @brief Read input data from Bit GPIO which is specified by pGPIO +* +* @param[in] pGPIO Pointer to GPIO module, can be GPIOA/GPIOB. +* +* @return Bit GPIO input value +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint8_t GPIO_BitRead(GPIO_PinType GPIO_Pin) +{ + uint8_t data; + /* Sanity check */ + ASSERT(GPIO_Pin <= GPIO_PTI7); + + + /* Config GPIO and pull select*/ + + if (GPIO_Pin < GPIO_PTE0) + { + if(((1<PDIR) > 0) /* Read Bit GPIO input value */ + data = 0x1; /* return value */ + else + data = 0x0; + + } + + else if (GPIO_Pin < GPIO_PTI0) + { + GPIO_Pin = (GPIO_PinType)(GPIO_Pin - 32); + + if(((1<PDIR) > 0) /* Read Bit GPIO input value */ + data = 0x1; /* return value */ + else + data = 0x0; + + } + + return data; + +} + + +/*****************************************************************************//*! +* @brief Write output data to GPIO which is specified by pGPIO +* +* @param[in] pGPIO Pointer to GPIO module, can be GPIOA/GPIOB. +* @param[in] u32Value value to output +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void GPIO_Write(GPIO_Type *pGPIO, uint32_t u32Value) +{ + /* Sanity check */ +#if defined(CPU_NV32) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB)); +#endif +#if defined(CPU_NV32M3) + ASSERT(pGPIO == GPIOA); +#endif +#if defined(CPU_NV32M4) + ASSERT((pGPIO == GPIOA) || (pGPIO == GPIOB) || (pGPIO == GPIOC)); +#endif + + pGPIO->PDOR = u32Value; /* Write Port Ouput Data Register */ + +} + +/*****************************************************************************//*! +* @brief Initialize GPIO single pin which is specified by GPIO_Pin +* +* @param[in] GPIO_Pin GPIO pin name, can be GPIO_PTA0,1 ... +* @param[in] GPIO_PinConfig Config output or input +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void GPIO_PinInit(GPIO_PinType GPIO_Pin, GPIO_PinConfigType GPIO_PinConfig) +{ + /* Sanity check */ + ASSERT(GPIO_Pin <= GPIO_PTI7); + + /* Config GPIO and pull select*/ +#if defined(CPU_NV32) + if (GPIO_Pin < GPIO_PTE0) + { + switch (GPIO_PinConfig) + { + case GPIO_PinOutput: + GPIOA->PDDR |= (1<PIDR |= (1<PUEL &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUEL &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUEL |= (1<PDDR |= (1<PIDR |= (1<PUEL &= ~(1<PDDR |= (1<PIDR |= (1<PUEH &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUEH &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUEH |= (1<PDDR |= (1<PIDR |= (1<PUEH &= ~(1<PDDR |= (1<PIDR |= (1<PUEL &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUEL &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUEL |= (1<PDDR |= (1<PIDR |= (1<PUEL &= ~(1<PDDR |= (1<PIDR |= (1<PUE0 &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUE0 &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUE0 |= (1<PDDR |= (1<PIDR |= (1<PUE0 &= ~(1<PDDR |= (1<PIDR |= (1<PUE1 &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUE1 &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUE1 |= (1<PDDR |= (1<PIDR |= (1<PUE1 &= ~(1<PDDR |= (1<PIDR |= (1<PUE2 &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUE2 &= ~(1<PDDR &= ~(1<PIDR &= ~(1<PUE2 |= (1<PDDR |= (1<PIDR |= (1<PUE2 &= ~(1<HDRVE |= PORT_HDRVE_PTB5_MASK; + break; + case GPIO_PTC1: + PORT->HDRVE |= PORT_HDRVE_PTC1_MASK; + break; + case GPIO_PTC5: + PORT->HDRVE |= PORT_HDRVE_PTC5_MASK; + break; + default: + break; + } +#endif + +#if defined(CPU_NV32M4) | defined(CPU_NV32) + switch (GPIO_Pin) + { + case GPIO_PTB4: + PORT->HDRVE |= PORT_HDRVE_PTB4_MASK; + break; + case GPIO_PTB5: + PORT->HDRVE |= PORT_HDRVE_PTB5_MASK; + break; + case GPIO_PTD0: + PORT->HDRVE |= PORT_HDRVE_PTD0_MASK; + break; + case GPIO_PTD1: + PORT->HDRVE |= PORT_HDRVE_PTD1_MASK; + break; + case GPIO_PTE0: + PORT->HDRVE |= PORT_HDRVE_PTE0_MASK; + break; + case GPIO_PTE1: + PORT->HDRVE |= PORT_HDRVE_PTE1_MASK; + break; + case GPIO_PTH0: + PORT->HDRVE |= PORT_HDRVE_PTH0_MASK; + break; + case GPIO_PTH1: + PORT->HDRVE |= PORT_HDRVE_PTH1_MASK; + break; + default: + break; + } +#endif + } +} + +/*****************************************************************************//*! +* @brief Toggle GPIO single pin which is specified by GPIO_Pin +* +* @param[in] GPIO_Pin GPIO pin name, can be GPIO_PTA0,1 ... +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void GPIO_PinToggle(GPIO_PinType GPIO_Pin) +{ + /* Sanity check */ + ASSERT(GPIO_Pin <= GPIO_PTI7); + + if (GPIO_Pin < GPIO_PTE0) + { + /* PTA0-7, PTB0-7, PTC0-7, PTD0-7 */ + GPIOA->PTOR = (1<PTOR = (1<PTOR = (1<PSOR = (1<PSOR = (1<PSOR = (1<PCOR = (1<PCOR = (1<PCOR = (1<SCGC |= SIM_SCGC_IIC_MASK; +#elif defined(CPU_NV32M3) + SIM->SCGC |= SIM_SCGC_IIC_MASK; +#elif defined(CPU_NV32M4) + if(pI2Cx == I2C0) + { + SIM->SCGC |= SIM_SCGC_I2C0_MASK; + } + else + { + SIM->SCGC |= SIM_SCGC_I2C1_MASK; + } +#endif + + I2C_SetBaudRate(pI2Cx,pI2CConfig->u16F); + I2C_SetSlaveAddress(pI2Cx,pI2CConfig->u16OwnA1); + pI2Cx->FLT = (uint8_t)pI2CConfig->u16Filt; + pI2Cx->RA = (uint8_t)pI2CConfig->u16RangeA & 0xfe; + I2C_SetSCLLowETMeout(pI2Cx,pI2CConfig->u16Slt); + + /* configure C2 control register */ + u8Temp = 0; + if( pI2CConfig->sSetting.bGCAEn ) + { + u8Temp |= I2C_C2_GCAEN_MASK; + } + if( pI2CConfig->sSetting.bAddressExt ) + { + u8Temp |= I2C_C2_ADEXT_MASK; + } + if( pI2CConfig->sSetting.bRangeAddEn ) + { + u8Temp |= I2C_C2_RMEN_MASK; + } + pI2Cx->C2 |= u8Temp; + + /* configure SMB rehister */ + u8Temp = 0; + if( pI2CConfig->sSetting.bFackEn ) + { + u8Temp |= I2C_SMB_FACK_MASK; + } + if( pI2CConfig->sSetting.bSMB_AlertEn ) + { + u8Temp |= I2C_SMB_ALERTEN_MASK; + } + if( pI2CConfig->sSetting.bSecondAddressEn ) + { + u8Temp |= I2C_SMB_SIICAEN_MASK; + } + if( pI2CConfig->sSetting.bSHTF2IntEn ) + { + u8Temp |= I2C_SMB_SHTF2IE_MASK; + } + pI2Cx->SMB = u8Temp; + + /* configure C1 rehister */ + u8Temp = 0; + if( pI2CConfig->sSetting.bIntEn ) + { + u8Temp |= I2C_C1_IICIE_MASK; + if(pI2Cx == I2C0) + { + NVIC_EnableIRQ(I2C0_IRQn); + } + #if defined(CPU_NV32M4) + else if(pI2Cx == I2C1) + { + NVIC_EnableIRQ(I2C1_IRQn); + } + #endif + else + { + // + } + } + if( pI2CConfig->sSetting.bWakeUpEn ) + { + u8Temp |= I2C_C1_WUEN_MASK; + } + if( pI2CConfig->sSetting.bI2CEn ) + { + u8Temp |= I2C_C1_IICEN_MASK; + } + pI2Cx->C1 = u8Temp; + + +} +/*****************************************************************************//*! + * + * @brief send out start signals. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return error status + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +uint8_t I2C_Start(I2C_Type *pI2Cx) +{ + uint32_t u32ETMeout; + uint8_t u8ErrorStatus; + + u32ETMeout = 0; + u8ErrorStatus = 0x00; + + I2C_TxEnable(pI2Cx); + pI2Cx->C1 |= I2C_C1_MST_MASK; + + while( (!I2C_IsBusy(pI2Cx)) && ( u32ETMeout < I2C_WAIT_STATUS_ETMEOUT)) + { + u32ETMeout ++; + } + + if( u32ETMeout == I2C_WAIT_STATUS_ETMEOUT ) + { + u8ErrorStatus |= I2C_ERROR_START_NO_BUSY_FLAG; + } + + return u8ErrorStatus; +} + +/*****************************************************************************//*! + * + * @brief send out stop signals. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return error status + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +uint8_t I2C_Stop(I2C_Type *pI2Cx) +{ + uint32_t u32ETMeout; + uint8_t u8ErrorStatus; + + u32ETMeout = 0; + u8ErrorStatus = 0x00; + + pI2Cx->C1 &= ~I2C_C1_MST_MASK; + + while( (I2C_IsBusy(pI2Cx) ) && ( u32ETMeout < I2C_WAIT_STATUS_ETMEOUT)) + { + u32ETMeout ++; + } + + if( u32ETMeout == I2C_WAIT_STATUS_ETMEOUT ) + { + u8ErrorStatus |= I2C_ERROR_STOP_BUSY_FLAG; + } + + return u8ErrorStatus; +} + + +/*****************************************************************************//*! + * + * @brief send out repeat start signals. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return error status. + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +uint8_t I2C_RepeatStart(I2C_Type *pI2Cx) +{ + uint32_t u32ETMeout; + uint8_t u8ErrorStatus; + + u32ETMeout = 0; + u8ErrorStatus = 0x00; + + pI2Cx->C1 |= I2C_C1_RSTA_MASK; + + while( (!I2C_IsBusy(I2C0) ) && ( u32ETMeout < I2C_WAIT_STATUS_ETMEOUT)) + { + u32ETMeout ++; + } + + if( u32ETMeout == I2C_WAIT_STATUS_ETMEOUT ) + { + u8ErrorStatus |= I2C_ERROR_START_NO_BUSY_FLAG; + } + + return u8ErrorStatus; +} + +/*****************************************************************************//*! + * + * @brief set slave address. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +void I2C_SetSlaveAddress(I2C_Type *pI2Cx,uint16_t u16SlaveAddress) +{ + /* write low 8bit address */ + pI2Cx->A1 = (uint8_t)u16SlaveAddress; + + /* write high 3bit address if it support 10bit slave address */ + pI2Cx->C2 &= ~I2C_C2_AD_MASK; + pI2Cx->C2 |= (uint8_t)(u16SlaveAddress>>8)&0x03; +} + +/*****************************************************************************//*! + * + * @brief disable IICIF interrupt. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +void I2C_IntDisable(I2C_Type *pI2Cx) +{ + pI2Cx->C1 &= ~I2C_C1_IICIE_MASK; + if(pI2Cx == I2C0) + { + NVIC_DisableIRQ(I2C0_IRQn); + } + #if defined(CPU_NV32M4) + else if(pI2Cx == I2C1) + { + NVIC_DisableIRQ(I2C1_IRQn); + } + #endif + else + { + + } +} +/*****************************************************************************//*! + * + * @brief enable IICIF interrupt. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +void I2C_IntEnable(I2C_Type *pI2Cx) +{ + pI2Cx->C1 |= I2C_C1_IICIE_MASK; + if(pI2Cx == I2C0) + { + NVIC_EnableIRQ(I2C0_IRQn); + } + #if defined(CPU_NV32M4) + else if(pI2Cx == I2C1) + { + NVIC_EnableIRQ(I2C1_IRQn); + } + #endif + else + { + + } +} + +/*****************************************************************************//*! + * + * @brief SCL low ETMeout value that determines the ETMeout period of SCL low. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +void I2C_SetSCLLowETMeout(I2C_Type *pI2Cx, uint16_t u16ETMeout) +{ + pI2Cx->SLTL = (uint8_t)u16ETMeout; + pI2Cx->SLTH = (uint8_t)(u16ETMeout>>8); +} +/*****************************************************************************//*! + * + * @brief deinit I2C module. + * + * @param[in] pI2Cx point to I2C module type. + * + * @return none + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ +void I2C_Deinit(I2C_Type *pI2Cx) +{ + pI2Cx->C1 &= ~I2C_C1_IICEN_MASK; +#if defined(CPU_NV32) + SIM->SCGC &= ~SIM_SCGC_IIC_MASK; +#elif defined(CPU_NV32M3) + SIM->SCGC &= ~SIM_SCGC_IIC_MASK; +#elif defined(CPU_NV32M4) + if(pI2Cx == I2C0) + { + SIM->SCGC &= ~SIM_SCGC_I2C0_MASK; + } + else + { + SIM->SCGC &= ~SIM_SCGC_I2C1_MASK; + } +#endif +} + +/*****************************************************************************//*! + * + * @brief write a byte to I2C module. + * + * @param[in] pI2Cx point to I2C module type. + * @param[in] u8WrBuff data buffer for writing. + * + * @return error status + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ + +uint8_t I2C_WriteOneByte(I2C_Type *pI2Cx, uint8_t u8WrBuff) +{ + uint32_t u32ETMeout; + uint8_t u8ErrorStatus; + + u32ETMeout = 0; + u8ErrorStatus = 0x00; + while (((I2C_GetStatus(pI2Cx)&I2C_S_TCF_MASK) != I2C_S_TCF_MASK) + && (u32ETMeout= I2C_WAIT_STATUS_ETMEOUT) + { + u8ErrorStatus |= I2C_ERROR_NO_WAIT_TCF_FLAG; + return u8ErrorStatus; + } + + I2C_TxEnable(pI2Cx); + I2C_WriteDataReg(pI2Cx,u8WrBuff); + + u32ETMeout = 0; + while (((I2C_GetStatus(pI2Cx)&I2C_S_IICIF_MASK) != I2C_S_IICIF_MASK) + && (u32ETMeout= I2C_WAIT_STATUS_ETMEOUT) + { + u8ErrorStatus |= I2C_ERROR_NO_WAIT_IICIF_FLAG; + return u8ErrorStatus; + } + + /* clear IICIF flag */ + I2C_ClearStatus(pI2Cx,I2C_S_IICIF_MASK); + if (I2C_GetStatus(pI2Cx) & I2C_S_RXAK_MASK) + { + u8ErrorStatus |= I2C_ERROR_NO_GET_ACK; + } + return u8ErrorStatus; +} +/*****************************************************************************//*! + * + * @brief read a byte from slave I2C. + * + * @param[in] pI2Cx point to I2C module type. + * @param[out] pRdBuff point to the data read from slave I2C. + * @param[out] u8Ack send out ack or nack. + * + * @return error status + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ + +uint8_t I2C_ReadOneByte(I2C_Type *pI2Cx, uint8_t *pRdBuff, uint8_t u8Ack) +{ + uint32_t u32ETMeout; + uint8_t u8ErrorStatus; + + u32ETMeout = 0; + u8ErrorStatus = 0x00; + while (((I2C_GetStatus(pI2Cx)&I2C_S_TCF_MASK) != I2C_S_TCF_MASK) + && (u32ETMeout= I2C_WAIT_STATUS_ETMEOUT) + { + u8ErrorStatus |= I2C_ERROR_NO_WAIT_TCF_FLAG; + return u8ErrorStatus; + } + + I2C_RxEnable(pI2Cx); + + if( u8Ack ) + { + /* send out nack */ + I2C_SendNack(pI2Cx); + + } + else + { + /* send out ack */ + I2C_SendAck(pI2Cx); + } + *pRdBuff = I2C_ReadDataReg(pI2Cx); + + u32ETMeout = 0; + while (((I2C_GetStatus(pI2Cx)&I2C_S_IICIF_MASK) != I2C_S_IICIF_MASK) + && (u32ETMeout= I2C_WAIT_STATUS_ETMEOUT) + { + u8ErrorStatus |= I2C_ERROR_NO_WAIT_IICIF_FLAG; + return u8ErrorStatus; + } + + /* clear IICIF flag */ + I2C_ClearStatus(pI2Cx,I2C_S_IICIF_MASK); + + return u8ErrorStatus; +} +/*****************************************************************************//*! + * + * @brief send data to I2C, and wait to complete transfering. + * + * @param[in] pI2Cx point to I2C module type. + * @param[in] u16SlaveAddress slave address. + * @param[in] pWrBuff point the first address of transfering data buffer. + * @param[in] the length of transfering data. + * + * @return error status + * + * @ Pass/ Fail criteria: none +*****************************************************************************/ + +uint8_t I2C_MasterSendWait(I2C_Type *pI2Cx,uint16_t u16SlaveAddress,uint8_t *pWrBuff,uint32_t u32Length) +{ + uint32_t i; + uint8_t u8ErrorStatus; + + /* send start signals to bus */ + u8ErrorStatus = I2C_Start(pI2Cx); + + /* send device address to slave */ + u8ErrorStatus = I2C_WriteOneByte(pI2Cx,((uint8_t)u16SlaveAddress<<1) | I2C_WRITE); + + /* if no error occur, received the correct ack from slave + continue to send data to slave + */ + if( u8ErrorStatus == I2C_ERROR_NULL ) + { + for(i=0;ioscConfig); /*OSCÄ£¿é³õʼ»¯ */ + + /* + * ¶ÔÍⲿ²Î¿¼Ê±ÖÓ½øÐзÖƵ£¬¿É½«ÍⲿʱÖÓ·ÖƵµ½31.25k~39.0625kÖ®¼ä + */ + + ICS_SetClkDivider(pConfig->u32ClkFreq); + + /*½«FLLµÄ²Î¿¼Ê±ÖÓÑ¡ÔñΪÍⲿʱÖÓ*/ + ICS->C1 = ICS->C1 & ~ICS_C1_IREFS_MASK; + + /*µÈ´ýFLL²Î¿¼Ê±ÖÓ±äΪÍⲿʱÖÓ*/ + +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop +}; +#endif + while(ICS->S & ICS_S_IREFST_MASK); + + /* µÈ´ýFLLʱÖÓ³ÉΪICSÊä³öʱÖÓÔ´*/ + while(!(ICS->S & ICS_S_LOCK_MASK)); + + /* + *ÏÖÔÚFLLÊä³öʱÖÓ±äʱÖÓƵÂʵÈÓÚFLL²Î¿¼Ê±ÖÓ·ÖƵ½á¹û³ËÒÔFLLµÄ±¶ÆµÏµÊý + * FLLµÄ±¶ÆµÏµÊýÇë²Î¿¼²Î¿¼ÊÖ²á + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö1·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) == 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + + /* + * Íê³É¶ÔÑ¡ÖеÄʱÖÓÔ´×ö1·ÖƵ£¬ÏµÍ³/×ÜÏßʱÖÓʱƵÂÊΪÉèÖõÄÄ¿±êƵÂÊ + */ + /*LOLSÇå0*/ + ICS->S |= ICS_S_LOLS_MASK; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEIģʽת±ä³ÉFBIģʽ£¬¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´ + * ½øÐÐ2·ÖƵ + * + * @ ²ÎÊý pConfig Ö¸ÏòICSÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FEI_to_FBI(ICS_ConfigType *pConfig) +{ + + /*ICSÊä³öʱÖÓÔ´Ñ¡ÔñÄÚ²¿²Î¿¼Ê±ÖÓ*/ + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(1); + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); + /*µÈ´ýÄÚ²¿Ê±ÖÓ³ÉΪICSÊä³öʱÖÓÔ´*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) !=1); + + /* + * ÏÖÔÚÄÚ²¿²Î¿¼Ê±ÖÓΪICSÊä³öʱÖÓÔ´ + */ +#if defined(BUS_CLK_EQU_CORE_DIVIDE_BY_2)||defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } + +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)); +#endif + + /*LOLSÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEIģʽת»»³ÉFBEģʽ£¬¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ + * OSCÄ£¿éµÄÊä³öʱÖÓÑ¡ÔñÕñµ´Æ÷ʱÖÓÔ´ + * + * @ ²ÎÊý pConfig Ö¸ÏòICSµÄÅäÖýṹÌå . + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ + +void FEI_to_FBE(ICS_ConfigType *pConfig) +{ + OSC_Init(&pConfig->oscConfig); /*³õʼ»¯OSC Ä£¿é */ + + /*ÉèÖÃFLLµÄ²Î¿¼Ê±ÖÓΪÍⲿʱÖÓ*/ + + ICS->C1 = ICS->C1 & ~(ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(2); + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); + + /*µÈÔڲο¼Ê±ÖÓ·¢Éú¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) !=2); /*ÍⲿʱÖÓ³ÉΪICSʱÖÓÊä³öÔ´*/ + while(ICS->S & ICS_S_IREFST_MASK); /*FLL²Î¿¼Ê±ÖÓ³ÉΪÍⲿʱÖÓ*/ + + /* + * ÏÖÔÚÍⲿʱÖÓ³ÉΪICSÊä³öʱÖÓÔ´ + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /* + * ÏÖÔÚICSÊä³öʱÖÓƵÂÊΪѡÖеÄÊä³öʱÖÓÔ´µÄ2·ÖƵ + */ + /* LOLSÇåÁã */ + ICS->S |= ICS_S_LOLS_MASK; +} + + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEIģʽת»»³ÉFBEģʽ£¬¶ÔÑ¡ÖеÄÊä³öʱÖÓÔ´×ö2·ÖƵ + * OSCÊä³öʱÖÓÑ¡ÔñEXTALÒý½ÅµÄÍⲿʱÖÓÔ´ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FEI_to_FBE_OSC(ICS_ConfigType *pConfig) +{ + + OSC_Init(&pConfig->oscConfig); /* ³õʼ»¯OSC */ + + /* + * ÉèÖÃÍⲿ²Î¿¼Ê±ÖӵķÖƵϵÊý£¬½«²Î¿¼Ê±ÖӵķÖƵ½á¹ûÉ趨ÔÚFLL¿ÉÒÔËø¶¨µÄ31.25k~39.0625k·¶Î§ÄÚ£¬ + */ + ICS_SetClkDivider(pConfig->u32ClkFreq); + + /*¸Ä±ä²Î¿¼Ê±ÖÓÔ´£¬½«FLLµÄ²Î¿¼Ê±ÖÓÉèÖÃΪ¶øÍⲿʱÖÓ*/ + ICS->C1 = ICS->C1 & ~(ICS_C1_IREFS_MASK);/*½«FLLµÄ²Î¿¼Ê±ÖÓÉèÖÃΪ¶øÍⲿʱÖÓ*/ + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(2); /*Êä³öʱÖÓÔ´Ñ¡ÔñÍⲿʱÖÓ*/ + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); + + /* µÈ´ý²Î¿¼Ê±ÖÓ·¢Éú¸Ä±ä*/ + +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) !=2);/*ÍⲿʱÖÓ³ÉΪICSʱÖÓÊä³öʱÖÓÔ´*/ + while(ICS->S & ICS_S_IREFST_MASK); /*ÍⲿʱÖÓ³ÉΪFLL²Î¿¼Ê±ÖÓ*/ + + /* + * ÏÖÔÚÍⲿʱÖÓ³ÉΪFLL²Î¿¼Ê±ÖÓºÍICSÊä³öʱÖÓÔ´ + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /* + * ÏÖÔÚICSµÄÊä³öʱÖÓƵÂÊ£¬ÎªÍⲿ²Î¿¼Ê±ÖÓµÄ2·ÖƵ + */ + /*LOLS ÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEIģʽת»»FEEģʽ£¬¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ + * OSCÊä³öʱÖÓÑ¡ÔñEXTALÒý½ÅµÄÍⲿʱÖÓÔ´ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ + +void FEI_to_FEE_OSC(ICS_ConfigType *pConfig) +{ + + OSC_Init(&pConfig->oscConfig); /* ³õʼ»¯OSC */ + + /* + * ÉèÖÃÍⲿ²Î¿¼Ê±ÖӵķÖƵϵÊý£¬½«²Î¿¼Ê±ÖӵķÖƵ½á¹ûÉ趨ÔÚFLL¿ÉÒÔËø¶¨µÄ31.25k~39.0625k·¶Î§ÄÚ + */ + ICS_SetClkDivider(pConfig->u32ClkFreq); + + /* ½«FLLµÄ²Î¿¼Ê±ÖÓÉèÖÃΪÍⲿʱÖÓ */ + + ICS->C1 = ICS->C1 & ~(ICS_C1_IREFS_MASK); + + /*µÈ´ý²Î¿¼Ê±Öӱ仯*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(ICS->S & ICS_S_IREFST_MASK); /*FLL²Î¿¼Ê±ÖÓ±äΪÍⲿʱÖÓ*/ + + /*µÈ´ýFLL³ÉΪICSÊä³öʱÖÓÔ´ */ + while(!(ICS->S & ICS_S_LOCK_MASK)); +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /* + * ÏÖÔÚICSÊä³öʱÖÓƵÂÊ£¬³ÉΪҪÉèÖõÄÄ¿±êƵÂÊ + */ + + /* LOLSÇåÁã */ + ICS->S |= ICS_S_LOLS_MASK; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEEģʽת»»³ÉFEIģʽ. + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FEE_to_FEI(ICS_ConfigType *pConfig) +{ + /*Ñ¡ÔñÄÚ²¿Ê±ÖÓ×÷ΪFLLµÄ²Î¿¼Ê±ÖÓ*/ + ICS->C1 = ICS->C1 | (ICS_C1_IREFS_MASK); + + /*µÈ´ý²Î¿¼Ê±ÖÓ·¢Éú¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(!(ICS->S & ICS_S_IREFST_MASK)); /*FLL²Î¿¼Ê±ÖÓ³ÉΪÄÚ²¿Ê±ÖÓ*/ + + /*FLLʱÖÓ³ÉΪICSÊä³öʱÖÓÔ´ */ + while(!(ICS->S & ICS_S_LOCK_MASK)); + /*LOLSÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; + + /* + * ÏÖÔÚFLLÊä³ö³ÉΪICSÊä³öʱÖÓÔ´ + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /* + * ÏÖÔÚϵͳ/×ÜÏßʱÖÓ´óԼΪ 16MHz + */ + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); + OSC_Disable(); /* ½ûÓà OSCÄ£¿é */ +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEEģʽת»»³ÉFBIģʽ. + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FEE_to_FBI(ICS_ConfigType *pConfig) +{ + /*LOLSÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; + + /* Ñ¡ÔñÄÚ²¿Ê±ÖÓ×÷ΪICSÊä³öʱÖÓÔ´ */ + /* Ñ¡ÔñÄÚ²¿Ê±ÖÓ×÷ΪFLL²Î¿¼Ê±ÖÓ */ + /* LP = 0 ÔÚbypassģʽFLL²»»á±»½ûÖ¹*/ + + ICS->C1 = ICS->C1 | (ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(1); + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); + + /* µÈ´ý²Î¿¼Ê±ÖÓ·¢Éú¸Ä±ä */ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(!(ICS->S & ICS_S_IREFST_MASK)); /*FLL²Î¿¼Ê±ÖÓ³ÉΪÄÚ²¿Ê±ÖÓ*/ + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) !=1); /*ÄÚ²¿Ê±³ÉΪICSÊä³öʱÖÓÔ´*/ + +#if defined(BUS_CLK_EQU_CORE_DIVIDE_BY_2)||defined(CPU_NV32) + /*¶ÔËùÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } + +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)); + +#endif + OSC_Disable(); +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFEEģʽת±ä³ÉFBEģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ + +void FEE_to_FBE(ICS_ConfigType *pConfig) +{ + /*LOLSÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; + + + /* LP = 0 */ + /*Ñ¡ÔñÍⲿʱÖÓ×÷ΪICSÊä³öʱÖÓÔ´*/ + /* LP = 0 ÔÚbypassģʽFLL²»»á±»½ûÖ¹*/ + + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(2); + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); + + /*µÈ´ýÊä³öʱÖÓÔ´·¢Éú¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) !=2); + + /* ÏÖÔÚICSÊä³öʱÖÓÔ´Ñ¡ÔñÍⲿʱÖÓÔ´ + * ×¢ÊÍ: È·±£ÍⲿʱÖÓƵÂÊÔÚ20MHzÒÔÄÚ + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÔñµÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBIģʽת»»³ÉFBEģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBI_to_FBE(ICS_ConfigType *pConfig) +{ + OSC_Init(&pConfig->oscConfig); /*³õʼ»¯OSC*/ + + /* Ñ¡ÔñÍⲿʱÖÓ×öΪFLLµÄ²Î¿¼Ê±ÖÓ */ + /*Ñ¡ÔñÍⲿʱÖÓ×÷ΪÊä³öʱÖÓÔ´*/ + + ICS->C1 = ICS->C1 & ~(ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(2); + + + /* µÈ´ýÊä³öʱÖÓÔ´·¢Éú¸Ä±ä */ + +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) !=2); /*ÍⲿʱÖÓ³ÉΪICSÊä³öʱÖÓÔ´*/ + while((ICS->S & ICS_S_IREFST_MASK));/*ÍⲿʱÖÓ³ÉΪFLLµÄ²Î¿¼Ê±ÖÓ*/ + + /* ÏÖÔÚϵͳʱÖÓÔ´ÊÇÍⲿ²Î¿¼Ê±ÖÓ + * ×¢ÊÍ:È·±£ÍⲿʱÖÓÔ´µÄƵÂÊÔÚ20MHzÄÚ + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif +} + +/*****************************************************************************//** + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBIģʽת»»³ÉFEEģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBI_to_FEE(ICS_ConfigType *pConfig) +{ + OSC_Init(&pConfig->oscConfig); /*³õʼ»¯OSC*/ + + /* Ñ¡ÔñÍⲿʱÖÓ×÷ΪFLLµÄ²Î¿¼Ê±ÖÓ */ + /* Ñ¡ÔñFLLÊä³ö×÷Ϊ×öΪICSÊä³öʱÖÓÔ´*/ + + ICS->C1 = ICS->C1 & ~(ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)); + + /*µÈ´ýʱÖÓÔ´¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + + while((ICS->S & ICS_S_CLKST_MASK)); /*FLLʱÖÓ³ÉΪICSÊä³öʱÖÓÔ´*/ + while((ICS->S & ICS_S_IREFST_MASK)); /*ÍⲿʱÖÓ³ÉΪFLL²Î¿¼Ê±ÖÓ*/ + + /* ÏÖÔÚϵͳʱÖÓԴΪÍⲿʱÖÓ + * ×¢ÊÍ: È·±£ÍⲿʱÖÓÔ´µÄƵÂÊÔÚ20MHzÄÚ + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /*LOLSÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBIģʽת»»³ÉFBIPģʽ + * + * @ ²ÎÊý pConfig Êä³öÖ¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ¾¯¸æ ±ØÐëÔËÐÐÔÚµ÷ÊÔ½Ó¿ÚûÓÐûÓнÓÏßµÄ״̬Ï + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBI_to_FBILP(ICS_ConfigType *pConfig) +{ + /* + * ¼ÙÉèÍⲿ¾§Õñʱ8MHz»òÕß4MHz + */ + ICS->C2 |= ICS_C2_LP_MASK; /*½øÈëµÍ¹¦ºÄģʽ */ +} + + + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBIģʽת±äΪFEIģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBI_to_FEI(ICS_ConfigType *pConfig) +{ + /* Ñ¡ÔñÄÚ²¿Ê±ÖÓΪFLLµÄ²Î¿¼Ê±ÖÓ */ + /*Ñ¡ÔñFLLÊä³ö×÷ΪICSÊä³öʱÖÓÔ´*/ + ICS->C1 = ICS->C1 | (ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)); + + /*µÈ´ýʱÖÓÔ´·¢Éú¸Ä±ä*/ + +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while((ICS->S & ICS_S_CLKST_MASK)); /*FLLÊä³ö³ÉΪICSÊä³öʱÖÓÔ´*/ + while(!(ICS->S & ICS_S_IREFST_MASK)); /*FLLµÄ²Î¿¼Ê±ÖÓÑ¡ÔñΪÍⲿʱÖÓ*/ + + + /* + * ÏÖÔÚICSÊä³öʱÖÓԴΪFLLÊä³ö + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + + /*LOLSÇåÁã */ + ICS->S |= ICS_S_LOLS_MASK; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBEģʽת»»³ÉFBIģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBE_to_FBI(ICS_ConfigType *pConfig) +{ + /*Ñ¡ÔñÄÚ²¿Ê±ÖÓ×÷ΪFLLµÄ²Î¿¼Ê±ÖÓ*/ + /*Ñ¡ÔñÄÚ²¿Ê±ÖÓ×÷ΪICSÊä³öʱÖÓÔ´*/ + ICS->C1 = ICS->C1 | (ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)) | ICS_C1_CLKS(1); + + /*µÈ´ýʱÖÓÔ´·¢Éú¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(((ICS->S & ICS_S_CLKST_MASK) >> ICS_S_CLKST_SHIFT) != 1);/*ÄÚ²¿Ê±ÖÓ³ÉΪICSÊä³öʱÖÓÔ´*/ + while(!(ICS->S & ICS_S_IREFST_MASK)); /*ÄÚ²¿Ê±ÖÓ³ÉΪFLLµÄ²Î¿¼Ê±ÖÓ*/ + + /* + * ÏÖÔÚICSÊä³öʱÖÓԴΪÄÚ²¿Ê±ÖÓ + */ + +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + + /* + * ½ûÓÃOSCÄ£¿é + */ + OSC_Disable(); +} + + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBEģʽת»»³ÉFEEģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBE_to_FEE(ICS_ConfigType *pConfig) +{ + + /*Ñ¡ÔñFLLÊä³ö×÷ΪÊä³öʱÖÓÔ´*/ + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)); + + /*µÈ´ýICSÊä³öʱÖÓÔ´·¢Éú¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while(ICS->S & ICS_S_CLKST_MASK); + + + /* + * ÏÖÔÚICSÊä³öʱÖÓԴΪFLLÊä³ö + * ×¢ÊÍ: ÍⲿʱÖÓƵÂÊ <= 20MHz + */ +#if defined(CPU_NV32) + /*¶ÔÑ¡ÖеÄICSÊä³öʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /* LOLSÇåÁã */ + ICS->S |= ICS_S_LOLS_MASK; +} + + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBEģʽת±ä³ÉFEIģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBE_to_FEI(ICS_ConfigType *pConfig) +{ + /* Ñ¡ÔñÄÚ²¿Ê±ÖÓ×÷ΪFLLµÄ²Î¿¼Ê±ÖÓ*/ + /*Ñ¡ÔñFLLÊä³ö×öΪICSÊä³öʱÖÓÔ´*/ + + ICS->C1 = ICS->C1 | (ICS_C1_IREFS_MASK); + ICS->C1 = (ICS->C1 & ~(ICS_C1_CLKS_MASK)); + + /*µÈ´ýʱÖÓÔ´¸Ä±ä*/ +#if defined(IAR) + asm( + "nop \n" + "nop \n" + ); +#elif defined(__MWERKS__) + asm{ + nop + nop + }; +#endif + while((ICS->S & ICS_S_CLKST_MASK)); /*FLLÊä³ö³ÉΪICSÊä³öʱÖÓÔ´*/ + while(!(ICS->S & ICS_S_IREFST_MASK)); /*ÄÚ²¿Ê±ÖÓÖгÉΪFLL²Î¿¼Ê±ÖÓ*/ + + /* + * ÏÖÔÚFLLÊä³ö³ÉΪICSÊä³öʱÖÓÔ´ + */ + +#if defined(CPU_NV32) + + /*¶ÔÑ¡ÖеÄʱÖÓÔ´×ö2·ÖƵ*/ + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) != 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(1); + } +#else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); +#endif + /*LOLSÇåÁã*/ + ICS->S |= ICS_S_LOLS_MASK; + + /* + *½ûÓÃOSCÄ£¿é + */ + OSC_Disable(); +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBEģʽת±äΪFBELPģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBE_to_FBELP(ICS_ConfigType *pConfig) +{ + /* enter low power mode */ + /*½øÈëµÍ¹¦ºÄģʽ*/ + ICS->C2 = ICS->C2 | (ICS_C2_LP_MASK); +} +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBELPģʽת»»³ÉFBEģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBELP_to_FBE(ICS_ConfigType *pConfig) +{ + /* enter low power mode */ + /*½ûÓõ͹¦ºÄģʽ*/ + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ½«ICSµÄ¹¤×÷ģʽÓɵ±Ç°µÄFBILPת»»µ½FBIģʽ + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ +void FBILP_to_FBI(ICS_ConfigType *pConfig) +{ + /* enter low power mode */ + /*½ûÓõ͹¦ºÄģʽ*/ + ICS->C2 = ICS->C2 & ~(ICS_C2_LP_MASK); +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª µ÷ÕûÄÚ²¿ÄÚ²¿Ê±ÖÓ (IRC). + * + * @ ²ÎÊý u16TrimValue µ÷ÕûÖµ + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + *****************************************************************************/ + +void ICS_Trim(uint16_t u16TrimValue) +{ + ICS->C3 = (uint8_t) u16TrimValue; /*½«µ÷ÕûֵдÈë¼Ä´æÆ÷*/ + ICS->C4 = (ICS->C4 & ~(ICS_C4_SCFTRIM_MASK)) | ((u16TrimValue>>8) & 0x01); + while(!(ICS->S & ICS_S_LOCK_MASK)); +} +/*****************************************************************************//*! + * + * @ ¸ÅÒª ¶ÔÍⲿ²Î¿¼Ê±ÖÓ½øÐзÖƵ£¬Ê¹µÃ·ÖƵ½á¹ûÔÚFLL¿ÉÒÔËø¶¨µÄ31.25k~39.0625kÄÚ + * + * @ ²ÎÊý u32ClkFreqKHz ²Î¿¼Ê±ÖÓƵÂÊ. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + *****************************************************************************/ + +void ICS_SetClkDivider(uint32_t u32ClkFreqKHz) +{ + + switch(u32ClkFreqKHz) + { + case 8000L: + case 10000L: + /* 8MHz or 10MHz*/ + ICS->C1 = (ICS->C1 & ~(ICS_C1_RDIV_MASK)) | ICS_C1_RDIV(3); + /*8MHz·ÖƵ½á¹ûÊÇ 8000/256 = 31.25K */ + /*10MHz·ÖƵ½á¹ûÊÇ 8000/256 = 31.25K*/ + break; + case 4000L: + /* 4MHz */ + ICS->C1 = (ICS->C1 & ~(ICS_C1_RDIV_MASK)) | ICS_C1_RDIV(2); + /*4MHz·ÖƵ½á¹ûÊÇ 4000/128 = 31.25K*/ + break; + case 12000L: + /* 12MHz */ + ICS->C1 = (ICS->C1 & ~(ICS_C1_RDIV_MASK)) | ICS_C1_RDIV(3); + /*12MHz·ÖƵ½á¹ûÊÇ12000/512 = 23.43K*/ + break; + case 16000L: + /* 16MHz */ + ICS->C1 = (ICS->C1 & ~(ICS_C1_RDIV_MASK)) | ICS_C1_RDIV(4); + /* 16MHz·ÖƵ½á¹ûÊÇ 16000/512 = 31.25K */ + break; + case 20000L: + /* 20MHz */ + ICS->C1 = (ICS->C1 & ~(ICS_C1_RDIV_MASK)) | ICS_C1_RDIV(4); + /*20MHz·ÖƵ½á¹ûÊÇ 20000/512 = 39.0625K */ + break; + case 32L: + /* 32KHz */ + ICS->C1 &= ~(ICS_C1_RDIV_MASK); + break; + default: + break; + } +} +/*****************************************************************************//*! + * + * @ ¸ÅÒª ³õʼ»¯ICSÄ£¿é¸ù¾Ý¶¨ÒåËùÐèÒªµÄ×ÜÏßʱÖÓƵÂÊ. + * + * @ ²ÎÊý pConfig Ö¸ÏòÅäÖýṹÌå. + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_ConfigType + *****************************************************************************/ + + +void ICS_Init(ICS_ConfigType *pConfig) +{ + if(pConfig->u8ClkMode == ICS_CLK_MODE_FEE) + { + pConfig->oscConfig.bIsCryst = 1; /* OSCµÄÊä³öÑ¡ÔñÑ¡ÔñÕñ¶¯Æ÷ʱÖÓÔ´ */ + pConfig->oscConfig.bWaitInit = 1; /* µÈ´ýÕñµ´Æ÷³õʼ»¯»¯Íê³É */ + + /*Ñ¡ÔñFEEģʽ£¬OSCÊä³öÑ¡ÔñÕñµ´Æ÷ʱÖÓÔ´*/ + FEI_to_FEE(pConfig); + } + else if (pConfig->u8ClkMode == ICS_CLK_MODE_FEE_OSC) + { + pConfig->oscConfig.bIsCryst = 0; /*OSCÊä³öʱÖÓÑ¡ÔñEEXTALÒý½ÅµÄÍⲿʱÖÓÔ´*/ + + /*Ñ¡ÔñFEE¹¤×÷ģʽ£»OSCÊä³öʱÖÓÑ¡ÔñEEXTALÒý½ÅµÄÍⲿʱÖÓÔ´*/ + FEI_to_FEE_OSC(pConfig); + } + else if (pConfig->u8ClkMode == ICS_CLK_MODE_FBE_OSC) + { + pConfig->oscConfig.bIsCryst = 0; /* is clock£ºOSCÊä³öʱÖÓÑ¡ÔñEXTALÒý½ÅµÄÍⲿʱÖÓÔ´ */ + /* Ñ¡ÔñFBE¹¤×÷ģʽ£»OSCÊä³öʱÖÓÑ¡ÔñEXTALÒý½ÅµÄÍⲿʱÖÓÔ´*/ + FEI_to_FBE_OSC(pConfig); + } + else if(pConfig->u8ClkMode == ICS_CLK_MODE_FBELP ) + { + pConfig->oscConfig.bIsCryst = 1; /* OSCµÄÊä³öʱÖÓÑ¡ÔñÑ¡ÔñÕñ¶¯Æ÷ʱÖÓÔ´ */ + pConfig->oscConfig.bWaitInit = 1; /*µÈ´ýÕñµ´Æ÷³õʼ»¯»¯Íê³É */ + + /* Ñ¡ÔñFBEģʽ£¬OSCµÄÊä³öʱÖÓÑ¡ÔñÑ¡ÔñÕñ¶¯Æ÷ʱÖÓÔ´*/ + FEI_to_FBE(pConfig); /*ÏÈÑ¡ÔñPBEģʽ*/ + FBE_to_FBELP(pConfig); /*Ñ¡ÔñFBELP*/ + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); + } + else if(pConfig->u8ClkMode == ICS_CLK_MODE_FBILP ) + { + + /* OSCÊä³öʱÖÓÑ¡ÔñEXTALÒý½ÅµÄÍⲿʱÖÓÔ´*/ + pConfig->oscConfig.bIsCryst = 0; + + /* Ñ¡ÔñFBEģʽ£¬OSCÊä³öʱÖÓÑ¡ÔñEXTALÒý½ÅµÄÍⲿʱÖÓÔ´*/ + FEI_to_FBI(pConfig); + FBI_to_FBILP(pConfig); + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); + } + else + { + + /*ICSĬÈϹ¤×÷ģʽFEIģʽ*/ + #if defined(CPU_NV32) + if(((ICS->C2 & ICS_C2_BDIV_MASK)>>5) == 1) + { + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); + } + #else + ICS->C2 = (ICS->C2 & ~(ICS_C2_BDIV_MASK)) | ICS_C2_BDIV(0); + #endif + } + +} +/*****************************************************************************//*! + * + * @ ¸ÅÒª ¶ÔICSÄ£¿é¸÷¼Ä´æÆ÷½øÐи´Î». + * + * @ ÎÞ²ÎÊý + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_Init + *****************************************************************************/ + +void ICS_DeInit(void) +{ + ICS->C1 = ICS_C1_DEFAULT; + ICS->C2 = ICS_C2_DEFAULT; + ICS->C3 = ICS_C3_DEFAULT; + ICS->C4 = ICS_C4_DEFAULT; + while(ICS->S != ICS_S_DEFAULT) + ; +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ͨ¹ýÉ趨µÄ²ÎÊý³õʼ»¯XOSC + * + * @ ²ÎÊý pConfig Ö¸ÏòoscÅäÖýṹÌå + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + *****************************************************************************/ +void OSC_Init(OSC_ConfigType *pConfig) +{ + uint8 cr = 0; + /* + * + */ + if(pConfig->bGain) /*¸ßÔöÒæÕñµ´Æ÷Ñ¡Ôñ*/ + { + /* high gain£ºÑ¡Ôñ¸ßÔöÒæģʽ */ + cr |= OSC_CR_HGO_MASK ; + } + + if(pConfig->bRange) /*ƵÂÊ·¶Î§µÄÑ¡Ôñ*/ + { + cr |= OSC_CR_RANGE_MASK; /*Ñ¡Ôñ¸ßƵ·¶Î§ */ + } + + if(pConfig->bStopEnable) /*ֹͣģʽϵÄOSCʹÄÜ*/ + { + cr |= OSC_CR_OSCSTEN_MASK; /*OSCÔÚֹͣģʽϱ£³ÖʹÄÜ*/ + } + + if(pConfig->bIsCryst) /*OSCÊä³öÑ¡Ôñ*/ + { + cr |= OSC_CR_OSCOS_MASK; /*Ñ¡ÔñÕñµ´Æ÷ʱÖÓ*/ + } + + if(pConfig->bEnable) /*OSCʹÄÜ*/ + { + cr |= OSC_CR_OSCEN_MASK; + } + + OSC->CR = cr; /*ÊýֵдÈë¿ØÖƼĴæÆ÷*/ + + if(pConfig->bWaitInit) + { + + /* + *µÈ´ý³õʼ»¯Íê³É + */ + while(!(OSC->CR & OSC_CR_OSCINIT_MASK)); + + } +} + +/*****************************************************************************//*! + * + * @ ¸ÅÒª ÖØÖÃOSCÄ£¿é£¬Ê¹Æä»Ö¸´µ½Ä¬ÈÏ״̬. + * + * @ ÎÞÊä²ÎÊý + * + * @ ÎÞ·µ»Ø + * + * @ ³É¹¦/ʧ°ÜµÄ±ê×¼ £ºÎÞ + * @ ²Î¿´ ICS_Init + *****************************************************************************/ + +void OSC_DeInit(void) +{ + OSC->CR = OSC_CR_DEFAULT; +} + + + + + diff --git a/bsp/nv32f100x/lib/src/kbi.c b/bsp/nv32f100x/lib/src/kbi.c new file mode 100644 index 0000000000000000000000000000000000000000..263e7341c2e2265f2685e1e1dd11f74e307034c3 --- /dev/null +++ b/bsp/nv32f100x/lib/src/kbi.c @@ -0,0 +1,296 @@ +/****************************************************************************** +* +* @brief providing APIs for configuring KBI. +* +******************************************************************************* +* +* provide APIs for configuring KBI +******************************************************************************/ +#include "common.h" +#include "kbi.h" +/****************************************************************************** +* External objects +******************************************************************************/ + +/****************************************************************************** +* Global variables +******************************************************************************/ +KBI_CallbackType KBI_Callback[KBI_MAX_NO] = {(KBI_CallbackType)NULL}; + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ +/****************************************************************************** +* KBI api list +* +*//*! @addtogroup kbi_api_list +* @{ +*******************************************************************************/ + + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief initialize KBI module. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] pConfig pointer to KBI configuration structure. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_DeInit. +* +*****************************************************************************/ +void KBI_Init(KBI_Type *pKBI, KBI_ConfigType *pConfig) +{ +#if defined(CPU_NV32) + uint16_t i; + uint8_t sc = 0; + uint8_t u8Port; + uint8_t u8PinPos; + uint16_t u16PinMapping[KBI_MAX_NO][8] = + { + { + 0, 1, 2, 3, 8, 9, 10, 11 /* KBI0 pins position in GPIOA register */ + }, + { + 24, 25, 26, 27, 28, 29, 30, 31 /* KBI1 pins position in GPIOA register */ + } + }; +#elif defined(CPU_NV32M3) + uint16_t i; + uint8_t sc = 0; + uint8_t u8Port; + uint8_t u8PinPos; + uint16_t u16PinMapping[KBI_MAX_NO][8] = + { + { + 0, 1, 2, 3, 8, 9, 10, 11 /* KBI0 pins position in GPIOA register */ + }, + { + 20, 21, 16, 17, 18, 19, 12, 13 /* KBI1 pins position in GPIOA register */ + } + }; +#elif defined(CPU_NV32M4) + uint32_t i; + uint32_t sc = 0; + uint32_t u8Port; + uint32_t u8PinPos; + + uint32_t u16PinMapping[KBI_MAX_NO][KBI_MAX_PINS_PER_PORT] = + { + {/* KBI0P0~KBI0P31 pins position in GPIOA register */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 + }, + {/* KBI1P0~KBI1P31 pins position in GPIOB register */ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 + } + }; +#endif + + + if(KBI0 == pKBI) + { + SIM->SCGC |= SIM_SCGC_KBI0_MASK; /* enable clock to KBI0 */\ + u8Port = 0; + } + else if (KBI1 == pKBI) + { + SIM->SCGC |= SIM_SCGC_KBI1_MASK; /* enable clock to KBI1 */ + u8Port = 1; + } + + /* mask keyboard interrupts first */ + sc = pConfig->sBits.bMode; + pKBI->SC = sc; + + /* configure KBI pin polarity and others */ + for (i = 0; i < KBI_MAX_PINS_PER_PORT; i++) + { + if(pConfig->sPin[i].bEn) + { + pKBI->PE |= (1<ES = (pKBI->ES & ~(1<sPin[i].bEdge << i); + u8PinPos = u16PinMapping[u8Port][i]; + ASSERT(!(u8PinPos & 0x80)); + #if defined(CPU_NV32)|| defined(CPU_NV32M3) + FGPIOA->PIDR &= ~(1<PDDR &= ~(1<PUEL |= (1<PIDR &= ~(1<PDDR &= ~(1<PUE0 |= (1<PIDR &= ~(1<PDDR &= ~(1<PUE1 |= (1<sBits.bRstKbsp<SC |= sc; + + /*Real KBI_SP register enable*/ + sc = pConfig->sBits.bKbspEn<SC |= sc; + #endif + + /* write to KBACK to clear any false interrupts */ + pKBI->SC = sc; + + /* enable interrupt if needed */ + if(pConfig->sBits.bIntEn) + { + pKBI->SC |= KBI_SC_KBIE_MASK; + + if(KBI0 == pKBI) + { + NVIC_EnableIRQ(KBI0_IRQn); + } + else + { + NVIC_EnableIRQ(KBI1_IRQn); + } + } +} + +/*****************************************************************************//*! +* +* @brief set up KBI callback routine. +* +* @param[in] pKBI pointer to KBI module. +* @param[in] pfnCallback pointer to callback routine. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +void KBI_SetCallback(KBI_Type *pKBI, KBI_CallbackType pfnCallback) +{ + if(KBI0 == pKBI) + { + KBI_Callback[0] = pfnCallback; + } + else + { + KBI_Callback[1] = pfnCallback; + } +} + +/*****************************************************************************//*! +* +* @brief deinit the kbi module. +* +* @param[in] pKBI pointer to KBI module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see KBI_Init. +* +*****************************************************************************/ +void KBI_DeInit(KBI_Type *pKBI) +{ + if(KBI0 == pKBI) + { + NVIC_DisableIRQ(KBI0_IRQn); + } + else + { + NVIC_DisableIRQ(KBI1_IRQn); + } + + pKBI->PE = 0; + pKBI->SC = 0; + pKBI->ES = 0; + + if(KBI0 == pKBI) + { + SIM->SCGC &= ~SIM_SCGC_KBI0_MASK; /* disable clock to KBI0 */ + } + else + { + SIM->SCGC &= ~SIM_SCGC_KBI1_MASK; /* disable clock to KBI1 */ + } +} + +/*! @} End of acmp_api_list */ + +/*****************************************************************************//*! +* +* @brief button group 0 (KBI0) interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ + +void KBI0_Isr(void) +{ + KBI0->SC |= KBI_SC_KBACK_MASK; /* clear interrupt flag */ + + if(KBI_Callback[0]) + { + KBI_Callback[0](); + } +} + + + +/*****************************************************************************//*! +* +* @brief button group 0 (KBI0) interrupt service routine. +* +* @param none. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ + +void KBI1_Isr(void) +{ + KBI1->SC |= KBI_SC_KBACK_MASK; /* clear interrupt flag */ + + if(KBI_Callback[1]) + { + KBI_Callback[1](); + } +} + diff --git a/bsp/nv32f100x/lib/src/pit.c b/bsp/nv32f100x/lib/src/pit.c new file mode 100644 index 0000000000000000000000000000000000000000..ed3fb2d9244790132c6fd2f9038b45877dc99a2a --- /dev/null +++ b/bsp/nv32f100x/lib/src/pit.c @@ -0,0 +1,213 @@ +/****************************************************************************** +* @brief Periodic Interrupt ETMer (PIT) source code. +* +******************************************************************************/ +#include "common.h" +#include "pit.h" + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ +/*! + * @brief global variable to store PIT callbacks. + * + */ +PIT_CallbackType PIT_Callback[2] = {(PIT_CallbackType)NULL}; /*!< PIT initial callback */ + +/****************************************************************************** +* Local functions +******************************************************************************/ +void PIT_Ch0Isr(void); +void PIT_Ch1Isr(void); + + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define PIT APIs +* +*//*! @addtogroup pit_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief initialize pit module. +* +* @param[in] u8Channel_No channel number +* @param[in] pConfig point to configuration +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void PIT_Init(uint8_t u8Channel_No, PIT_ConfigType *pConfig) +{ + SIM->SCGC |= SIM_SCGC_PIT_MASK; /*!< enable clock to PIT */ + + if (pConfig->bFreeze) + { + PIT_SetDebugFreeze(); + } + + if (pConfig->bModuleDis == 0) + { + PIT_Enable(); /*!< enable pit module */ + } + + PIT_SetLoadVal(u8Channel_No, pConfig->u32LoadValue); + + if (pConfig->bInterruptEn) + { + if (u8Channel_No) + { + NVIC_EnableIRQ(PIT_CH1_IRQn); + } + else + { + NVIC_EnableIRQ(PIT_CH0_IRQn); + } + PIT_ChannelEnableInt(u8Channel_No); + } + else + { + NVIC_DisableIRQ(PIT_CH0_IRQn); + } + + if (pConfig->bChainMode) + { + PIT_ChannelEnableChain(u8Channel_No); + } + + if (pConfig->bETMerEn) + { + PIT_ChannelEnable(u8Channel_No); + } + +} + + +/*****************************************************************************//*! +* +* @brief initialize pit module. +* +* @param[in] u8Channel_No channel number +* @param[in] u32loadvalue load value for pit register +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void PIT_SetLoadVal(uint8_t u8Channel, uint32_t u32loadvalue) + +{ + PIT->CHANNEL[u8Channel].LDVAL = u32loadvalue; +} + + +/*****************************************************************************//*! +* +* @brief pit module set call back. +* +* @param[in] u8Channel_No channel number. +* @param[in] pfnCallback point to call back. +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void PIT_SetCallback(uint8_t u8Channel_No, PIT_CallbackType pfnCallback) +{ + PIT_Callback[u8Channel_No] = pfnCallback; +} + + +/*****************************************************************************//*! +* +* @brief pit module de-initialize, reset pit register +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void PIT_DeInit(void) +{ + NVIC_DisableIRQ(PIT_CH0_IRQn); + NVIC_DisableIRQ(PIT_CH1_IRQn); + PIT_SetLoadVal(0,0); + PIT_SetLoadVal(1,0); + PIT_ChannelDisable(0); + PIT_ChannelDisable(1); + PIT_ChannelDisableInt(0); + PIT_ChannelDisableInt(1); + PIT_ChannelDisableChain(0); + PIT_ChannelDisableChain(1); + PIT_ChannelClrFlags(0); + PIT_ChannelClrFlags(1); + PIT_SetDebugOn(); + PIT_Disable(); + SIM->SCGC &= ~SIM_SCGC_PIT_MASK; +} +/*! @} End of pit_api_list */ + + +/*****************************************************************************//*! +* +* @brief pit module channel 0 isr. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void PIT_Ch0Isr(void) +{ + PIT_ChannelClrFlags(0); + + if (PIT_Callback[0]) + { + PIT_Callback[0](); + } +} + +/*****************************************************************************//*! +* +* @brief pit module channel 1 isr. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void PIT_Ch1Isr(void) +{ + PIT_ChannelClrFlags(1); + if (PIT_Callback[1]) + { + PIT_Callback[1](); + } +} + + diff --git a/bsp/nv32f100x/lib/src/pmc.c b/bsp/nv32f100x/lib/src/pmc.c new file mode 100644 index 0000000000000000000000000000000000000000..2c6a604e833404dee94a9648c7216643b342bccd --- /dev/null +++ b/bsp/nv32f100x/lib/src/pmc.c @@ -0,0 +1,113 @@ + +/****************************************************************************** +* @brief providing APIs for configuring PMC. +* +******************************************************************************* +* +* provide APIs for configuring PMC +******************************************************************************/ +#include "common.h" +#include "pmc.h" + +/****************************************************************************** +* Constants +******************************************************************************/ +/****************************************************************************** +* Macros +******************************************************************************/ +/****************************************************************************** +* Types +******************************************************************************/ +/****************************************************************************** +* Global variables +******************************************************************************/ +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* PMC api list. +* +*//*! @addtogroup pmc_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! +* +* @brief configure PMC with given parameters. +* +* @param[in] pPMC_Config PMC configuration structure. +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_DeInit. +* +*****************************************************************************/ +void PMC_Init(PMC_Type *pPMC, PMC_ConfigType *pPMC_Config) +{ + pPMC->SPMSC1 = pPMC_Config->sCtrlstatus.byte; + pPMC->SPMSC2 = pPMC_Config->sDetectVoltSelect.byte; +} + + +/*****************************************************************************//*! +* +* @brief config the pmc register to the default mode. +* +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +* @see PMC_Init. +* +*****************************************************************************/ +void PMC_DeInit(PMC_Type *pPMC) +{ + pPMC->SPMSC1 = 0x1C; + pPMC->SPMSC2 = 0; +} + + +/*****************************************************************************//*! +* +* @brief config the pmc mode among run, wait and stop modes. +* +* @param[in] u8PmcMode PMC mode select. +* @param[in] pPMC pointer to the PMC module. +* +* @return none. +* +* @ Pass/ Fail criteria: none. +* +*****************************************************************************/ +void PMC_SetMode(PMC_Type *pPMC,uint8_t u8PmcMode) +{ + switch(u8PmcMode & 0x3) + { + case PmcModeRun: + break; + case PmcModeWait: + wait(); + break; + case PmcModeStop4: + /* enable LVD in stop mode */ + pPMC->SPMSC1 |= (PMC_SPMSC1_LVDE_MASK | PMC_SPMSC1_LVDSE_MASK); + stop(); + break; + case PmcModeStop3: + /* disable LVD in stop mode */ + pPMC->SPMSC1 &= ~(PMC_SPMSC1_LVDE_MASK | PMC_SPMSC1_LVDRE_MASK | PMC_SPMSC1_LVDSE_MASK); + stop(); + break; + default: + break; + } + +} + +/*! @} End of pmc_api_list */ + diff --git a/bsp/nv32f100x/lib/src/rtc.c b/bsp/nv32f100x/lib/src/rtc.c new file mode 100644 index 0000000000000000000000000000000000000000..960fbae8a402c7076fac1e6e902bb29f121018d1 --- /dev/null +++ b/bsp/nv32f100x/lib/src/rtc.c @@ -0,0 +1,165 @@ +/****************************************************************************** +* @brief Real-ETMe counter (RTC) driver source code. +* +******************************************************************************/ +#include "common.h" +#include "rtc.h" + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ +/*! + * @brief global variable to store RTC callbacks. + * + */ +RTC_CallbackType RTC_Callback[1] = {(RTC_CallbackType)NULL}; /*!< RTC initial callback */ + +/****************************************************************************** +* Local functions +******************************************************************************/ +void RTC_Isr(void); + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define RTC APIs +* +*//*! @addtogroup rtc_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief inital RTC module +* +* @param[in] pConfig point to configuration +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void RTC_Init(RTC_ConfigType *pConfig) +{ + uint16_t u16Clocksource, u16Prescler; + uint16_t u16ModVal; + + u16Clocksource =0; + u16Prescler =0; + u16ModVal =0; + + SIM->SCGC |= SIM_SCGC_RTC_MASK; + + u16ModVal = pConfig->u16ModuloValue; + RTC_SetModulo(u16ModVal); + + if (pConfig->bRTCOut) + { + + RTC->SC= RTC_SC_RTCO_MASK; + } + + if (pConfig->bInterruptEn) + { + NVIC_EnableIRQ(RTC_IRQn); + RTC_EnableInt(); + } + else + { + NVIC_DisableIRQ(RTC_IRQn); + } + + if (pConfig->bFlag) + { + RTC_ClrFlags(); + } + + u16Clocksource = pConfig->bClockSource; + u16Prescler = pConfig->bClockPresaler; + + RTC_SetClock(u16Clocksource,u16Prescler ); +} + + + +/*****************************************************************************//*! +* +* @brief set call back function for rtc module +* +* @param[in] pfnCallback point to call back function +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void RTC_SetCallback(RTC_CallbackType pfnCallback) +{ + RTC_Callback[0] = pfnCallback; +} + + +/*****************************************************************************//*! +* +* @brief de-initialize rtc module , reset rtc register +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void RTC_DeInit(void) +{ + NVIC_DisableIRQ(RTC_IRQn); + RTC->MOD = 0; + while(RTC->MOD); + + if(RTC_GetFlags()) + { + RTC_ClrFlags(); + } + + RTC->SC = 0; + while(RTC->SC); + SIM->SCGC &= ~SIM_SCGC_RTC_MASK; +} + +/*! @} End of rtc_api_list */ + +/*****************************************************************************//*! +* +* @brief RTC module interrupt service routine +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void RTC_Isr(void) +{ + RTC_ClrFlags(); + if (RTC_Callback[0]) + { + RTC_Callback[0](); + } +} + + diff --git a/bsp/nv32f100x/lib/src/sim.c b/bsp/nv32f100x/lib/src/sim.c new file mode 100644 index 0000000000000000000000000000000000000000..1273b7ee7474fe229fc9dfdf63b7817492708c8d --- /dev/null +++ b/bsp/nv32f100x/lib/src/sim.c @@ -0,0 +1,348 @@ + +/****************************************************************************** +* +* @brief providing APIs for system integration module (SIM). +* +******************************************************************************* +* +* provide APIs for SIM +******************************************************************************/ +#include "common.h" +#include "sim.h" + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define SIM API list +* +*//*! @addtogroup sim_api_list +* @{ +*******************************************************************************/ +#if defined(CPU_NV32) +/*****************************************************************************//*! + * + * @brief initialize SIM registers. + * + * @param[in] pConfig pointer to SIM configuration. + * + * @return none + * + * @ Pass/ Fail criteria: none + * @see SIM_ConfigType + *****************************************************************************/ +void SIM_Init(SIM_ConfigType *pConfig) +{ + uint32_t u32Sopt; + uint32_t u32PinSel; + uint32_t u32Scgc; + uint32_t u32BusDiv; + /* + * intialize the registers to reset default values + */ + u32Sopt = 0x0010000E; /* enable SWD, RESET, and NMI pins */ + u32PinSel = 0; + u32Scgc = 0x00003000; /* enable SWD and FLASH */ + u32BusDiv = 0; + u32BusDiv = pConfig->sBits.bBusDiv; + if(pConfig->sBits.bDisableNMI) + { + u32Sopt &= ~SIM_SOPT_NMIE_MASK; + } + if(pConfig->sBits.bDisableRESET) + { + u32Sopt &= ~SIM_SOPT_RSTPE_MASK; + } + if(pConfig->sBits.bDisableSWD) + { + u32Sopt &= ~SIM_SOPT_SWDE_MASK; + } + if(pConfig->sBits.bEnableCLKOUT) + { + u32Sopt |= SIM_SOPT_CLKOE_MASK; + } + if(pConfig->sBits.bETMSYNC) + { + u32Sopt |= SIM_SOPT_ETMSYNC_MASK; + } + if(pConfig->sBits.bRXDCE) + { + u32Sopt |= SIM_SOPT_RXDCE_MASK; + } + if(pConfig->sBits.bTXDME) + { + u32Sopt |= SIM_SOPT_TXDME_MASK; + } + if(pConfig->sBits.bACIC) + { + u32Sopt |= SIM_SOPT_ACIC_MASK; + } + if(pConfig->sBits.bRTCC) + { + u32Sopt |= SIM_SOPT_RTCC_MASK; + } + if(pConfig->sBits.bRXDFE) + { + u32Sopt |= SIM_SOPT_RXDFE_MASK; + } + u32Sopt |= ((pConfig->u8BusRef & 0x07) << 16); + u32Sopt |= ((pConfig->u8Delay) << 24); + u32Sopt |= ((pConfig->sBits.u8ADHWT & 0x03) << 8); + u32PinSel = pConfig->u32PinSel; + u32Scgc = pConfig->u32SCGC; + +/* write SIM registers */ + SIM->SOPT = u32Sopt; + SIM->PINSEL = u32PinSel; + SIM->SCGC = u32Scgc; + SIM->BUSDIV = u32BusDiv; +} +#elif defined(CPU_NV32M3) +/*****************************************************************************//*! + * + * @brief initialize SIM registers. + * + * @param[in] pConfig pointer to SIM configuration. + * + * @return none + * + * @ Pass/ Fail criteria: none + * @see SIM_ConfigType + *****************************************************************************/ + +void SIM_Init(SIM_ConfigType *pConfig) +{ + uint32_t u32Sopt; + uint32_t u32PinSel; + uint32_t u32Scgc; + uint32_t u32ClockDiv; + /* + * intialize the registers to reset default values + */ + u32Sopt = 0x0010000E; /* enable SWD, RESET, and NMI pins */ + u32PinSel = 0; + u32Scgc = 0x00003000; /* enable SWD and FLASH */ + u32ClockDiv = 0; + u32ClockDiv = pConfig->u32CLKDIV; + if(pConfig->sBits.bDisableNMI) + { + u32Sopt &= ~SIM_SOPT_NMIE_MASK; + } + if(pConfig->sBits.bDisableRESET) + { + u32Sopt &= ~SIM_SOPT_RSTPE_MASK; + } + if(pConfig->sBits.bDisableSWD) + { + u32Sopt &= ~SIM_SOPT_SWDE_MASK; + } + if(pConfig->sBits.bEnableCLKOUT) + { + u32Sopt |= SIM_SOPT_CLKOE_MASK; + } + if(pConfig->sBits.bETMSYNC) + { + u32Sopt |= SIM_SOPT_ETMSYNC_MASK; + } + if(pConfig->sBits.bRXDCE) + { + u32Sopt |= SIM_SOPT_RXDCE_MASK; + } + if(pConfig->sBits.bTXDME) + { + u32Sopt |= SIM_SOPT_TXDME_MASK; + } + if(pConfig->sBits.bACTRG) + { + u32Sopt |= SIM_SOPT_ACTRG_MASK; + } + u32Sopt |= ((pConfig->u8BusRef & 0x07) << 16); + u32Sopt |= ((pConfig->u8Delay) << 24); + u32Sopt |= ((pConfig->sBits.u8ADHWT & 0x07) << 20); + u32Sopt |= ((pConfig->sBits.bRXDFE)&0x03<<8); + u32Sopt |= ((pConfig->sBits.bETMIC)&0x03<<6); + + u32PinSel = pConfig->u32PinSel; + u32Scgc = pConfig->u32SCGC; +/* write SIM registers */ + SIM->SOPT = u32Sopt; + SIM->PINSEL = u32PinSel; + SIM->SCGC = u32Scgc; + SIM->CLKDIV = u32ClockDiv; +} +#elif defined(CPU_NV32M4) +/*****************************************************************************//*! + * + * @brief initialize SIM registers. + * + * @param[in] pConfig pointer to SIM configuration. + * + * @return none + * + * @ Pass/ Fail criteria: none + * @see SIM_ConfigType + *****************************************************************************/ +void SIM_Init(SIM_ConfigType *pConfig) +{ + uint32_t u32Sopt; + uint32_t u32PinSel; + uint32_t u32Scgc; + uint32_t u32ClockDiv; + /* + * intialize the registers to reset default values + */ + u32Sopt = 0x0E; /* enable SWD, RESET, and NMI pins */ + u32PinSel = 0; + u32Scgc = 0x00003000; /* enable SWD and FLASH */ + u32ClockDiv = 0; + u32ClockDiv = pConfig->u32CLKDIV; + if(pConfig->sBits.bDisableNMI) + { + u32Sopt &= ~SIM_SOPT0_NMIE_MASK; + } + if(pConfig->sBits.bDisableRESET) + { + u32Sopt &= ~SIM_SOPT0_RSTPE_MASK; + } + if(pConfig->sBits.bDisableSWD) + { + u32Sopt &= ~SIM_SOPT0_SWDE_MASK; + } + if(pConfig->sBits.bEnableCLKOUT) + { + u32Sopt |= SIM_SOPT0_CLKOE_MASK; + } + if(pConfig->sBits.bETMSYNC) + { + u32Sopt |= SIM_SOPT0_ETMSYNC_MASK; + } + if(pConfig->sBits.bRXDCE) + { + u32Sopt |= SIM_SOPT0_RXDCE_MASK; + } + if(pConfig->sBits.bTXDME) + { + u32Sopt |= SIM_SOPT0_TXDME_MASK; + } + if(pConfig->sBits.bACTRG) + { + u32Sopt |= SIM_SOPT0_ACTRG_MASK; + } + u32Sopt |= ((pConfig->u8BusRef & 0x07) << 16); + u32Sopt |= ((pConfig->u8Delay) << 24); + u32Sopt |= ((pConfig->sBits.u8ADHWT & 0x07) << 20); + u32Sopt |= ((pConfig->sBits.bRXDFE)&0x03<<8); + //u32Sopt |= ((pConfig->sBits.bETMIC)&0x03<<6); + + u32PinSel = pConfig->u32PinSel; + u32Scgc = pConfig->u32SCGC; +/* write SIM registers */ + SIM->SOPT0 = u32Sopt; + SIM->PINSEL = u32PinSel; + SIM->SCGC = u32Scgc; + SIM->CLKDIV = u32ClockDiv; +} +#endif + +/*****************************************************************************//*! + * + * @brief set SIM clock gating registers to enable or disable peripheral clocks. + * + * @param[in] u32PeripheralMask peripherial bits mask. + * @param[in] u8GateOn 1: ON, 0: OFF. + * + * @return none + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + +void SIM_SetClockGating(uint32_t u32PeripheralMask, uint8_t u8GateOn) +{ + uint32_t u32Scgc; + + /* + * save original clock gating value + */ + u32Scgc = SIM->SCGC; + + if(u8GateOn) + { + u32Scgc |= u32PeripheralMask; + } + else + { + u32Scgc &= ~u32PeripheralMask; + } + + SIM->SCGC = u32Scgc; +} + + +/*****************************************************************************//*! + * + * @brief read the corresponding status flags. + * + * @param[in] u32StatusMask indicates which status to be read. + * + * @return status. + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ +uint32_t SIM_GetStatus(uint32_t u32StatusMask) +{ + uint32_t u32Status; + + u32Status = SIM->SRSID & u32StatusMask; + return (u32Status); +} + +/*****************************************************************************//*! + * + * @brief read the corresponding ID. + * + * @param[in] u8ID type of ID. + * + * @return ID + * + * @ Pass/ Fail criteria: none. + * @see IDType. + *****************************************************************************/ +uint8_t SIM_ReadID(IDType sID) +{ + uint32_t u32ID; + uint8_t u8IDOffset[4] = + { + 28, 24, 20,16 + }; + u32ID = (SIM->SRSID >> u8IDOffset[sID]) & 0x0F; + return (u32ID); +} +/*! @} End of sim_api_list */ + + + diff --git a/bsp/nv32f100x/lib/src/spi.c b/bsp/nv32f100x/lib/src/spi.c new file mode 100644 index 0000000000000000000000000000000000000000..a48293f3af751e6b21a75136b0f629b73ebfa348 --- /dev/null +++ b/bsp/nv32f100x/lib/src/spi.c @@ -0,0 +1,329 @@ + +/****************************************************************************** +* @brief providing APIs for configuring SPI module (SPI). +* +******************************************************************************* +* +* provide APIs for configuring SPI module (SPI). +******************************************************************************/ +#include "common.h" +#include "spi.h" + + +/****************************************************************************** +* Local variables +******************************************************************************/ + +SPI_CallbackType SPI_Callback[MAX_SPI_NO] = {(SPI_CallbackType)NULL}; + + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local functions +*****************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define SPI APIs +* +*//*! @addtogroup spi_api_list +* @{ +*******************************************************************************/ +/*****************************************************************************//*! + * + * @brief initialize SPI as per params. + * + * @param[in] pSPI point to SPI module type. + * @param[in] pConfig point to configuration parameters. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +void SPI_Init(SPI_Type *pSPI, SPI_ConfigType *pConfig) +{ +#if defined(CPU_NV32M3) + /* sanity check */ + ASSERT((pSPI == SPI0)); + SIM->SCGC |= SIM_SCGC_SPI0_MASK; +#else + /* sanity check */ + ASSERT((pSPI == SPI0) || (pSPI == SPI1)); + + /* enable SPI clock gating on */ + if( pSPI == SPI0) + { + SIM->SCGC |= SIM_SCGC_SPI0_MASK; + } + else + { + SIM->SCGC |= SIM_SCGC_SPI1_MASK; + } +#endif + /* configure other control bits */ + if( pConfig->sSettings.bIntEn) + { + SPI_IntEnable(pSPI); +#if defined(CPU_NV32M3) + NVIC_EnableIRQ(SPI0_IRQn); +#else + if( pSPI == SPI0 ) + { + NVIC_EnableIRQ(SPI0_IRQn); + } + else + { + NVIC_EnableIRQ(SPI1_IRQn); + } +#endif + } + + if( pConfig->sSettings.bTxIntEn) + { + SPI_TxIntEnable(pSPI); +#if defined(CPU_NV32M3) + NVIC_EnableIRQ(SPI0_IRQn); +#else + if( pSPI == SPI0 ) + { + NVIC_EnableIRQ(SPI0_IRQn); + } + else + { + NVIC_EnableIRQ(SPI1_IRQn); + } +#endif + } + if( pConfig->sSettings.bMasterMode) + { + SPI_SetMasterMode(pSPI); + } + else + { + SPI_SetSlaveMode(pSPI); + } + + if( pConfig->sSettings.bClkPolarityLow) + { + SPI_SetClockPol(pSPI,1); + } + if( pConfig->sSettings.bClkPhase1) + { + SPI_SetClockPhase(pSPI,1); + }else + { + SPI_SetClockPhase(pSPI,0); + } + if( pConfig->sSettings.bShiftLSBFirst) + { + SPI_SetLSBFirst(pSPI); + } + if( pConfig->sSettings.bMatchIntEn) + { + SPI_MatchIntEnable(pSPI); + } + if( pConfig->sSettings.bModeFaultEn) + { + SPI_ModfEnable(pSPI); + } + if( pConfig->sSettings.bMasterAutoDriveSS) + { + /* set both SSOE and MODFEN bits when auto drive slave SS is enabled */ + SPI_SSOutputEnable(pSPI); + SPI_ModfEnable(pSPI); + } + + if( pConfig->sSettings.bPinAsOuput) + { + SPI_BidirPinEnable(pSPI); + } + + if( pConfig->sSettings.bBidirectionModeEn) + { + SPI_BidirOutEnable(pSPI); + } + if( pConfig->sSettings.bStopInWaitMode) + { + SPI_ClockStopEnable(pSPI); + } + + if(pConfig->sSettings.bMasterMode) + { + SPI_SetBaudRate(pSPI,pConfig->u32BusClkHz,pConfig->u32BitRate); + } + + /* enable SPI module */ + if( pConfig->sSettings.bModuleEn) + { + SPI_Enable(pSPI); + } +} + +/*****************************************************************************//*! + * + * @brief SPI set band rate. + * + * @param[in] pSPI point to SPI module type. + * @param[in] u32BusClock Bus clock. + * @param[in] u32Bps set spi's baudrate. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +void SPI_SetBaudRate(SPI_Type *pSPI,uint32_t u32BusClock,uint32_t u32Bps) +{ + uint32_t u32BitRateDivisor; + uint8_t u8Sppr; + uint8_t u8Spr; + uint8_t u8ReadFlag; + u32BitRateDivisor = u32BusClock/u32Bps; /* calculate bit rate divisor */ + + u8ReadFlag = 0; + /* find best fit SPPR and SPR */ + for (u8Spr = 0; u8Spr <= 8; u8Spr++) + { + for(u8Sppr = 0; u8Sppr <= 7; u8Sppr++) + { + if((u32BitRateDivisor>>(u8Spr+1))<=(u8Sppr+1)) + { + u8ReadFlag = 1; + break; + } + } + if(u8ReadFlag) + { + break; + } + } + if(u8Sppr >=8) + { + u8Sppr = 7; + } + if(u8Spr >8) + { + u8Spr = 8; + } + /* set bit rate */ + pSPI->BR = SPI_BR_SPPR(u8Sppr) | SPI_BR_SPR(u8Spr); +} + +/*****************************************************************************//*! + * + * @brief implement write data to SPI. + * + * @param[in] pSPI pointer to SPI module type. + * @param[in] pWrBuff -- write data buffer pointer. + * @param[in] uiLength -- read/write data length. + * @param[out] pRdBuff -- read data buffer pointer. + * + * @return if <0, means error, 0: success. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +ResultType SPI_TransferWait(SPI_Type *pSPI, SPI_WidthType* pRdBuff, SPI_WidthType *pWrBuff,uint32 uiLength) +{ + ResultType err = SPI_ERR_SUCCESS; + uint32_t i; + + if(!uiLength) + { + return (err); + } + for(i = 0; i < uiLength; i++) + { + while(!SPI_IsSPTEF(pSPI)); + SPI_WriteDataReg(pSPI,pWrBuff[i]); + while(!SPI_IsSPRF(pSPI)); + pRdBuff[i] = SPI_ReadDataReg(pSPI); + } + return (err); +} + + + +/*****************************************************************************//*! + * + * @brief Deinitialize SPI to the default state (reset value). + * + * @param[in] pSPI pointer to SPI module type. + * + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ +void SPI_DeInit(SPI_Type *pSPI) +{ + int16 i; + pSPI->C1 = SPI_C1_DEFAULT; + pSPI->C2 = SPI_C2_DEFAULT; + pSPI->BR = SPI_BR_DEFAULT; + pSPI->M = SPI_M_DEFAULT; + for(i = 0; i<100; i++); /* wait for some cycles for the ISR exit */ +} + +/*****************************************************************************//*! + * + * @brief set up SPI callback routines to be called by interrupt service routine. + * + * @param[in] pSPI pointer to SPI module type. + * @param[in] pfnCallback callback routine. + * + * @return none. + * + * @ Pass/ Fail criteria: none. +*****************************************************************************/ +void SPI_SetCallback(SPI_Type *pSPI,SPI_CallbackType pfnCallback) +{ + uint32_t u32Port = ((uint32_t)pSPI-(uint32_t)SPI0)>>12; + ASSERT(u32Port <2); + SPI_Callback[u32Port] = pfnCallback; +} + +/*! @} End of spi_api_list */ + + +/*****************************************************************************//*! + * + * @brief SPI0 interrupt service routine. + * + * @param none. + * @return none. + * + * @ Pass/ Fail criteria: none. + *****************************************************************************/ + +void SPI0_Isr(void) +{ + if( SPI_Callback[0] ) + { + SPI_Callback[0](); + } +} +#ifndef CPU_NV32M3 +/*****************************************************************************//*! + * + * @brief SPI1 interrupt service routine. + * + * @param none. + * @return none. + * + * @ Pass/ Fail criteria: none + *****************************************************************************/ + +void SPI1_Isr(void) +{ + if( SPI_Callback[1] ) + { + SPI_Callback[1](); + } +} +#endif + + diff --git a/bsp/nv32f100x/lib/src/startup_NV32.s b/bsp/nv32f100x/lib/src/startup_NV32.s new file mode 100644 index 0000000000000000000000000000000000000000..269adeedf71817f9e4caa2c45dbbd34fc7c8c1b3 --- /dev/null +++ b/bsp/nv32f100x/lib/src/startup_NV32.s @@ -0,0 +1,347 @@ +;/***************************************************************************** +; * @file: startup_NV32.s +; * @purpose: CMSIS Cortex-M0plus Core Device Startup File for the +; * NV32F100 +;* +; *------- <<< Use Configuration Wizard in Context Menu >>> ------------------ +; * +; *****************************************************************************/ + + +; 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 Handler + DCD NMI_Handler ; NMI Handler + DCD 0 ; Reserved + 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 Handler + DCD 0 ; Reserved + DCD 0 ; Reserved + DCD PendSV_Handler ; PendSV Handler + DCD SysTick_Handler ; SysTick Handler + + ; External Interrupts + DCD Reserved16_IRQHandler ; Reserved interrupt 16 + DCD Reserved17_IRQHandler ; Reserved interrupt 17 + DCD Reserved18_IRQHandler ; Reserved interrupt 18 + DCD Reserved19_IRQHandler ; Reserved interrupt 19 + DCD Reserved20_IRQHandler ; Reserved interrupt 20 + DCD ETMRH_IRQHandler ; ETMRH command complete/read collision interrupt + DCD LVD_LVW_IRQHandler ; Low Voltage Detect, Low Voltage Warning + DCD IRQ_IRQHandler ; External interrupt + DCD I2C0_IRQHandler ; I2C0 interrupt + DCD Reserved25_IRQHandler ; Reserved interrupt 25 + DCD SPI0_IRQHandler ; SPI0 interrupt + DCD SPI1_IRQHandler ; SPI1 interrupt + DCD UART0_IRQHandler ; UART0 status/error interrupt + DCD UART1_IRQHandler ; UART1 status/error interrupt + DCD UART2_IRQHandler ; UART2 status/error interrupt + DCD ADC0_IRQHandler ; ADC0 interrupt + DCD ACMP0_IRQHandler ; ACMP0 interrupt + DCD ETM0_IRQHandler ; ETM0 Single interrupt vector for all sources + DCD ETM1_IRQHandler ; ETM1 Single interrupt vector for all sources + DCD ETM2_IRQHandler ; ETM2 Single interrupt vector for all sources + DCD RTC_IRQHandler ; RTC overflow + DCD ACMP1_IRQHandler ; ACMP1 interrupt + DCD PIT_CH0_IRQHandler ; PIT CH0 overflow + DCD PIT_CH1_IRQHandler ; PIT CH1 overflow + DCD KBI0_IRQHandler ; Keyboard interrupt 0 + DCD KBI1_IRQHandler ; Keyboard interrupt 1 + DCD Reserved42_IRQHandler ; Reserved interrupt 42 + DCD ICS_IRQHandler ; MCG interrupt + DCD Watchdog_IRQHandler ; WDOG Interrupt + DCD Reserved45_IRQHandler ; Reserved interrupt 45 + DCD Reserved46_IRQHandler ; Reserved interrupt 46 + DCD Reserved47_IRQHandler ; Reserved interrupt 47 +__Vectors_End + +__Vectors_Size EQU __Vectors_End - __Vectors + +; Flash Configuration +; 16-byte flash configuration field that stores default protection settings (loaded on reset) +; and security information that allows the MCU to restrict acces to the FTFL module. +; Backdoor Comparison Key +; Backdoor Key 0 <0x0-0xFF:2> +; Backdoor Key 1 <0x0-0xFF:2> +; Backdoor Key 2 <0x0-0xFF:2> +; Backdoor Key 3 <0x0-0xFF:2> +; Backdoor Key 4 <0x0-0xFF:2> +; Backdoor Key 5 <0x0-0xFF:2> +; Backdoor Key 6 <0x0-0xFF:2> +; Backdoor Key 7 <0x0-0xFF:2> +BackDoorK0 EQU 0xFF +BackDoorK1 EQU 0xFF +BackDoorK2 EQU 0xFF +BackDoorK3 EQU 0xFF +BackDoorK4 EQU 0xFF +BackDoorK5 EQU 0xFF +BackDoorK6 EQU 0xFF +BackDoorK7 EQU 0xFF +; +; EEPROM Protection Register (EEPROT) +; The DFPROT register defines which D-Flash sectors are protected against program and erase operations. +; DPOPEN +; <0=> Enables EEPROM memory protection +; <1=> Disables EEPROM memory protection +; DPS +; <0=> Flash address range: 0x00_0000 - 0x00_001F; protected size: 32 bytes +; <1=> Flash address range: 0x00_0000 - 0x00_003F; protected size: 64 bytes +; <2=> Flash address range: 0x00_0000 - 0x00_005F; protected size: 96 bytes +; <3=> Flash address range: 0x00_0000 - 0x00_007F; protected size: 128 bytes +; <4=> Flash address range: 0x00_0000 - 0x00_009F; protected size: 160 bytes +; <5=> Flash address range: 0x00_0000 - 0x00_00BF; protected size: 192 bytes +; <6=> Flash address range: 0x00_0000 - 0x00_00DF; protected size: 224 bytes +; <7=> Flash address range: 0x00_0000 - 0x00_00FF; protected size: 256 bytes +EEPROT EQU 0xFF +; +; FPROT +; P-Flash Protection Register +; FPOPEN +; <0=> FPHDIS and FPLDIS bits define unprotected address ranges as specified by the corresponding FPHS and FPLS bits FPROT1.1 +; <1=> FPHDIS and FPLDIS bits enable protection for the address range specified by the corresponding FPHS and FPLS bits +; FPHDIS +; <0=> Protection/Unprotection enabled +; <1=> Protection/Unprotection disabled +; FPHS +; <0=> Address range: 0x00_7C00-0x00_7FFF; protected size: 1 KB +; <1=> Address range: 0x00_7800-0x00_7FFF; protected size: 2 KB +; <2=> Address range: 0x00_7000-0x00_7FFF; protected size: 4 KB +; <3=> Address range: 0x00_6000-0x00_7FFF; protected size: 8 KB +; FPLDIS +; <0=> Protection/Unprotection enabled +; <1=> Protection/Unprotection disabled +; FPLS +; <0=> Address range: 0x00_0000-0x00_07FF; protected size: 2 KB +; <1=> Address range: 0x00_0000-0x00_0FFF; protected size: 4 KB +; <2=> Address range: 0x00_0000-0x00_1FFF; protected size: 8 KB +; <3=> Address range: 0x00_0000-0x00_3FFF; protected size: 16 KB +FPROT EQU 0xFF +; +; +; Flash security byte (FSEC) +; WARNING: If SEC field is configured as "MCU security status is secure" and MEEN field is configured as "Mass erase is disabled", +; MCU's security status cannot be set back to unsecure state since Mass erase via the debugger is blocked !!! +; SEC +; <2=> MCU security status is unsecure +; <3=> MCU security status is secure +; Flash Security +; This bits define the security state of the MCU. +; KEYEN +; <2=> Backdoor key access enabled +; <3=> Backdoor key access disabled +; Backdoor key Security Enable +; These bits enable and disable backdoor key access to the FTFL module. +FSEC EQU 0xFE +; +; Flash Option Register (FOPT) +FOPT EQU 0xFE +; + IF :LNOT::DEF:RAM_TARGET + AREA |.ARM.__at_0x400|, CODE, READONLY + DCB BackDoorK0, BackDoorK1, BackDoorK2, BackDoorK3 + DCB BackDoorK4, BackDoorK5, BackDoorK6, BackDoorK7 + DCB 0xFF, 0xFF, 0xFF, 0xFF + DCB EEPROT, FPROT, FSEC, FOPT ;Modified by ARM. DCB FPROT, EEPROT, FOPT, FSEC + ENDIF + + AREA |.text|, CODE, READONLY + + +; Reset Handler + +Reset_Handler PROC + EXPORT Reset_Handler [WEAK] + IMPORT SystemInit + IMPORT __main + 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 +MemManage_Handler\ + PROC + EXPORT MemManage_Handler [WEAK] + B . + ENDP +BusFault_Handler\ + PROC + EXPORT BusFault_Handler [WEAK] + B . + ENDP +UsageFault_Handler\ + PROC + EXPORT UsageFault_Handler [WEAK] + B . + ENDP +SVC_Handler PROC + EXPORT SVC_Handler [WEAK] + B . + ENDP +DebugMon_Handler\ + PROC + EXPORT DebugMon_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 Reserved16_IRQHandler [WEAK] + EXPORT Reserved17_IRQHandler [WEAK] + EXPORT Reserved18_IRQHandler [WEAK] + EXPORT Reserved19_IRQHandler [WEAK] + EXPORT Reserved20_IRQHandler [WEAK] + EXPORT ETMRH_IRQHandler [WEAK] + EXPORT LVD_LVW_IRQHandler [WEAK] + EXPORT IRQ_IRQHandler [WEAK] + EXPORT I2C0_IRQHandler [WEAK] + EXPORT Reserved25_IRQHandler [WEAK] + EXPORT SPI0_IRQHandler [WEAK] + EXPORT SPI1_IRQHandler [WEAK] + EXPORT UART0_IRQHandler [WEAK] + EXPORT UART1_IRQHandler [WEAK] + EXPORT UART2_IRQHandler [WEAK] + EXPORT ADC0_IRQHandler [WEAK] + EXPORT ACMP0_IRQHandler [WEAK] + EXPORT ETM0_IRQHandler [WEAK] + EXPORT ETM1_IRQHandler [WEAK] + EXPORT ETM2_IRQHandler [WEAK] + EXPORT RTC_IRQHandler [WEAK] + EXPORT ACMP1_IRQHandler [WEAK] + EXPORT PIT_CH0_IRQHandler [WEAK] + EXPORT PIT_CH1_IRQHandler [WEAK] + EXPORT KBI0_IRQHandler [WEAK] + EXPORT KBI1_IRQHandler [WEAK] + EXPORT Reserved42_IRQHandler [WEAK] + EXPORT ICS_IRQHandler [WEAK] + EXPORT Watchdog_IRQHandler [WEAK] + EXPORT Reserved45_IRQHandler [WEAK] + EXPORT Reserved46_IRQHandler [WEAK] + EXPORT Reserved47_IRQHandler [WEAK] + EXPORT DefaultISR [WEAK] + +Reserved16_IRQHandler +Reserved17_IRQHandler +Reserved18_IRQHandler +Reserved19_IRQHandler +Reserved20_IRQHandler +ETMRH_IRQHandler +LVD_LVW_IRQHandler +IRQ_IRQHandler +I2C0_IRQHandler +Reserved25_IRQHandler +SPI0_IRQHandler +SPI1_IRQHandler +UART0_IRQHandler +UART1_IRQHandler +UART2_IRQHandler +ADC0_IRQHandler +ACMP0_IRQHandler +ETM0_IRQHandler +ETM1_IRQHandler +ETM2_IRQHandler +RTC_IRQHandler +ACMP1_IRQHandler +PIT_CH0_IRQHandler +PIT_CH1_IRQHandler +KBI0_IRQHandler +KBI1_IRQHandler +Reserved42_IRQHandler +ICS_IRQHandler +Watchdog_IRQHandler +Reserved45_IRQHandler +Reserved46_IRQHandler +Reserved47_IRQHandler +DefaultISR + + 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 diff --git a/bsp/nv32f100x/lib/src/uart.c b/bsp/nv32f100x/lib/src/uart.c new file mode 100644 index 0000000000000000000000000000000000000000..0159628ea06a05d046c947ddff92eb85894b6ff0 --- /dev/null +++ b/bsp/nv32f100x/lib/src/uart.c @@ -0,0 +1,459 @@ +/****************************************************************************** +* @brief providing common UART API. +* +******************************************************************************/ +#include "uart.h" + +/****************************************************************************** +* Local variables +******************************************************************************/ +UART_CallbackType UART_Callback = NULL; +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local functions +*****************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define UART APIs +* +*//*! @addtogroup uart_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief initialize the UART, interrupts disabled, and no hardware flow-control. +* +* @param[in] pUART base of UART port +* @param[in] pConfig pointer to UART configuration structure +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +void UART_Init(UART_Type *pUART, UART_ConfigType *pConfig) +{ + uint16_t u16Sbr; + uint8_t u8Temp; + uint32_t u32SysClk = pConfig->u32SysClkHz; + uint32_t u32Baud = pConfig->u32Baudrate; + + /* Sanity check */ + ASSERT((pUART == UART0) || (pUART == UART1) || (pUART == UART2)); + + /* Enable the clock to the selected UART */ + if (pUART == UART0) + { + SIM->SCGC |= SIM_SCGC_UART0_MASK; + } +#if defined(CPU_NV32) | defined(CPU_NV326) + else if (pUART == UART1) + { + SIM->SCGC |= SIM_SCGC_UART1_MASK; + } + else + { + SIM->SCGC |= SIM_SCGC_UART2_MASK; + } +#endif + /* Make sure that the transmitter and receiver are disabled while we + * change settings. + */ + pUART->C2 &= ~(UART_C2_TE_MASK | UART_C2_RE_MASK ); + + /* Configure the UART for 8-bit mode, no parity */ + pUART->C1 = 0; + + /* Calculate baud settings */ + u16Sbr = (((u32SysClk)>>4) + (u32Baud>>1))/u32Baud; + + /* Save off the current value of the UARTx_BDH except for the SBR field */ + u8Temp = pUART->BDH & ~(UART_BDH_SBR_MASK); + + pUART->BDH = u8Temp | UART_BDH_SBR(u16Sbr >> 8); + pUART->BDL = (uint8_t)(u16Sbr & UART_BDL_SBR_MASK); + + /* Enable receiver and transmitter */ + pUART->C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK ); +} + +/*****************************************************************************//*! +* +* @brief receive a character. +* +* @param[in] pUART base of UART port +* +* @return unsigned char +* +*****************************************************************************/ +uint8_t UART_GetChar(UART_Type *pUART) +{ + + /* Sanity check */ + ASSERT((pUART == UART0) || (pUART == UART1) || (pUART == UART2)); + + /* Wait until character has been received */ + while (!(pUART->S1 & UART_S1_RDRF_MASK)); + + /* Return the 8-bit data from the receiver */ + return pUART->D; +} +/*****************************************************************************//*! +* +* @brief send a character. +* +* @param[in] pUART base of UART port +* @param[in] u8Char char to send +* +* @return none +* +*****************************************************************************/ +void UART_PutChar(UART_Type *pUART, uint8_t u8Char) +{ + /* Wait until space is available in the FIFO */ + while (!(pUART->S1 & UART_S1_TDRE_MASK)); + + /* Send the character */ + pUART->D = (uint8_t)u8Char; +} + +/*****************************************************************************//*! +* +* @brief set baudrate. +* +* @param[in] pUART base of UART port +* @param[in] pConfig baudrate config parameters +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +void UART_SetBaudrate(UART_Type *pUART, UART_ConfigBaudrateType *pConfig) +{ + uint8_t u8Temp; + uint16_t u16Sbr; + uint32_t u32SysClk = pConfig->u32SysClkHz; + uint32_t u32baud = pConfig->u32Baudrate; + + /* Sanity check */ + ASSERT((pUART == UART0) || (pUART == UART1) || (pUART == UART2)); + + /* Calculate baud settings */ + u16Sbr = (((u32SysClk)>>4) + (u32baud>>1))/u32baud; + + /* Save off the current value of the UARTx_BDH except for the SBR field */ + u8Temp = pUART->BDH & ~(UART_BDH_SBR_MASK); + + pUART->BDH = u8Temp | UART_BDH_SBR(u16Sbr >> 8); + pUART->BDL = (uint8_t)(u16Sbr & UART_BDL_SBR_MASK); + + /* Enable receiver and transmitter */ + pUART->C2 |= (UART_C2_TE_MASK | UART_C2_RE_MASK ); + +} + +/*****************************************************************************//*! +* +* @brief enable interrupt. +* +* @param[in] pUART base of UART port +* @param[in] InterruptType interrupt type +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +void UART_EnableInterrupt(UART_Type *pUART, UART_InterruptType InterruptType) +{ + + /* Sanity check */ + ASSERT((pUART == UART0) || (pUART == UART1) || (pUART == UART2)); + + if (InterruptType == UART_TxBuffEmptyInt) + { + pUART->C2 |= UART_C2_TIE_MASK; + } + else if (InterruptType == UART_TxCompleteInt) + { + pUART->C2 |= UART_C2_TCIE_MASK; + } + else if (InterruptType == UART_RxBuffFullInt) + { + pUART->C2 |= UART_C2_RIE_MASK; + } + else if (InterruptType == UART_IdleLineInt) + { + pUART->C2 |= UART_C2_ILIE_MASK; + } + else if (InterruptType == UART_RxOverrunInt) + { + pUART->C3 |= UART_C3_ORIE_MASK; + } + else if (InterruptType == UART_NoiseErrorInt) + { + pUART->C3 |= UART_C3_NEIE_MASK; + } + else if (InterruptType == UART_FramingErrorInt) + { + pUART->C3 |= UART_C3_FEIE_MASK; + } + else if (InterruptType == UART_ParityErrorInt) + { + pUART->C3 |= UART_C3_FEIE_MASK; + } + else + { + /* un-supported Interrupt type */ + } +} + +/*****************************************************************************//*! +* +* @brief disable interrupt. +* +* @param[in] pUART base of UART port +* @param[in] InterruptType interrupt type +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +void UART_DisableInterrupt(UART_Type *pUART, UART_InterruptType InterruptType) +{ + /* Sanity check */ + ASSERT((pUART == UART0) || (pUART == UART1) || (pUART == UART2)); + + + if (InterruptType == UART_TxBuffEmptyInt) + { + pUART->C2 &= (~UART_C2_TIE_MASK); + } + else if (InterruptType == UART_TxCompleteInt) + { + pUART->C2 &= (~UART_C2_TCIE_MASK); + } + else if (InterruptType == UART_RxBuffFullInt) + { + pUART->C2 &= (~UART_C2_RIE_MASK); + } + else if (InterruptType == UART_IdleLineInt) + { + pUART->C2 &= (~UART_C2_ILIE_MASK); + } + else if (InterruptType == UART_RxOverrunInt) + { + pUART->C3 &= (~UART_C3_ORIE_MASK); + } + else if (InterruptType == UART_NoiseErrorInt) + { + pUART->C3 &= (~UART_C3_NEIE_MASK); + } + else if (InterruptType == UART_FramingErrorInt) + { + pUART->C3 &= (~UART_C3_FEIE_MASK); + } + else if (InterruptType == UART_ParityErrorInt) + { + pUART->C3 &= (~UART_C3_FEIE_MASK); + } + else + { + /* un-supported interrupt type */ + } +} + + +/*****************************************************************************//*! +* +* @brief get flags from 2 UART status registers. +* +* @param[in] pUART base of UART port +* +* @return 16-bit flags +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +uint16_t UART_GetFlags(UART_Type *pUART) +{ + uint16_t u16StatusFlags = 0; + + u16StatusFlags = pUART->S2; + u16StatusFlags = (u16StatusFlags<<8)| pUART->S1; + + return u16StatusFlags; +} +/*****************************************************************************//*! +* +* @brief check whether the specified flag is set. +* +* @param[in] pUART base of UART port +* @param[in] FlagType flag type +* +* @return +* 1, flag is set +* 0, flag is clear +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ +uint8_t UART_CheckFlag(UART_Type *pUART, UART_FlagType FlagType) +{ + uint16_t u16StatusFlags = 0; + + u16StatusFlags = UART_GetFlags(pUART); + + return (u16StatusFlags & (1<>12; + UART_Callback = pfnCallback; +} + + +/*! @} End of uart_api_list */ + + +/*****************************************************************************//*! +* +* @brief uart0 interrupt service routine. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +void UART0_Isr(void) +{ + UART_Callback(UART0); +} + + +#if defined(CPU_NV32) | defined(CPU_NV326) +/*****************************************************************************//*! +* +* @brief uart1 interrupt service routine. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +void UART1_Isr(void) +{ + UART_Callback(UART1); +} +/*****************************************************************************//*! +* +* @brief uart2 interrupt service routine. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: +*****************************************************************************/ +void UART2_Isr(void) +{ + UART_Callback(UART2); +} + + +#endif + + + diff --git a/bsp/nv32f100x/lib/src/wdog.c b/bsp/nv32f100x/lib/src/wdog.c new file mode 100644 index 0000000000000000000000000000000000000000..bf17e65037b84884d02f0ca75e7bf052f339e5e0 --- /dev/null +++ b/bsp/nv32f100x/lib/src/wdog.c @@ -0,0 +1,324 @@ + +/****************************************************************************** +* +* @brief Provide common watchdog module routines. +* +* @history: +* Jun. 25, 2013 modified the watch dog unlock sequence and disable sequence +******************************************************************************/ +#include "common.h" +#include "wdog.h" + +/****************************************************************************** +* Global variables +******************************************************************************/ + +/****************************************************************************** +* Constants and macros +******************************************************************************/ + +/****************************************************************************** +* Local types +******************************************************************************/ + +/****************************************************************************** +* Local function prototypes +******************************************************************************/ + +/****************************************************************************** +* Local variables +******************************************************************************/ + +/****************************************************************************** +* Local functions +******************************************************************************/ + +/****************************************************************************** +* Global functions +******************************************************************************/ + +/****************************************************************************** +* define watchdog API list +* +*//*! @addtogroup wdog_api_list +* @{ +*******************************************************************************/ + +/*****************************************************************************//*! +* +* @brief Watchdog ETMer disable routine. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see WDOG_Enable +*****************************************************************************/ + +void WDOG_Disable(void) +{ + uint8_t u8Cs1 = WDOG->CS1; + uint8_t u8Cs2 = WDOG->CS2; + uint16_t u16TOVAL = WDOG->TOVAL; + uint16_t u16WIN = WDOG->WIN; + + u8Cs1 &= ~WDOG_CS1_EN_MASK; + + /* First unlock the watchdog so that we can write to registers */ + WDOG_Unlock(); + WDOG->CS2 = u8Cs2; + WDOG->TOVAL = u16TOVAL; + WDOG->WIN = u16WIN; + WDOG->CS1 = u8Cs1; +} + + +/*****************************************************************************//*! +* +* @brief Watchdog ETMer disable routine with update enabled. +* +* Disable watchdog but the watchdog can be enabled and updated later. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see WDOG_Enable +*****************************************************************************/ + +void WDOG_DisableWDOGEnableUpdate(void) +{ + uint8_t u8Cs1 = WDOG->CS1; + uint8_t u8Cs2 = WDOG->CS2; + uint16_t u16TOVAL = WDOG->TOVAL; + uint16_t u16WIN = WDOG->WIN; + + u8Cs1 &= ~WDOG_CS1_EN_MASK; + u8Cs1 |= WDOG_CS1_UPDATE_MASK; + + /* First unlock the watchdog so that we can write to registers */ + //WDOG_Unlock(); + WDOG->CS2 = u8Cs2; + WDOG->TOVAL = u16TOVAL; + WDOG->WIN = u16WIN; + WDOG->CS1 = u8Cs1; +} + +/*****************************************************************************//*! +* +* @brief Watchdog ETMer enable routine. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @see WDOG_Disable +*****************************************************************************/ + +void WDOG_Enable(void) +{ + uint8_t u8Cs1 = WDOG->CS1; + + u8Cs1 |= WDOG_CS1_EN_MASK; + + /* First unlock the watchdog so that we can write to registers */ + WDOG_Unlock(); + WDOG->CS1 = u8Cs1; +} + + +/*****************************************************************************//*! +* +* @brief initialize watchdog. +* +* @param[in] pConfig poiner to watchdog configuration strcture. +* +* @return none +* +* @ Pass/ Fail criteria: none +* +* @warning make sure that WDOG is not initialized after reset or WDOG update is enabled +* after reset by calling WDOG_EnableUpdate / WDOG_DisableWDOGEnableUpdate. +* +* @see WDOG_EnableUpdate, WDOG_DisableWDOGEnableUpdate +* +*****************************************************************************/ + +void WDOG_Init(WDOG_ConfigPtr pConfig) +{ + uint8_t u8Cs1; + uint8_t u8Cs2; + uint16_t u16Toval; + uint16_t u16Win; + + u8Cs1 = 0x80; /* default CS1 register value */ + u8Cs2 = 0; + u16Toval = pConfig->u16ETMeOut; + u16Win = pConfig->u16WinETMe; + + if(pConfig->sBits.bDisable) + { + u8Cs1 &= ~WDOG_CS1_EN_MASK; + } + if(pConfig->sBits.bIntEnable) + { + u8Cs1 |= WDOG_CS1_INT_MASK; + } + if(pConfig->sBits.bStopEnable) + { + u8Cs1 |= WDOG_CS1_STOP_MASK; + } + if(pConfig->sBits.bDbgEnable) + { + u8Cs1 |= WDOG_CS1_DBG_MASK; + } + if(pConfig->sBits.bWaitEnable) + { + u8Cs1 |= WDOG_CS1_WAIT_MASK; + } + if(pConfig->sBits.bUpdateEnable) + { + u8Cs1 |= WDOG_CS1_UPDATE_MASK; + } + if(pConfig->sBits.bWinEnable) + { + u8Cs2 |= WDOG_CS2_WIN_MASK; + } + if(pConfig->sBits.bPrescaler) + { + u8Cs2 |= WDOG_CS2_PRES_MASK; + } + u8Cs2 |= (pConfig->sBits.bClkSrc & 0x03); + + /* write regisers */ + WDOG_Unlock(); /* unlock watchdog first */ + WDOG->CS2 = u8Cs2; + + WDOG->TOVAL8B.TOVALL = u16Toval; + WDOG->TOVAL8B.TOVALH = u16Toval >> 8; + + WDOG->WIN8B.WINL = u16Win; + WDOG->WIN8B.WINH = u16Win >> 8; + + WDOG->CS1 = u8Cs1; +} + + +/*****************************************************************************//*! +* +* @brief initialize watchdog to the default state. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @warning make sure that WDOG update is enabled after reset by calling WDOG_EnableUpdate. +* or by calling WDOG_DisableWDOGEnableUpdate. +* +* @see WDOG_DisableWDOGEnableUpdate, WDOG_EnableUpdate +* +*****************************************************************************/ + +void WDOG_DeInit(void) +{ + WDOG_Unlock(); + + WDOG->CS2 = WDOG_CS2_DEFAULT_VALUE; + WDOG->TOVAL = WDOG_TOVAL_DEFAULT_VALUE; + WDOG->WIN = WDOG_WIN_DEFAULT_VALUE; + WDOG->CS1 = WDOG_CS1_DEFAULT_VALUE; +} + +/*****************************************************************************//*! +* +* @brief feed/refresh watchdog. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +*****************************************************************************/ + +void WDOG_Feed(void) +{ + DisableInterrupts; + WDOG->CNT = 0x02A6; + WDOG->CNT = 0x80B4; + EnableInterrupts; +} + + + +/*****************************************************************************//*! +* +* @brief enable update of WDOG. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @warning this must be the last step of writing control bits sequence. +*****************************************************************************/ + +void WDOG_EnableUpdate(void) +{ + uint8_t u8Cs1 = WDOG->CS1; + uint8_t u8Cs2 = WDOG->CS2; + uint16_t u16TOVAL = WDOG->TOVAL; + uint16_t u16WIN = WDOG->WIN; + + u8Cs1 |= WDOG_CS1_UPDATE_MASK; + + /* First unlock the watchdog so that we can write to registers */ + WDOG_Unlock(); + WDOG->CS2 = u8Cs2; + WDOG->TOVAL = u16TOVAL; + WDOG->WIN = u16WIN; + WDOG->CS1 = u8Cs1; +} + + +/*****************************************************************************//*! +* +* @brief disable update of WDOG. +* +* @param none +* +* @return none +* +* @ Pass/ Fail criteria: none +* @warning this must be the last step of writing control bits sequence. +*****************************************************************************/ + +void WDOG_DisableUpdate(void) +{ + uint8_t u8Cs1 = WDOG->CS1; + uint8_t u8Cs2 = WDOG->CS2; + uint16_t u16TOVAL = WDOG->TOVAL; + uint16_t u16WIN = WDOG->WIN; + + u8Cs1 &= ~WDOG_CS1_UPDATE_MASK; + + /* First unlock the watchdog so that we can write to registers */ + WDOG_Unlock(); + WDOG->CS2 = u8Cs2; + WDOG->TOVAL = u16TOVAL; + WDOG->WIN = u16WIN; + WDOG->CS1 = u8Cs1; + +} + + +/********************************************************************/ + +/*! @} End of wdog_api_list */ + + + + diff --git a/bsp/nv32f100x/project.uvprojx b/bsp/nv32f100x/project.uvprojx new file mode 100644 index 0000000000000000000000000000000000000000..96d97f3ba2daf9df10c93eb7a5b5b477274785cb --- /dev/null +++ b/bsp/nv32f100x/project.uvprojx @@ -0,0 +1,711 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + nv32f100x + 0x4 + ARM-ADS + 5060183::V5.06 update 2 (build 183)::ARMCC + + + NV32F100FS16E + Navota MCU + Keil.NV32F100_DFP.1.0 + http://www.keil.com/pack/ + IRAM(0x1FFFF800,0x2000) IROM(0x00000000,0x20000) IROM2(0x00400000,0x1400) CPUTYPE("Cortex-M0+") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD1FFFF800 -FC2000 -FN2 -FF0nv32f100_128 -FS00 -FL020000 -FF1nv32f100_nvr -FS1400000 -FL11400 -FP0($$Device:NV32F100FS16E$Flash\nv32f100_128.FLM) -FP1($$Device:NV32F100FS16E$Flash\nv32f100_nvr.FLM)) + 0 + $$Device:NV32F100FS16E$Device\Include\nv32f100.h + + + + + + + + + + $$Device:NV32F100FS16E$SVD\nv32f100S16.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\output\ + nv32f100x + 1 + 0 + 0 + 1 + 1 + C:\Users\HF00\Documents\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 1 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 0 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0+ + SARMCM3.DLL + + TARMCM1.DLL + -pCM0+ + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4103 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0+" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 1 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x1ffff800 + 0x2000 + + + 1 + 0x0 + 0x20000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x20000 + + + 1 + 0x400000 + 0x1400 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x1ffff800 + 0x2000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + + + NV32, KEIL + + app\inc;.;board\inc;lib\inc;..\..\include;..\..\libcpu\arm\cortex-m0;..\..\libcpu\arm\common;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\drivers\spi;..\..\components\drivers\include;..\..\components\drivers\include;..\..\components\finsh + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0x08000000 + 0x20000000 + + + + + --keep *.o(.rti_fn.*) --keep *.o(FSymTab) + + + + + + + + Applications + + + main.c + 1 + .\app\src\main.c + + + ledapp.c + 1 + app\src\ledapp.c + + + + + Drivers + + + board.c + 1 + board\src\board.c + + + drv_spi.c + 1 + board\src\drv_spi.c + + + drv_uart.c + 1 + board\src\drv_uart.c + + + start.c + 1 + board\src\start.c + + + sysinit.c + 1 + board\src\sysinit.c + + + + + Lib + + + acmp.c + 1 + lib\src\acmp.c + + + adc.c + 1 + lib\src\adc.c + + + arm_cm0.c + 1 + lib\src\arm_cm0.c + + + crc.c + 1 + lib\src\crc.c + + + eeprom.c + 1 + lib\src\eeprom.c + + + etm.c + 1 + lib\src\etm.c + + + flash.c + 1 + lib\src\flash.c + + + gpio.c + 1 + lib\src\gpio.c + + + i2c.c + 1 + lib\src\i2c.c + + + ics.c + 1 + lib\src\ics.c + + + kbi.c + 1 + lib\src\kbi.c + + + pit.c + 1 + lib\src\pit.c + + + pmc.c + 1 + lib\src\pmc.c + + + rtc.c + 1 + lib\src\rtc.c + + + sim.c + 1 + lib\src\sim.c + + + spi.c + 1 + lib\src\spi.c + + + uart.c + 1 + lib\src\uart.c + + + wdog.c + 1 + lib\src\wdog.c + + + startup_NV32.s + 2 + lib\src\startup_NV32.s + + + + + Kernel + + + clock.c + 1 + ..\..\src\clock.c + + + components.c + 1 + ..\..\src\components.c + + + device.c + 1 + ..\..\src\device.c + + + idle.c + 1 + ..\..\src\idle.c + + + ipc.c + 1 + ..\..\src\ipc.c + + + irq.c + 1 + ..\..\src\irq.c + + + kservice.c + 1 + ..\..\src\kservice.c + + + mem.c + 1 + ..\..\src\mem.c + + + object.c + 1 + ..\..\src\object.c + + + scheduler.c + 1 + ..\..\src\scheduler.c + + + thread.c + 1 + ..\..\src\thread.c + + + timer.c + 1 + ..\..\src\timer.c + + + + + CORTEX-M0 + + + cpuport.c + 1 + ..\..\libcpu\arm\cortex-m0\cpuport.c + + + context_rvds.S + 2 + ..\..\libcpu\arm\cortex-m0\context_rvds.S + + + backtrace.c + 1 + ..\..\libcpu\arm\common\backtrace.c + + + div0.c + 1 + ..\..\libcpu\arm\common\div0.c + + + showmem.c + 1 + ..\..\libcpu\arm\common\showmem.c + + + + + DeviceDrivers + + + pin.c + 1 + ..\..\components\drivers\misc\pin.c + + + serial.c + 1 + ..\..\components\drivers\serial\serial.c + + + spi_core.c + 1 + ..\..\components\drivers\spi\spi_core.c + + + spi_dev.c + 1 + ..\..\components\drivers\spi\spi_dev.c + + + completion.c + 1 + ..\..\components\drivers\src\completion.c + + + dataqueue.c + 1 + ..\..\components\drivers\src\dataqueue.c + + + pipe.c + 1 + ..\..\components\drivers\src\pipe.c + + + portal.c + 1 + ..\..\components\drivers\src\portal.c + + + ringbuffer.c + 1 + ..\..\components\drivers\src\ringbuffer.c + + + workqueue.c + 1 + ..\..\components\drivers\src\workqueue.c + + + + + finsh + + + shell.c + 1 + ..\..\components\finsh\shell.c + + + symbol.c + 1 + ..\..\components\finsh\symbol.c + + + cmd.c + 1 + ..\..\components\finsh\cmd.c + + + msh.c + 1 + ..\..\components\finsh\msh.c + + + msh_cmd.c + 1 + ..\..\components\finsh\msh_cmd.c + + + msh_file.c + 1 + ..\..\components\finsh\msh_file.c + + + + + + + +
diff --git a/bsp/nv32f100x/rtconfig.h b/bsp/nv32f100x/rtconfig.h new file mode 100644 index 0000000000000000000000000000000000000000..0279e205ae2e13fd67328616b7869290386e5ae9 --- /dev/null +++ b/bsp/nv32f100x/rtconfig.h @@ -0,0 +1,101 @@ +/* RT-Thread config file */ +#ifndef __RTTHREAD_CFG_H__ +#define __RTTHREAD_CFG_H__ + +/* RT_NAME_MAX*/ +#define RT_NAME_MAX 8 + +/* RT_ALIGN_SIZE*/ +#define RT_ALIGN_SIZE 4 + +/* PRIORITY_MAX */ +#define RT_THREAD_PRIORITY_MAX 32 + +/* Tick per Second */ +#define RT_TICK_PER_SECOND 1000 + +/* SECTION: RT_DEBUG */ +/* Thread Debug */ +//#define RT_DEBUG +//#define RT_DEBUG_INIT 1 +//#define RT_USING_OVERFLOW_CHECK + +/* Using Hook */ +/* #define RT_USING_HOOK */ + +/* Using Software Timer */ +/* #define RT_USING_TIMER_SOFT */ +#define RT_TIMER_THREAD_PRIO 4 +#define RT_TIMER_THREAD_STACK_SIZE 512 +#define RT_TIMER_TICK_PER_SECOND 10 + +/* SECTION: IPC */ +/* Using Semaphore*/ +#define RT_USING_SEMAPHORE + +/* Using Mutex */ +#define RT_USING_MUTEX + +/* Using Event */ +#define RT_USING_EVENT + +/* Using MailBox */ +/* #define RT_USING_MAILBOX */ + +/* Using Message Queue */ +/* #define RT_USING_MESSAGEQUEUE */ + +/* SECTION: Memory Management */ +/* Using Memory Pool Management*/ +/* #define RT_USING_MEMPOOL */ + +/* Using Dynamic Heap Management */ +#define RT_USING_HEAP + +/* Using Small MM */ +#define RT_USING_SMALL_MEM +#define RT_USING_TINY_SIZE + +// +#define RT_USING_COMPONENTS_INIT + +/* SECTION: Device System */ +/* Using Device System */ +#define RT_USING_DEVICE +// +#define RT_USING_DEVICE_IPC +// +#define RT_USING_SERIAL +#define RT_USING_HOOK +#define RT_USING_CPU_USAGE +/* SECTION: Console options */ +#define RT_USING_CONSOLE +#define RT_USING_RTTTERMINAL +/* the buffer size of console*/ +#define RT_CONSOLEBUF_SIZE 128 +// +#define RT_CONSOLE_DEVICE_NAME "uart0" + + +/* SECTION: finsh, a C-Express shell */ +#define RT_USING_FINSH +#define RT_FINSHPROMRT_SIZE 16 +/* configure finsh parameters */ +#define FINSH_THREAD_PRIORITY 25 +#define FINSH_THREAD_STACK_SIZE 512 +#define FINSH_HISTORY_LINES 1 +/* Using symbol table */ +#define FINSH_USING_SYMTAB +//#define FINSH_USING_DESCRIPTION +#define FINSH_USING_MSH +#define FINSH_USING_MSH_ONLY + +#define RT_USING_PIN +#define RT_USING_SPI +#define RT_DBG_APP + +#define RT_USING_UART0 + +#define RT_USING_USER_MAIN + +#endif diff --git a/bsp/nv32f100x/rtconfig.py b/bsp/nv32f100x/rtconfig.py new file mode 100644 index 0000000000000000000000000000000000000000..6927eee3ab869614cfad6d4b65e2f7c4d39aa63c --- /dev/null +++ b/bsp/nv32f100x/rtconfig.py @@ -0,0 +1,126 @@ +import os + +# toolchains options +ARCH='arm' +CPU='cortex-m0' +CROSS_TOOL='gcc' + +if os.getenv('RTT_CC'): + CROSS_TOOL = os.getenv('RTT_CC') + +# cross_tool provides the cross compiler +# EXEC_PATH is the compiler execute path, for example, CodeSourcery, Keil MDK, IAR +if CROSS_TOOL == 'gcc': + PLATFORM = 'gcc' + EXEC_PATH = 'G:/iot/camera_studio-win32-20160903/camera_studio/tools/arm-2014.05/bin' +elif CROSS_TOOL == 'keil': + print '================ERROR============================' + print 'Not support iar yet!' + print '=================================================' + exit(0) +elif CROSS_TOOL == 'iar': + print '================ERROR============================' + print 'Not support iar yet!' + print '=================================================' + exit(0) + +if os.getenv('RTT_EXEC_PATH'): + EXEC_PATH = os.getenv('RTT_EXEC_PATH') + +#BUILD = 'debug' +BUILD = 'release' +NV32_TYPE = 'NV32F100X' + +if PLATFORM == 'gcc': + # toolchains + PREFIX = 'arm-none-eabi-' + CC = PREFIX + 'gcc' + AS = PREFIX + 'gcc' + AR = PREFIX + 'ar' + LINK = PREFIX + 'gcc' + TARGET_EXT = 'axf' + SIZE = PREFIX + 'size' + OBJDUMP = PREFIX + 'objdump' + OBJCPY = PREFIX + 'objcopy' + + DEVICE = ' -mcpu=cortex-m0 -mthumb -ffunction-sections -fdata-sections' + CFLAGS = DEVICE + ' -DNV32F100X' + ' -DNULL=0' + AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' + LFLAGS = DEVICE + ' -Wl,--gc-sections,-Map=rtthread-nv32.map,-cref,-u,Reset_Handler -T nv32_rom.ld' + + CPATH = '' + LPATH = '' + + if BUILD == 'debug': + CFLAGS += ' -O0 -gdwarf-2' + AFLAGS += ' -gdwarf-2' + else: + CFLAGS += ' -O2' + + POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n' + +elif PLATFORM == 'armcc': + # toolchains + CC = 'armcc' + AS = 'armasm' + AR = 'armar' + LINK = 'armlink' + TARGET_EXT = 'axf' + + DEVICE = ' --device DARMSTM' + CFLAGS = DEVICE + ' --apcs=interwork' + AFLAGS = DEVICE + LFLAGS = DEVICE + ' --info sizes --info totals --info unused --info veneers --list rtthread-nv32.map --scatter nv32_rom.sct' + + CFLAGS += ' -I./' + + EXEC_PATH += '/ARM/bin/' + + if BUILD == 'debug': + CFLAGS += ' -g -O0' + AFLAGS += ' -g' + else: + CFLAGS += ' -O2' + + POST_ACTION = 'fromelf --bin $TARGET --output rtthread.bin \nfromelf -z $TARGET' + +elif PLATFORM == 'iar': + # toolchains + CC = 'iccarm' + AS = 'iasmarm' + AR = 'iarchive' + LINK = 'ilinkarm' + TARGET_EXT = 'out' + + CFLAGS = DEVICE + CFLAGS += ' --diag_suppress Pa050' + CFLAGS += ' --no_cse' + CFLAGS += ' --no_unroll' + CFLAGS += ' --no_inline' + CFLAGS += ' --no_code_motion' + CFLAGS += ' --no_tbaa' + CFLAGS += ' --no_clustering' + CFLAGS += ' --no_scheduling' + CFLAGS += ' --debug' + CFLAGS += ' --endian=little' + CFLAGS += ' --cpu=Cortex-M0' + CFLAGS += ' -e' + CFLAGS += ' --fpu=None' + CFLAGS += ' --dlib_config "' + IAR_PATH + '/arm/INC/c/DLib_Config_Normal.h"' + CFLAGS += ' -Ol' + CFLAGS += ' --use_c++_inline' + + AFLAGS = '' + AFLAGS += ' -s+' + AFLAGS += ' -w+' + AFLAGS += ' -r' + AFLAGS += ' --cpu Cortex-M0' + AFLAGS += ' --fpu None' + + LFLAGS = ' --config nv32f100x_flash.icf' + LFLAGS += ' --redirect _Printf=_PrintfTiny' + LFLAGS += ' --redirect _Scanf=_ScanfSmall' + LFLAGS += ' --entry __iar_program_start' + + EXEC_PATH = IAR_PATH + '/arm/bin/' + POST_ACTION = '' diff --git a/bsp/nv32f100x/template.uvprojx b/bsp/nv32f100x/template.uvprojx new file mode 100644 index 0000000000000000000000000000000000000000..bab53d35cc367e655fec3c80b4ba5bc80c60354b --- /dev/null +++ b/bsp/nv32f100x/template.uvprojx @@ -0,0 +1,379 @@ + + + + 2.1 + +
### uVision Project, (C) Keil Software
+ + + + nv32f100x + 0x4 + ARM-ADS + 5060183::V5.06 update 2 (build 183)::ARMCC + + + NV32F100FS16E + Navota MCU + Keil.NV32F100_DFP.1.0 + http://www.keil.com/pack/ + IRAM(0x1FFFF800,0x2000) IROM(0x00000000,0x20000) IROM2(0x00400000,0x1400) CPUTYPE("Cortex-M0+") CLOCK(12000000) ELITTLE + + + UL2CM3(-S0 -C0 -P0 -FD1FFFF800 -FC2000 -FN2 -FF0nv32f100_128 -FS00 -FL020000 -FF1nv32f100_nvr -FS1400000 -FL11400 -FP0($$Device:NV32F100FS16E$Flash\nv32f100_128.FLM) -FP1($$Device:NV32F100FS16E$Flash\nv32f100_nvr.FLM)) + 0 + $$Device:NV32F100FS16E$Device\Include\nv32f100.h + + + + + + + + + + $$Device:NV32F100FS16E$SVD\nv32f100S16.svd + 0 + 0 + + + + + + + 0 + 0 + 0 + 0 + 1 + + .\output\ + nv32f100x + 1 + 0 + 0 + 1 + 1 + C:\Users\HF00\Documents\ + 1 + 0 + 0 + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + + 0 + 0 + + + 0 + 0 + 0 + 0 + + 1 + + + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 3 + + + 0 + + + SARMCM3.DLL + + DARMCM1.DLL + -pCM0+ + SARMCM3.DLL + + TARMCM1.DLL + -pCM0+ + + + + 1 + 0 + 0 + 0 + 16 + + + + + 1 + 0 + 0 + 1 + 1 + 4103 + + 1 + BIN\UL2CM3.DLL + + + + + + 0 + + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 1 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + "Cortex-M0+" + + 0 + 0 + 0 + 1 + 1 + 0 + 0 + 0 + 0 + 1 + 8 + 1 + 0 + 0 + 0 + 3 + 3 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 1 + 0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x1ffff800 + 0x2000 + + + 1 + 0x0 + 0x20000 + + + 0 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x0 + + + 1 + 0x0 + 0x20000 + + + 1 + 0x400000 + 0x1400 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x0 + 0x0 + + + 0 + 0x1ffff800 + 0x2000 + + + 0 + 0x0 + 0x0 + + + + + + 1 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 2 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 1 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + 1 + 0 + 0 + 0 + 0 + 0 + 0x08000000 + 0x20000000 + + + + + --keep *.o(.rti_fn.*) --keep *.o(FSymTab) + + + + + + + + +