From 4cfeca08e1158aab99f37385fbed1f25fd3038e8 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sun, 12 Jul 2015 13:57:15 +0200 Subject: [PATCH] ARM: get serial working based on MBED code. Pretty complex, this MBED system, it requires no less than 24 additional files. This will be fleshd out before too long. SIZES ARM... lpc1114 FLASH : 5956 bytes 19% RAM : 176 bytes 5% EEPROM : 0 bytes 0% --- Makefile-ARM | 6 +- cpu-arm.c | 6 +- mbed-LPC11xx.h | 614 ++++++++++++++ mbed-PeripheralNames.h | 77 ++ mbed-PinNames.h | 246 ++++++ mbed-PortNames.h | 42 + mbed-bitfields.h | 1777 ++++++++++++++++++++++++++++++++++++++++ mbed-cmsis.h | 26 + mbed-cmsis_nvic.h | 63 ++ mbed-core_cm0.h | 694 ++++++++++++++++ mbed-core_cmFunc.h | 645 +++++++++++++++ mbed-core_cmInstr.h | 697 ++++++++++++++++ mbed-device.h | 71 ++ mbed-error.c | 49 ++ mbed-gpio_object.h | 66 ++ mbed-mbed_assert.h | 59 ++ mbed-mbed_error.h | 75 ++ mbed-objects.h | 86 ++ mbed-pinmap.c | 62 ++ mbed-pinmap.h | 55 ++ mbed-pinmap_common.c | 85 ++ mbed-serial_api.c | 319 ++++++++ mbed-serial_api.h | 91 ++ mbed-system_LPC11xx.c | 383 +++++++++ mbed-system_LPC11xx.h | 76 ++ mbed-toolchain.h | 44 + mendel.c | 2 + serial-arm.c | 16 +- 28 files changed, 6423 insertions(+), 9 deletions(-) create mode 100644 mbed-LPC11xx.h create mode 100644 mbed-PeripheralNames.h create mode 100644 mbed-PinNames.h create mode 100644 mbed-PortNames.h create mode 100644 mbed-bitfields.h create mode 100644 mbed-cmsis.h create mode 100644 mbed-cmsis_nvic.h create mode 100644 mbed-core_cm0.h create mode 100644 mbed-core_cmFunc.h create mode 100644 mbed-core_cmInstr.h create mode 100644 mbed-device.h create mode 100644 mbed-error.c create mode 100644 mbed-gpio_object.h create mode 100644 mbed-mbed_assert.h create mode 100644 mbed-mbed_error.h create mode 100644 mbed-objects.h create mode 100644 mbed-pinmap.c create mode 100644 mbed-pinmap.h create mode 100644 mbed-pinmap_common.c create mode 100644 mbed-serial_api.c create mode 100644 mbed-serial_api.h create mode 100644 mbed-system_LPC11xx.c create mode 100644 mbed-system_LPC11xx.h create mode 100644 mbed-toolchain.h diff --git a/Makefile-ARM b/Makefile-ARM index 049d4de..24ec955 100644 --- a/Makefile-ARM +++ b/Makefile-ARM @@ -97,7 +97,11 @@ TARGET = $(PROGRAM).hex #SOURCES = $(wildcard *.c) # Until the generic ARM port is completed, we'd have to wrap all sources # in #ifdef __AVR__. To avoid this, build only a selection for now: -SOURCES = mendel.c cpu.c serial.c +SOURCES = mendel.c cpu.c serial.c +SOURCES += mbed-serial_api.c mbed-pinmap.c mbed-pinmap_common.c mbed-error.c +ifeq ($(MCU), lpc1114) + SOURCES += mbed-system_LPC11xx.c +endif # Other target MCU specific adjustments: diff --git a/cpu-arm.c b/cpu-arm.c index 4400000..1febeac 100644 --- a/cpu-arm.c +++ b/cpu-arm.c @@ -7,10 +7,6 @@ #if defined TEACUP_C_INCLUDE && defined __ARMEL__ -/** - SystemInit will be called before main from startup assembly code. -*/ -void SystemInit(void) { -} +/* Nothing yet. */ #endif /* defined TEACUP_C_INCLUDE && defined __ARMEL__ */ diff --git a/mbed-LPC11xx.h b/mbed-LPC11xx.h new file mode 100644 index 0000000..7e3a883 --- /dev/null +++ b/mbed-LPC11xx.h @@ -0,0 +1,614 @@ +/**************************************************************************** + * $Id:: LPC11xx.h 9198 2012-05-29 usb00175 $ + * Project: NXP LPC11xx software example + * + * Description: + * CMSIS Cortex-M0 Core Peripheral Access Layer Header File for + * NXP LPC11xx Device Series + + **************************************************************************** + * Software that is described herein is for illustrative purposes only +* which provides customers with programming information regarding the +* products. This software is supplied "AS IS" without any warranties. +* NXP Semiconductors assumes no responsibility or liability for the +* use of the software, conveys no license or title under any patent, +* copyright, or mask work right to the product. NXP Semiconductors +* reserves the right to make changes in the software without +* notification. NXP Semiconductors also make no representation or +* warranty that such application will be suitable for the specified +* use without further testing or modification. + +* Permission to use, copy, modify, and distribute this software and its +* documentation is hereby granted, under NXP Semiconductors' +* relevant copyright in the software, without fee, provided that it +* is used in conjunction with NXP Semiconductors microcontrollers. This +* copyright, permission, and disclaimer notice must appear in all copies of +* this code. + +****************************************************************************/ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/LPC11xx.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef __LPC11xx_H__ +#define __LPC11xx_H__ + +#ifdef __cplusplus + extern "C" { +#endif + +/** @addtogroup LPC11xx_Definitions LPC11xx Definitions + This file defines all structures and symbols for LPC11xx: + - Registers and bitfields + - peripheral base address + - peripheral ID + - PIO definitions + @{ +*/ + + +/******************************************************************************/ +/* Processor and Core Peripherals */ +/******************************************************************************/ +/** @addtogroup LPC11xx_CMSIS LPC11xx CMSIS Definitions + Configuration of the Cortex-M0 Processor and Core Peripherals + @{ +*/ + +/* + * ========================================================================== + * ---------- Interrupt Number Definition ----------------------------------- + * ========================================================================== + */ +typedef enum IRQn +{ +/****** Cortex-M0 Processor Exceptions Numbers ***************************************************/ + NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ + HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */ + SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */ + PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */ + SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */ + +/****** LPC11Cxx or LPC11xx Specific Interrupt Numbers *******************************************************/ + WAKEUP0_IRQn = 0, /*!< All I/O pins can be used as wakeup source. */ + WAKEUP1_IRQn = 1, /*!< There are 13 pins in total for LPC11xx */ + WAKEUP2_IRQn = 2, + WAKEUP3_IRQn = 3, + WAKEUP4_IRQn = 4, + WAKEUP5_IRQn = 5, + WAKEUP6_IRQn = 6, + WAKEUP7_IRQn = 7, + WAKEUP8_IRQn = 8, + WAKEUP9_IRQn = 9, + WAKEUP10_IRQn = 10, + WAKEUP11_IRQn = 11, + WAKEUP12_IRQn = 12, + CAN_IRQn = 13, /*!< CAN Interrupt */ + SSP1_IRQn = 14, /*!< SSP1 Interrupt */ + I2C_IRQn = 15, /*!< I2C Interrupt */ + TIMER_16_0_IRQn = 16, /*!< 16-bit Timer0 Interrupt */ + TIMER_16_1_IRQn = 17, /*!< 16-bit Timer1 Interrupt */ + TIMER_32_0_IRQn = 18, /*!< 32-bit Timer0 Interrupt */ + TIMER_32_1_IRQn = 19, /*!< 32-bit Timer1 Interrupt */ + SSP0_IRQn = 20, /*!< SSP0 Interrupt */ + UART_IRQn = 21, /*!< UART Interrupt */ + Reserved0_IRQn = 22, /*!< Reserved Interrupt */ + Reserved1_IRQn = 23, + ADC_IRQn = 24, /*!< A/D Converter Interrupt */ + WDT_IRQn = 25, /*!< Watchdog timer Interrupt */ + BOD_IRQn = 26, /*!< Brown Out Detect(BOD) Interrupt */ + FMC_IRQn = 27, /*!< Flash Memory Controller Interrupt */ + EINT3_IRQn = 28, /*!< External Interrupt 3 Interrupt */ + EINT2_IRQn = 29, /*!< External Interrupt 2 Interrupt */ + EINT1_IRQn = 30, /*!< External Interrupt 1 Interrupt */ + EINT0_IRQn = 31, /*!< External Interrupt 0 Interrupt */ +} IRQn_Type; + +/* + * ========================================================================== + * ----------- Processor and Core Peripheral Section ------------------------ + * ========================================================================== + */ + +/* Configuration of the Cortex-M0 Processor and Core Peripherals */ +#define __MPU_PRESENT 0 /*!< MPU present or not */ +#define __NVIC_PRIO_BITS 2 /*!< Number of Bits used for Priority Levels */ +#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ + +/*@}*/ /* end of group LPC11xx_CMSIS */ + + +#include "mbed-core_cm0.h" /* Cortex-M0 processor and core peripherals */ +#include "mbed-system_LPC11xx.h" /* System Header */ + + +/******************************************************************************/ +/* Device Specific Peripheral Registers structures */ +/******************************************************************************/ + +#if defined ( __CC_ARM ) +#pragma anon_unions +#endif + +/*------------- System Control (SYSCON) --------------------------------------*/ +/** @addtogroup LPC11xx_SYSCON LPC11xx System Control Block + @{ +*/ +typedef struct +{ + __IO uint32_t SYSMEMREMAP; /*!< Offset: 0x000 System memory remap (R/W) */ + __IO uint32_t PRESETCTRL; /*!< Offset: 0x004 Peripheral reset control (R/W) */ + __IO uint32_t SYSPLLCTRL; /*!< Offset: 0x008 System PLL control (R/W) */ + __I uint32_t SYSPLLSTAT; /*!< Offset: 0x00C System PLL status (R/ ) */ + uint32_t RESERVED0[4]; + + __IO uint32_t SYSOSCCTRL; /*!< Offset: 0x020 System oscillator control (R/W) */ + __IO uint32_t WDTOSCCTRL; /*!< Offset: 0x024 Watchdog oscillator control (R/W) */ + __IO uint32_t IRCCTRL; /*!< Offset: 0x028 IRC control (R/W) */ + uint32_t RESERVED1[1]; + __IO uint32_t SYSRSTSTAT; /*!< Offset: 0x030 System reset status Register (R/ ) */ + uint32_t RESERVED2[3]; + __IO uint32_t SYSPLLCLKSEL; /*!< Offset: 0x040 System PLL clock source select (R/W) */ + __IO uint32_t SYSPLLCLKUEN; /*!< Offset: 0x044 System PLL clock source update enable (R/W) */ + uint32_t RESERVED3[10]; + + __IO uint32_t MAINCLKSEL; /*!< Offset: 0x070 Main clock source select (R/W) */ + __IO uint32_t MAINCLKUEN; /*!< Offset: 0x074 Main clock source update enable (R/W) */ + __IO uint32_t SYSAHBCLKDIV; /*!< Offset: 0x078 System AHB clock divider (R/W) */ + uint32_t RESERVED4[1]; + + __IO uint32_t SYSAHBCLKCTRL; /*!< Offset: 0x080 System AHB clock control (R/W) */ + uint32_t RESERVED5[4]; + __IO uint32_t SSP0CLKDIV; /*!< Offset: 0x094 SSP0 clock divider (R/W) */ + __IO uint32_t UARTCLKDIV; /*!< Offset: 0x098 UART clock divider (R/W) */ + __IO uint32_t SSP1CLKDIV; /*!< Offset: 0x09C SSP1 clock divider (R/W) */ + uint32_t RESERVED6[12]; + + __IO uint32_t WDTCLKSEL; /*!< Offset: 0x0D0 WDT clock source select (R/W) */ + __IO uint32_t WDTCLKUEN; /*!< Offset: 0x0D4 WDT clock source update enable (R/W) */ + __IO uint32_t WDTCLKDIV; /*!< Offset: 0x0D8 WDT clock divider (R/W) */ + uint32_t RESERVED8[1]; + __IO uint32_t CLKOUTCLKSEL; /*!< Offset: 0x0E0 CLKOUT clock source select (R/W) */ + __IO uint32_t CLKOUTUEN; /*!< Offset: 0x0E4 CLKOUT clock source update enable (R/W) */ + __IO uint32_t CLKOUTDIV; /*!< Offset: 0x0E8 CLKOUT clock divider (R/W) */ + uint32_t RESERVED9[5]; + + __IO uint32_t PIOPORCAP0; /*!< Offset: 0x100 POR captured PIO status 0 (R/ ) */ + __IO uint32_t PIOPORCAP1; /*!< Offset: 0x104 POR captured PIO status 1 (R/ ) */ + uint32_t RESERVED10[18]; + __IO uint32_t BODCTRL; /*!< Offset: 0x150 BOD control (R/W) */ + __IO uint32_t SYSTCKCAL; /*!< Offset: 0x154 System tick counter calibration (R/W) */ + + uint32_t RESERVED13[7]; + __IO uint32_t NMISRC; /*!< Offset: 0x174 NMI source selection register (R/W) */ + uint32_t RESERVED14[34]; + + __IO uint32_t STARTAPRP0; /*!< Offset: 0x200 Start logic edge control Register 0 (R/W) */ + __IO uint32_t STARTERP0; /*!< Offset: 0x204 Start logic signal enable Register 0 (R/W) */ + __O uint32_t STARTRSRP0CLR; /*!< Offset: 0x208 Start logic reset Register 0 ( /W) */ + __I uint32_t STARTSRP0; /*!< Offset: 0x20C Start logic status Register 0 (R/) */ + __IO uint32_t STARTAPRP1; /*!< Offset: 0x210 Start logic edge control Register 0 (R/W). (LPC11UXX only) */ + __IO uint32_t STARTERP1; /*!< Offset: 0x214 Start logic signal enable Register 0 (R/W). (LPC11UXX only) */ + __O uint32_t STARTRSRP1CLR; /*!< Offset: 0x218 Start logic reset Register 0 ( /W). (LPC11UXX only) */ + __IO uint32_t STARTSRP1; /*!< Offset: 0x21C Start logic status Register 0 (R/W). (LPC11UXX only) */ + uint32_t RESERVED17[4]; + + __IO uint32_t PDSLEEPCFG; /*!< Offset: 0x230 Power-down states in Deep-sleep mode (R/W) */ + __IO uint32_t PDAWAKECFG; /*!< Offset: 0x234 Power-down states after wake-up (R/W) */ + __IO uint32_t PDRUNCFG; /*!< Offset: 0x238 Power-down configuration Register (R/W) */ + uint32_t RESERVED15[110]; + __I uint32_t DEVICE_ID; /*!< Offset: 0x3F4 Device ID (R/ ) */ +} LPC_SYSCON_TypeDef; +/*@}*/ /* end of group LPC11xx_SYSCON */ + + +/*------------- Pin Connect Block (IOCON) --------------------------------*/ +/** @addtogroup LPC11xx_IOCON LPC11xx I/O Configuration Block + @{ +*/ +typedef struct +{ + __IO uint32_t PIO2_6; /*!< Offset: 0x000 I/O configuration for pin PIO2_6 (R/W) */ + uint32_t RESERVED0[1]; + __IO uint32_t PIO2_0; /*!< Offset: 0x008 I/O configuration for pin PIO2_0/DTR/SSEL1 (R/W) */ + __IO uint32_t RESET_PIO0_0; /*!< Offset: 0x00C I/O configuration for pin RESET/PIO0_0 (R/W) */ + __IO uint32_t PIO0_1; /*!< Offset: 0x010 I/O configuration for pin PIO0_1/CLKOUT/CT32B0_MAT2 (R/W) */ + __IO uint32_t PIO1_8; /*!< Offset: 0x014 I/O configuration for pin PIO1_8/CT16B1_CAP0 (R/W) */ + __IO uint32_t SSEL1_LOC; /*!< Offset: 0x018 IOCON SSEL1 location register (IOCON_SSEL1_LOC, address 0x4004 4018) */ + __IO uint32_t PIO0_2; /*!< Offset: 0x01C I/O configuration for pin PIO0_2/SSEL0/CT16B0_CAP0 (R/W) */ + + __IO uint32_t PIO2_7; /*!< Offset: 0x020 I/O configuration for pin PIO2_7 (R/W) */ + __IO uint32_t PIO2_8; /*!< Offset: 0x024 I/O configuration for pin PIO2_8 (R/W) */ + __IO uint32_t PIO2_1; /*!< Offset: 0x028 I/O configuration for pin PIO2_1/nDSR/SCK1 (R/W) */ + __IO uint32_t PIO0_3; /*!< Offset: 0x02C I/O configuration for pin PIO0_3 (R/W) */ + __IO uint32_t PIO0_4; /*!< Offset: 0x030 I/O configuration for pin PIO0_4/SCL (R/W) */ + __IO uint32_t PIO0_5; /*!< Offset: 0x034 I/O configuration for pin PIO0_5/SDA (R/W) */ + __IO uint32_t PIO1_9; /*!< Offset: 0x038 I/O configuration for pin PIO1_9/CT16B1_MAT0 (R/W) */ + __IO uint32_t PIO3_4; /*!< Offset: 0x03C I/O configuration for pin PIO3_4 (R/W) */ + + __IO uint32_t PIO2_4; /*!< Offset: 0x040 I/O configuration for pin PIO2_4 (R/W) */ + __IO uint32_t PIO2_5; /*!< Offset: 0x044 I/O configuration for pin PIO2_5 (R/W) */ + __IO uint32_t PIO3_5; /*!< Offset: 0x048 I/O configuration for pin PIO3_5 (R/W) */ + __IO uint32_t PIO0_6; /*!< Offset: 0x04C I/O configuration for pin PIO0_6/SCK0 (R/W) */ + __IO uint32_t PIO0_7; /*!< Offset: 0x050 I/O configuration for pin PIO0_7/nCTS (R/W) */ + __IO uint32_t PIO2_9; /*!< Offset: 0x054 I/O configuration for pin PIO2_9 (R/W) */ + __IO uint32_t PIO2_10; /*!< Offset: 0x058 I/O configuration for pin PIO2_10 (R/W) */ + __IO uint32_t PIO2_2; /*!< Offset: 0x05C I/O configuration for pin PIO2_2/DCD/MISO1 (R/W) */ + + __IO uint32_t PIO0_8; /*!< Offset: 0x060 I/O configuration for pin PIO0_8/MISO0/CT16B0_MAT0 (R/W) */ + __IO uint32_t PIO0_9; /*!< Offset: 0x064 I/O configuration for pin PIO0_9/MOSI0/CT16B0_MAT1 (R/W) */ + __IO uint32_t SWCLK_PIO0_10; /*!< Offset: 0x068 I/O configuration for pin SWCLK/PIO0_10/SCK0/CT16B0_MAT2 (R/W) */ + __IO uint32_t PIO1_10; /*!< Offset: 0x06C I/O configuration for pin PIO1_10/AD6/CT16B1_MAT1 (R/W) */ + __IO uint32_t PIO2_11; /*!< Offset: 0x070 I/O configuration for pin PIO2_11/SCK0 (R/W) */ + __IO uint32_t R_PIO0_11; /*!< Offset: 0x074 I/O configuration for pin TDI/PIO0_11/AD0/CT32B0_MAT3 (R/W) */ + __IO uint32_t R_PIO1_0; /*!< Offset: 0x078 I/O configuration for pin TMS/PIO1_0/AD1/CT32B1_CAP0 (R/W) */ + __IO uint32_t R_PIO1_1; /*!< Offset: 0x07C I/O configuration for pin TDO/PIO1_1/AD2/CT32B1_MAT0 (R/W) */ + + __IO uint32_t R_PIO1_2; /*!< Offset: 0x080 I/O configuration for pin nTRST/PIO1_2/AD3/CT32B1_MAT1 (R/W) */ + __IO uint32_t PIO3_0; /*!< Offset: 0x084 I/O configuration for pin PIO3_0/nDTR (R/W) */ + __IO uint32_t PIO3_1; /*!< Offset: 0x088 I/O configuration for pin PIO3_1/nDSR (R/W) */ + __IO uint32_t PIO2_3; /*!< Offset: 0x08C I/O configuration for pin PIO2_3/RI/MOSI1 (R/W) */ + __IO uint32_t SWDIO_PIO1_3; /*!< Offset: 0x090 I/O configuration for pin SWDIO/PIO1_3/AD4/CT32B1_MAT2 (R/W) */ + __IO uint32_t PIO1_4; /*!< Offset: 0x094 I/O configuration for pin PIO1_4/AD5/CT32B1_MAT3 (R/W) */ + __IO uint32_t PIO1_11; /*!< Offset: 0x098 I/O configuration for pin PIO1_11/AD7 (R/W) */ + __IO uint32_t PIO3_2; /*!< Offset: 0x09C I/O configuration for pin PIO3_2/nDCD (R/W) */ + + __IO uint32_t PIO1_5; /*!< Offset: 0x0A0 I/O configuration for pin PIO1_5/nRTS/CT32B0_CAP0 (R/W) */ + __IO uint32_t PIO1_6; /*!< Offset: 0x0A4 I/O configuration for pin PIO1_6/RXD/CT32B0_MAT0 (R/W) */ + __IO uint32_t PIO1_7; /*!< Offset: 0x0A8 I/O configuration for pin PIO1_7/TXD/CT32B0_MAT1 (R/W) */ + __IO uint32_t PIO3_3; /*!< Offset: 0x0AC I/O configuration for pin PIO3_3/nRI (R/W) */ + __IO uint32_t SCK_LOC; /*!< Offset: 0x0B0 SCK pin location select Register (R/W) */ + __IO uint32_t DSR_LOC; /*!< Offset: 0x0B4 DSR pin location select Register (R/W) */ + __IO uint32_t DCD_LOC; /*!< Offset: 0x0B8 DCD pin location select Register (R/W) */ + __IO uint32_t RI_LOC; /*!< Offset: 0x0BC RI pin location Register (R/W) */ + + __IO uint32_t CT16B0_CAP0_LOC; /*!< Offset: 0x0C0 IOCON CT16B0_CAP0 location register (IOCON_CT16B0_CAP0_LOC, address 0x4004 40C0) */ + __IO uint32_t SCK1_LOC; /*!< Offset: 0x0C4 IOCON SCK1 location register (IOCON_SCK1_LOC, address 0x4004 40C4) */ + __IO uint32_t MISO1_LOC; /*!< Offset: 0x0C8 IOCON MISO1 location register (IOCON_MISO1_LOC, address 0x4004 40C8) */ + __IO uint32_t MOSI1_LOC; /*!< Offset: 0x0CC IOCON MOSI1 location register (IOCON_MOSI1_LOC, address 0x4004 40CC) */ + __IO uint32_t CT32B0_CAP0_LOC; /*!< Offset: 0x0D0 IOCON CT32B0_CAP0 location register (IOCON_CT32B0_CAP0_LOC, address 0x4004 40D0) */ + __IO uint32_t RXD_LOC; /*!< Offset: 0x0D4 IOCON RXD location register (IOCON_RXD_LOC, address 0x4004 40D4) */ +} LPC_IOCON_TypeDef; +/*@}*/ /* end of group LPC11xx_IOCON */ + + +/*------------- Power Management Unit (PMU) --------------------------*/ +/** @addtogroup LPC11xx_PMU LPC11xx Power Management Unit + @{ +*/ +typedef struct +{ + __IO uint32_t PCON; /*!< Offset: 0x000 Power control Register (R/W) */ + __IO uint32_t GPREG0; /*!< Offset: 0x004 General purpose Register 0 (R/W) */ + __IO uint32_t GPREG1; /*!< Offset: 0x008 General purpose Register 1 (R/W) */ + __IO uint32_t GPREG2; /*!< Offset: 0x00C General purpose Register 2 (R/W) */ + __IO uint32_t GPREG3; /*!< Offset: 0x010 General purpose Register 3 (R/W) */ + __IO uint32_t GPREG4; /*!< Offset: 0x014 General purpose Register 4 (R/W) */ +} LPC_PMU_TypeDef; +/*@}*/ /* end of group LPC11xx_PMU */ + + + +// ------------------------------------------------------------------------------------------------ +// ----- FLASHCTRL ----- +// ------------------------------------------------------------------------------------------------ + +typedef struct { /*!< (@ 0x4003C000) FLASHCTRL Structure */ + __I uint32_t RESERVED0[4]; + __IO uint32_t FLASHCFG; /*!< (@ 0x4003C010) Flash memory access time configuration register */ + __I uint32_t RESERVED1[3]; + __IO uint32_t FMSSTART; /*!< (@ 0x4003C020) Signature start address register */ + __IO uint32_t FMSSTOP; /*!< (@ 0x4003C024) Signature stop-address register */ + __I uint32_t RESERVED2[1]; + __I uint32_t FMSW0; /*!< (@ 0x4003C02C) Word 0 [31:0] */ + __I uint32_t FMSW1; /*!< (@ 0x4003C030) Word 1 [63:32] */ + __I uint32_t FMSW2; /*!< (@ 0x4003C034) Word 2 [95:64] */ + __I uint32_t FMSW3; /*!< (@ 0x4003C038) Word 3 [127:96] */ + __I uint32_t RESERVED3[1001]; + __I uint32_t FMSTAT; /*!< (@ 0x4003CFE0) Signature generation status register */ + __I uint32_t RESERVED4[1]; + __IO uint32_t FMSTATCLR; /*!< (@ 0x4003CFE8) Signature generation status clear register */ +} LPC_FLASHCTRL_Type; + + +/*------------- General Purpose Input/Output (GPIO) --------------------------*/ +/** @addtogroup LPC11xx_GPIO LPC11xx General Purpose Input/Output + @{ +*/ +typedef struct +{ + union { + __IO uint32_t MASKED_ACCESS[4096]; /*!< Offset: 0x0000 to 0x3FFC Port data Register for pins PIOn_0 to PIOn_11 (R/W) */ + struct { + uint32_t RESERVED0[4095]; + __IO uint32_t DATA; /*!< Offset: 0x3FFC Port data Register (R/W) */ + }; + }; + uint32_t RESERVED1[4096]; + __IO uint32_t DIR; /*!< Offset: 0x8000 Data direction Register (R/W) */ + __IO uint32_t IS; /*!< Offset: 0x8004 Interrupt sense Register (R/W) */ + __IO uint32_t IBE; /*!< Offset: 0x8008 Interrupt both edges Register (R/W) */ + __IO uint32_t IEV; /*!< Offset: 0x800C Interrupt event Register (R/W) */ + __IO uint32_t IE; /*!< Offset: 0x8010 Interrupt mask Register (R/W) */ + __I uint32_t RIS; /*!< Offset: 0x8014 Raw interrupt status Register (R/ ) */ + __I uint32_t MIS; /*!< Offset: 0x8018 Masked interrupt status Register (R/ ) */ + __O uint32_t IC; /*!< Offset: 0x801C Interrupt clear Register (/W) */ +} LPC_GPIO_TypeDef; +/*@}*/ /* end of group LPC11xx_GPIO */ + +/*------------- Timer (TMR) --------------------------------------------------*/ +/** @addtogroup LPC11xx_TMR LPC11xx 16/32-bit Counter/Timer + @{ +*/ +typedef struct +{ + __IO uint32_t IR; /*!< Offset: 0x000 Interrupt Register (R/W) */ + __IO uint32_t TCR; /*!< Offset: 0x004 Timer Control Register (R/W) */ + __IO uint32_t TC; /*!< Offset: 0x008 Timer Counter Register (R/W) */ + __IO uint32_t PR; /*!< Offset: 0x00C Prescale Register (R/W) */ + __IO uint32_t PC; /*!< Offset: 0x010 Prescale Counter Register (R/W) */ + __IO uint32_t MCR; /*!< Offset: 0x014 Match Control Register (R/W) */ + union { + __IO uint32_t MR[4]; /*!< Offset: Match Register base */ + struct{ + __IO uint32_t MR0; /*!< Offset: 0x018 Match Register 0 (R/W) */ + __IO uint32_t MR1; /*!< Offset: 0x01C Match Register 1 (R/W) */ + __IO uint32_t MR2; /*!< Offset: 0x020 Match Register 2 (R/W) */ + __IO uint32_t MR3; /*!< Offset: 0x024 Match Register 3 (R/W) */ + }; + }; + __IO uint32_t CCR; /*!< Offset: 0x028 Capture Control Register (R/W) */ + __I uint32_t CR0; /*!< Offset: 0x02C Capture Register 0 (R/ ) */ + __I uint32_t CR1; /*!< Offset: 0x030 Capture Register 1 (R/ ) */ + uint32_t RESERVED1[2]; + __IO uint32_t EMR; /*!< Offset: 0x03C External Match Register (R/W) */ + uint32_t RESERVED2[12]; + __IO uint32_t CTCR; /*!< Offset: 0x070 Count Control Register (R/W) */ + __IO uint32_t PWMC; /*!< Offset: 0x074 PWM Control Register (R/W) */ +} LPC_TMR_TypeDef; +/*@}*/ /* end of group LPC11xx_TMR */ + + +/*------------- Universal Asynchronous Receiver Transmitter (UART) -----------*/ +/** @addtogroup LPC11xx_UART LPC11xx Universal Asynchronous Receiver/Transmitter + @{ +*/ +typedef struct +{ + union { + __I uint32_t RBR; /*!< Offset: 0x000 Receiver Buffer Register (R/ ) */ + __O uint32_t THR; /*!< Offset: 0x000 Transmit Holding Register ( /W) */ + __IO uint32_t DLL; /*!< Offset: 0x000 Divisor Latch LSB (R/W) */ + }; + union { + __IO uint32_t DLM; /*!< Offset: 0x004 Divisor Latch MSB (R/W) */ + __IO uint32_t IER; /*!< Offset: 0x000 Interrupt Enable Register (R/W) */ + }; + union { + __I uint32_t IIR; /*!< Offset: 0x008 Interrupt ID Register (R/ ) */ + __O uint32_t FCR; /*!< Offset: 0x008 FIFO Control Register ( /W) */ + }; + __IO uint32_t LCR; /*!< Offset: 0x00C Line Control Register (R/W) */ + __IO uint32_t MCR; /*!< Offset: 0x010 Modem control Register (R/W) */ + __I uint32_t LSR; /*!< Offset: 0x014 Line Status Register (R/ ) */ + __I uint32_t MSR; /*!< Offset: 0x018 Modem status Register (R/ ) */ + __IO uint32_t SCR; /*!< Offset: 0x01C Scratch Pad Register (R/W) */ + __IO uint32_t ACR; /*!< Offset: 0x020 Auto-baud Control Register (R/W) */ + uint32_t RESERVED0; + __IO uint32_t FDR; /*!< Offset: 0x028 Fractional Divider Register (R/W) */ + uint32_t RESERVED1; + __IO uint32_t TER; /*!< Offset: 0x030 Transmit Enable Register (R/W) */ + uint32_t RESERVED2[6]; + __IO uint32_t RS485CTRL; /*!< Offset: 0x04C RS-485/EIA-485 Control Register (R/W) */ + __IO uint32_t ADRMATCH; /*!< Offset: 0x050 RS-485/EIA-485 address match Register (R/W) */ + __IO uint32_t RS485DLY; /*!< Offset: 0x054 RS-485/EIA-485 direction control delay Register (R/W) */ + __I uint32_t FIFOLVL; /*!< Offset: 0x058 FIFO Level Register (R) */ +} LPC_UART_TypeDef; +/*@}*/ /* end of group LPC11xx_UART */ + + +/*------------- Synchronous Serial Communication (SSP) -----------------------*/ +/** @addtogroup LPC11xx_SSP LPC11xx Synchronous Serial Port + @{ +*/ +typedef struct +{ + __IO uint32_t CR0; /*!< Offset: 0x000 Control Register 0 (R/W) */ + __IO uint32_t CR1; /*!< Offset: 0x004 Control Register 1 (R/W) */ + __IO uint32_t DR; /*!< Offset: 0x008 Data Register (R/W) */ + __I uint32_t SR; /*!< Offset: 0x00C Status Registe (R/ ) */ + __IO uint32_t CPSR; /*!< Offset: 0x010 Clock Prescale Register (R/W) */ + __IO uint32_t IMSC; /*!< Offset: 0x014 Interrupt Mask Set and Clear Register (R/W) */ + __I uint32_t RIS; /*!< Offset: 0x018 Raw Interrupt Status Register (R/) */ + __I uint32_t MIS; /*!< Offset: 0x01C Masked Interrupt Status Register (R/) */ + __O uint32_t ICR; /*!< Offset: 0x020 SSPICR Interrupt Clear Register (/W) */ +} LPC_SSP_TypeDef; +/*@}*/ /* end of group LPC11xx_SSP */ + + +/*------------- Inter-Integrated Circuit (I2C) -------------------------------*/ +/** @addtogroup LPC11xx_I2C LPC11xx I2C-Bus Interface + @{ +*/ +typedef struct +{ + __IO uint32_t CONSET; /*!< Offset: 0x000 I2C Control Set Register (R/W) */ + __I uint32_t STAT; /*!< Offset: 0x004 I2C Status Register (R/ ) */ + __IO uint32_t DAT; /*!< Offset: 0x008 I2C Data Register (R/W) */ + __IO uint32_t ADR0; /*!< Offset: 0x00C I2C Slave Address Register 0 (R/W) */ + __IO uint32_t SCLH; /*!< Offset: 0x010 SCH Duty Cycle Register High Half Word (R/W) */ + __IO uint32_t SCLL; /*!< Offset: 0x014 SCL Duty Cycle Register Low Half Word (R/W) */ + __O uint32_t CONCLR; /*!< Offset: 0x018 I2C Control Clear Register ( /W) */ + __IO uint32_t MMCTRL; /*!< Offset: 0x01C Monitor mode control register (R/W) */ + __IO uint32_t ADR1; /*!< Offset: 0x020 I2C Slave Address Register 1 (R/W) */ + __IO uint32_t ADR2; /*!< Offset: 0x024 I2C Slave Address Register 2 (R/W) */ + __IO uint32_t ADR3; /*!< Offset: 0x028 I2C Slave Address Register 3 (R/W) */ + __I uint32_t DATA_BUFFER; /*!< Offset: 0x02C Data buffer register ( /W) */ + __IO uint32_t MASK0; /*!< Offset: 0x030 I2C Slave address mask register 0 (R/W) */ + __IO uint32_t MASK1; /*!< Offset: 0x034 I2C Slave address mask register 1 (R/W) */ + __IO uint32_t MASK2; /*!< Offset: 0x038 I2C Slave address mask register 2 (R/W) */ + __IO uint32_t MASK3; /*!< Offset: 0x03C I2C Slave address mask register 3 (R/W) */ +} LPC_I2C_TypeDef; +/*@}*/ /* end of group LPC11xx_I2C */ + + +/*------------- Watchdog Timer (WDT) -----------------------------------------*/ +/** @addtogroup LPC11xx_WDT LPC11xx WatchDog Timer + @{ +*/ +typedef struct +{ + __IO uint32_t MOD; /*!< Offset: 0x000 Watchdog mode register (R/W) */ + __IO uint32_t TC; /*!< Offset: 0x004 Watchdog timer constant register (R/W) */ + __O uint32_t FEED; /*!< Offset: 0x008 Watchdog feed sequence register (W) */ + __I uint32_t TV; /*!< Offset: 0x00C Watchdog timer value register (R) */ + uint32_t RESERVED0; + __IO uint32_t WARNINT; /*!< Offset: 0x014 Watchdog timer warning int. register (R/W) */ + __IO uint32_t WINDOW; /*!< Offset: 0x018 Watchdog timer window value register (R/W) */ +} LPC_WDT_TypeDef; +/*@}*/ /* end of group LPC11xx_WDT */ + + +/*------------- Analog-to-Digital Converter (ADC) ----------------------------*/ +/** @addtogroup LPC11xx_ADC LPC11xx Analog-to-Digital Converter + @{ +*/ +typedef struct +{ + __IO uint32_t CR; /*!< Offset: 0x000 A/D Control Register (R/W) */ + __IO uint32_t GDR; /*!< Offset: 0x004 A/D Global Data Register (R/W) */ + uint32_t RESERVED0; + __IO uint32_t INTEN; /*!< Offset: 0x00C A/D Interrupt Enable Register (R/W) */ + __IO uint32_t DR[8]; /*!< Offset: 0x010-0x02C A/D Channel 0..7 Data Register (R/W) */ + __I uint32_t STAT; /*!< Offset: 0x030 A/D Status Register (R/ ) */ +} LPC_ADC_TypeDef; +/*@}*/ /* end of group LPC11xx_ADC */ + + +/*------------- CAN Controller (CAN) ----------------------------*/ +/** @addtogroup LPC11xx_CAN LPC11xx Controller Area Network(CAN) + @{ +*/ +typedef struct +{ + __IO uint32_t CNTL; /* 0x000 */ + __IO uint32_t STAT; + __IO uint32_t EC; + __IO uint32_t BT; + __IO uint32_t INT; + __IO uint32_t TEST; + __IO uint32_t BRPE; + uint32_t RESERVED0; + __IO uint32_t IF1_CMDREQ; /* 0x020 */ + __IO uint32_t IF1_CMDMSK; + __IO uint32_t IF1_MSK1; + __IO uint32_t IF1_MSK2; + __IO uint32_t IF1_ARB1; + __IO uint32_t IF1_ARB2; + __IO uint32_t IF1_MCTRL; + __IO uint32_t IF1_DA1; + __IO uint32_t IF1_DA2; + __IO uint32_t IF1_DB1; + __IO uint32_t IF1_DB2; + uint32_t RESERVED1[13]; + __IO uint32_t IF2_CMDREQ; /* 0x080 */ + __IO uint32_t IF2_CMDMSK; + __IO uint32_t IF2_MSK1; + __IO uint32_t IF2_MSK2; + __IO uint32_t IF2_ARB1; + __IO uint32_t IF2_ARB2; + __IO uint32_t IF2_MCTRL; + __IO uint32_t IF2_DA1; + __IO uint32_t IF2_DA2; + __IO uint32_t IF2_DB1; + __IO uint32_t IF2_DB2; + uint32_t RESERVED2[21]; + __I uint32_t TXREQ1; /* 0x100 */ + __I uint32_t TXREQ2; + uint32_t RESERVED3[6]; + __I uint32_t ND1; /* 0x120 */ + __I uint32_t ND2; + uint32_t RESERVED4[6]; + __I uint32_t IR1; /* 0x140 */ + __I uint32_t IR2; + uint32_t RESERVED5[6]; + __I uint32_t MSGV1; /* 0x160 */ + __I uint32_t MSGV2; + uint32_t RESERVED6[6]; + __IO uint32_t CLKDIV; /* 0x180 */ +} LPC_CAN_TypeDef; +/*@}*/ /* end of group LPC11xx_CAN */ + +#if defined ( __CC_ARM ) +#pragma no_anon_unions +#endif + +/******************************************************************************/ +/* Peripheral memory map */ +/******************************************************************************/ +/* Base addresses */ +#define LPC_FLASH_BASE (0x00000000UL) +#define LPC_RAM_BASE (0x10000000UL) +#define LPC_APB0_BASE (0x40000000UL) +#define LPC_AHB_BASE (0x50000000UL) + +/* APB0 peripherals */ +#define LPC_I2C_BASE (LPC_APB0_BASE + 0x00000) +#define LPC_WDT_BASE (LPC_APB0_BASE + 0x04000) +#define LPC_UART_BASE (LPC_APB0_BASE + 0x08000) +#define LPC_CT16B0_BASE (LPC_APB0_BASE + 0x0C000) +#define LPC_CT16B1_BASE (LPC_APB0_BASE + 0x10000) +#define LPC_CT32B0_BASE (LPC_APB0_BASE + 0x14000) +#define LPC_CT32B1_BASE (LPC_APB0_BASE + 0x18000) +#define LPC_ADC_BASE (LPC_APB0_BASE + 0x1C000) +#define LPC_PMU_BASE (LPC_APB0_BASE + 0x38000) +#define LPC_FLASHCTRL_BASE (LPC_APB0_BASE + 0x3C000) +#define LPC_SSP0_BASE (LPC_APB0_BASE + 0x40000) +#define LPC_IOCON_BASE (LPC_APB0_BASE + 0x44000) +#define LPC_SYSCON_BASE (LPC_APB0_BASE + 0x48000) +#define LPC_CAN_BASE (LPC_APB0_BASE + 0x50000) +#define LPC_SSP1_BASE (LPC_APB0_BASE + 0x58000) + +/* AHB peripherals */ +#define LPC_GPIO_BASE (LPC_AHB_BASE + 0x00000) +#define LPC_GPIO0_BASE (LPC_AHB_BASE + 0x00000) +#define LPC_GPIO1_BASE (LPC_AHB_BASE + 0x10000) +#define LPC_GPIO2_BASE (LPC_AHB_BASE + 0x20000) +#define LPC_GPIO3_BASE (LPC_AHB_BASE + 0x30000) + +/******************************************************************************/ +/* Peripheral declaration */ +/******************************************************************************/ +#define LPC_I2C ((LPC_I2C_TypeDef *) LPC_I2C_BASE ) +#define LPC_WDT ((LPC_WDT_TypeDef *) LPC_WDT_BASE ) +#define LPC_UART ((LPC_UART_TypeDef *) LPC_UART_BASE ) +#define LPC_TMR16B0 ((LPC_TMR_TypeDef *) LPC_CT16B0_BASE) +#define LPC_TMR16B1 ((LPC_TMR_TypeDef *) LPC_CT16B1_BASE) +#define LPC_TMR32B0 ((LPC_TMR_TypeDef *) LPC_CT32B0_BASE) +#define LPC_TMR32B1 ((LPC_TMR_TypeDef *) LPC_CT32B1_BASE) +#define LPC_ADC ((LPC_ADC_TypeDef *) LPC_ADC_BASE ) +#define LPC_PMU ((LPC_PMU_TypeDef *) LPC_PMU_BASE ) +#define LPC_FLASHCTRL ((LPC_FLASHCTRL_Type *) LPC_FLASHCTRL_BASE) +#define LPC_SSP0 ((LPC_SSP_TypeDef *) LPC_SSP0_BASE ) +#define LPC_SSP1 ((LPC_SSP_TypeDef *) LPC_SSP1_BASE ) +#define LPC_CAN ((LPC_CAN_TypeDef *) LPC_CAN_BASE ) +#define LPC_IOCON ((LPC_IOCON_TypeDef *) LPC_IOCON_BASE ) +#define LPC_SYSCON ((LPC_SYSCON_TypeDef *) LPC_SYSCON_BASE) +#define LPC_GPIO0 ((LPC_GPIO_TypeDef *) LPC_GPIO0_BASE ) +#define LPC_GPIO1 ((LPC_GPIO_TypeDef *) LPC_GPIO1_BASE ) +#define LPC_GPIO2 ((LPC_GPIO_TypeDef *) LPC_GPIO2_BASE ) +#define LPC_GPIO3 ((LPC_GPIO_TypeDef *) LPC_GPIO3_BASE ) + +#ifdef __cplusplus +} +#endif + +#endif /* __LPC11xx_H__ */ diff --git a/mbed-PeripheralNames.h b/mbed-PeripheralNames.h new file mode 100644 index 0000000..050843e --- /dev/null +++ b/mbed-PeripheralNames.h @@ -0,0 +1,77 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/PeripheralNames.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef MBED_PERIPHERALNAMES_H +#define MBED_PERIPHERALNAMES_H + +#include "mbed-cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + UART_0 = (int)LPC_UART_BASE +} UARTName; + +typedef enum { + I2C_0 = (int)LPC_I2C_BASE +} I2CName; + +typedef enum { + ADC0_0 = 0, + ADC0_1, + ADC0_2, + ADC0_3, + ADC0_4, + ADC0_5, + ADC0_6, + ADC0_7 +} ADCName; + +typedef enum { + SPI_0 = (int)LPC_SSP0_BASE, + SPI_1 = (int)LPC_SSP1_BASE +} SPIName; + +typedef enum { + PWM_1 = 0, + PWM_2, + PWM_3, + PWM_4, + PWM_5 +} PWMName; + +#define STDIO_UART_TX USBTX +#define STDIO_UART_RX USBRX +#define STDIO_UART UART_0 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-PinNames.h b/mbed-PinNames.h new file mode 100644 index 0000000..51b3ec5 --- /dev/null +++ b/mbed-PinNames.h @@ -0,0 +1,246 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/PinNames.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef MBED_PINNAMES_H +#define MBED_PINNAMES_H + +#include "mbed-cmsis.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + PIN_INPUT, + PIN_OUTPUT +} PinDirection; + +#define PORT_SHIFT 12 +#define PIN_SHIFT 8 + +typedef enum { + // LPC1114 Pin Names (PORT[15:12] + PIN[11:8] + IOCON offset[7:0]) + + P0_0 = (0 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x0c, + P0_1 = (0 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x10, + P0_2 = (0 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x1c, + P0_3 = (0 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0x2c, + P0_4 = (0 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x30, + P0_5 = (0 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0x34, + P0_6 = (0 << PORT_SHIFT) | (6 << PIN_SHIFT) | 0x4c, + P0_7 = (0 << PORT_SHIFT) | (7 << PIN_SHIFT) | 0x50, + P0_8 = (0 << PORT_SHIFT) | (8 << PIN_SHIFT) | 0x60, + P0_9 = (0 << PORT_SHIFT) | (9 << PIN_SHIFT) | 0x64, + P0_11 = (0 << PORT_SHIFT) | (11 << PIN_SHIFT) | 0x74, + + P1_0 = (1 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x78, + P1_1 = (1 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x7c, + P1_2 = (1 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x80, + P1_4 = (1 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x94, + P1_5 = (1 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0xa0, + P1_6 = (1 << PORT_SHIFT) | (6 << PIN_SHIFT) | 0xa4, + P1_7 = (1 << PORT_SHIFT) | (7 << PIN_SHIFT) | 0xa8, + P1_8 = (1 << PORT_SHIFT) | (8 << PIN_SHIFT) | 0x14, + P1_9 = (1 << PORT_SHIFT) | (9 << PIN_SHIFT) | 0x38, + P1_10 = (1 << PORT_SHIFT) | (10 << PIN_SHIFT) | 0x6c, + P1_11 = (1 << PORT_SHIFT) | (11 << PIN_SHIFT) | 0x98, + + P2_0 = (2 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x08, + P2_1 = (2 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x28, + P2_2 = (2 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x5c, + P2_3 = (2 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0x8c, + P2_4 = (2 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x40, + P2_5 = (2 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0x44, + P2_6 = (2 << PORT_SHIFT) | (6 << PIN_SHIFT) | 0x00, + P2_7 = (2 << PORT_SHIFT) | (7 << PIN_SHIFT) | 0x20, + P2_8 = (2 << PORT_SHIFT) | (8 << PIN_SHIFT) | 0x24, + P2_9 = (2 << PORT_SHIFT) | (9 << PIN_SHIFT) | 0x54, + P2_10 = (2 << PORT_SHIFT) | (10 << PIN_SHIFT) | 0x58, + P2_11 = (2 << PORT_SHIFT) | (11 << PIN_SHIFT) | 0x70, + + P3_0 = (3 << PORT_SHIFT) | (0 << PIN_SHIFT) | 0x84, + P3_1 = (3 << PORT_SHIFT) | (1 << PIN_SHIFT) | 0x88, + P3_2 = (3 << PORT_SHIFT) | (2 << PIN_SHIFT) | 0x9c, + P3_3 = (3 << PORT_SHIFT) | (3 << PIN_SHIFT) | 0xac, + P3_4 = (3 << PORT_SHIFT) | (4 << PIN_SHIFT) | 0x3c, + P3_5 = (3 << PORT_SHIFT) | (5 << PIN_SHIFT) | 0x48, + + // mbed DIP Pin Names (CQ board) +// p4 = P0_0, + p5 = P0_9, + p6 = P0_8, + p7 = P0_6, + p8 = P1_5, + p9 = P1_7, + p10 = P1_6, + p11 = P0_7, + p12 = P1_0, + p13 = P1_1, + p14 = P1_2, + p15 = P0_11, + p16 = P1_0, + p17 = P1_1, + p18 = P1_2, + p20 = P1_4, + p22 = P0_2, + p23 = P0_11, + p24 = P0_2, + p25 = P1_8, + p26 = P1_9, + p27 = P0_4, + p28 = P0_5, + p29 = P0_3, + p30 = P0_1, + + // Other mbed Pin Names + LED1 = P1_5, + LED2 = P0_7, + LED3 = P1_5, + LED4 = P0_7, + + USBTX = P1_7, + USBRX = P1_6, + + // mbed DIP Pin Names (LPCXpresso LPC1114) +// xp4 = P0_0, + xp5 = P0_9, + xp6 = P0_8, + xp7 = P2_11, + xp8 = P0_2, + xp9 = P1_7, + xp10 = P1_6, + xp11 = P0_7, + xp12 = P2_0, + xp13 = P2_1, + xp14 = P2_2, + xp15 = P0_11, + xp16 = P1_0, + xp17 = P1_1, + xp18 = P1_2, + xp20 = P1_4, + xp21 = P1_5, + xp22 = P1_8, + xp23 = P0_6, + xp25 = P3_0, + xp26 = P3_1, + xp27 = P3_2, + + xp29 = P3_3, + xp30 = P2_10, + xp31 = P2_9, + xp32 = P2_8, + xp33 = P2_7, + xp34 = P2_6, + xp35 = P2_5, + xp36 = P2_4, + xp37 = P2_3, + xp38 = P1_11, + xp39 = P1_10, + xp40 = P1_9, + xp41 = P0_4, + xp42 = P0_5, + xp43 = P0_3, + xp44 = P0_1, + + // Other mbed Pin Names + xLED1 = P0_7, + + // DIP Package Names + + dp1 = P0_8, + dp2 = P0_9, + dp4 = P0_11, + dp5 = P0_5, + dp6 = P0_6, + dp9 = P1_0, + dp10 = P1_1, + dp11 = P1_2, + dp13 = P1_4, + dp14 = P1_5, + dp15 = P1_6, + dp16 = P1_7, + dp17 = P1_8, + dp18 = P1_9, +// dp23 = P0_0, + dp24 = P0_1, + dp25 = P0_2, + dp26 = P0_3, + dp27 = P0_4, + dp28 = P0_7, + + dip1 = P0_8, + dip2 = P0_9, + dip4 = P0_11, + dip5 = P0_5, + dip6 = P0_6, + dip9 = P1_0, + dip10 = P1_1, + dip11 = P1_2, + dip13 = P1_4, + dip14 = P1_5, + dip15 = P1_6, + dip16 = P1_7, + dip17 = P1_8, + dip18 = P1_9, +// dip23 = P0_0, + dip24 = P0_1, + dip25 = P0_2, + dip26 = P0_3, + dip27 = P0_4, + dip28 = P0_7, + + + + // Not connected + NC = (int)0xFFFFFFFF, +} PinName; + +typedef enum { + CHANNEL0 = WAKEUP0_IRQn, + CHANNEL1 = WAKEUP1_IRQn, + CHANNEL2 = WAKEUP2_IRQn, + CHANNEL3 = WAKEUP3_IRQn, + CHANNEL4 = WAKEUP4_IRQn, + CHANNEL5 = WAKEUP5_IRQn, + CHANNEL6 = WAKEUP6_IRQn, + CHANNEL7 = WAKEUP7_IRQn +} Channel; + +typedef enum { + PullUp = 2, + PullDown = 1, + PullNone = 0, + Repeater = 3, + OpenDrain = 4, + PullDefault = PullDown +} PinMode; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-PortNames.h b/mbed-PortNames.h new file mode 100644 index 0000000..24059c6 --- /dev/null +++ b/mbed-PortNames.h @@ -0,0 +1,42 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/PortNames.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ +#ifndef MBED_PORTNAMES_H +#define MBED_PORTNAMES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + Port0 = 0, + Port1 = 1, + Port2 = 2, + Port3 = 3 +} PortName; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mbed-bitfields.h b/mbed-bitfields.h new file mode 100644 index 0000000..55160c6 --- /dev/null +++ b/mbed-bitfields.h @@ -0,0 +1,1777 @@ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/bitfields.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ +#ifndef MBED_BITFIELDS_H +#define MBED_BITFIELDS_H + +//! Massage  x for use in bitfield  name. +#define BFN_PREP(x, name) ( ((x)<>name##_SHIFT ) + +//! Set bitfield  name from  y to  x: y.name= x. +#define BFN_SET(y, x, name) (y = ((y)&~name##_MASK) | BFN_PREP(x,name) ) + + +/* SYSMEMREMAP, address 0x4004 8000 */ +#define SYSMEMREMAP_MAP_MASK 0x0003 // System memory remap +#define SYSMEMREMAP_MAP_SHIFT 0 + +/* PRESETCTRL, address 0x4004 8004 */ +#define PRESETCTRL_SSP0_RST_N (1 << 0) // SPI0 reset control +#define PRESETCTRL_I2C_RST_N (1 << 1) // I2C reset control +#define PRESETCTRL_SSP1_RST_N (1 << 2) // SPI1 reset control +#define PRESETCTRL_CAN_RST_N (1 << 3) // C_CAN reset control. See Section 3.1 for part specific details. + +/* SYSPLLCTRL, address 0x4004 8008 */ +#define SYSPLLCTRL_MSEL_MASK 0x001F // Feedback divider value. The division value M is the programmed MSEL value + 1. 00000: Division ratio M = 1 to 11111: Division ratio M = 32. +#define SYSPLLCTRL_MSEL_SHIFT 0 +#define SYSPLLCTRL_PSEL_MASK 0x0060 // Post divider ratio P. The division ratio is 2 P. +#define SYSPLLCTRL_PSEL_SHIFT 5 + +/* SYSPLLSTAT, address 0x4004 800C */ +#define SYSPLLSTAT_LOCK (1 << 0) // PLL lock status + +/* SYSOSCCTRL, address 0x4004 8020 */ +#define SYSOSCCTRL_BYPASS (1 << 0) // Bypass system oscillator +#define SYSOSCCTRL_FREQRANGE (1 << 1) // Determines frequency range for Low-power oscillator. + +/* WDTOSCCTRL, address 0x4004 8024 */ +#define WDTOSCCTRL_DIVSEL_MASK 0x001F // Select divider for Fclkana. wdt_osc_clk = Fclkana/ (2 (1 + DIVSEL)) 00000: 2 (1 + DIVSEL) = 2 00001: 2 (1 + DIVSEL) = 4 to 11111: 2 (1 + DIVSEL) = 64 +#define WDTOSCCTRL_DIVSEL_SHIFT 0 +#define WDTOSCCTRL_FREQSEL_MASK 0x01E0 // Select watchdog oscillator analog output frequency (Fclkana). +#define WDTOSCCTRL_FREQSEL_SHIFT 5 + +/* IRCCTRL, address 0x4004 8028 */ +#define IRCCTRL_TRIM_MASK 0x00FF // Trim value +#define IRCCTRL_TRIM_SHIFT 0 + +/* SYSRSTSTAT, address 0x4004 8030 */ +#define SYSRSTSTAT_POR (1 << 0) // POR reset status +#define SYSRSTSTAT_EXTRST (1 << 1) // Status of the external RESET pin. +#define SYSRSTSTAT_WDT (1 << 2) // Status of the Watchdog reset +#define SYSRSTSTAT_BOD (1 << 3) // Status of the Brown-out detect reset +#define SYSRSTSTAT_SYSRST (1 << 4) // Status of the software system reset + +/* SYSPLLCLKSEL, address 0x4004 8040 */ +#define SYSPLLCLKSEL_SEL_MASK 0x0003 // System PLL clock source +#define SYSPLLCLKSEL_SEL_SHIFT 0 + +/* SYSPLLCLKUEN, address 0x4004 8044 */ +#define SYSPLLCLKUEN_ENA (1 << 0) // Enable system PLL clock source update + +/* MAINCLKSEL, address 0x4004 8070 */ +#define MAINCLKSEL_SEL_MASK 0x0003 // Clock source for main clock +#define MAINCLKSEL_SEL_SHIFT 0 + +/* MAINCLKUEN, address 0x4004 8074 */ +#define MAINCLKUEN_ENA (1 << 0) // Enable main clock source update 0 + +/* SYSAHBCLKDIV, address 0x4004 8078 */ +#define SYSAHBCLKDIV_DIV_MASK 0x00FF // System AHB clock divider values 0: System clock disabled. 1: Divide by 1. to 255: Divide by 255. +#define SYSAHBCLKDIV_DIV_SHIFT 0 + +/* SYSAHBCLKCTRL, address 0x4004 8080 */ +#define SYSAHBCLKCTRL_SYS (1 << 0) // Enables clock for AHB to APB bridge, to the AHB matrix, to the Cortex-M0 FCLK and HCLK, to the SysCon, and to the PMU. This bit is read only. +#define SYSAHBCLKCTRL_ROM (1 << 1) // Enables clock for ROM. +#define SYSAHBCLKCTRL_RAM (1 << 2) // Enables clock for RAM. +#define SYSAHBCLKCTRL_FLASHREG (1 << 3) // Enables clock for flash register interface. +#define SYSAHBCLKCTRL_FLASHARRAY (1 << 4) // Enables clock for flash array access. +#define SYSAHBCLKCTRL_I2C (1 << 5) // Enables clock for I2C. +#define SYSAHBCLKCTRL_GPIO (1 << 6) // Enables clock for GPIO. +#define SYSAHBCLKCTRL_CT16B0 (1 << 7) // Enables clock for 16-bit counter/timer 0. +#define SYSAHBCLKCTRL_CT16B1 (1 << 8) // Enables clock for 16-bit counter/timer 1. +#define SYSAHBCLKCTRL_CT32B0 (1 << 9) // Enables clock for 32-bit counter/timer 0. +#define SYSAHBCLKCTRL_CT32B1 (1 << 10) // Enables clock for 32-bit counter/timer 1. +#define SYSAHBCLKCTRL_SSP0 (1 << 11) // Enables clock for SPI0. +#define SYSAHBCLKCTRL_UART (1 << 12) // Enables clock for UART. See Section 3.1 for part specific details. +#define SYSAHBCLKCTRL_ADC (1 << 13) // Enables clock for ADC. +#define SYSAHBCLKCTRL_WDT (1 << 15) // Enables clock for WDT. +#define SYSAHBCLKCTRL_IOCON (1 << 16) // Enables clock for I/O configuration block. +#define SYSAHBCLKCTRL_CAN (1 << 17) // Enables clock for C_CAN. See Section 3.1 for part specific details. +#define SYSAHBCLKCTRL_SSP1 (1 << 18) // Enables clock for SPI1. + +/* SSP0CLKDIV, address 0x4004 8094 */ +#define SSP0CLKDIV_DIV_MASK 0x00FF // SPI0_PCLK clock divider values 0: Disable SPI0_PCLK. 1: Divide by 1. to 255: Divide by 255. +#define SSP0CLKDIV_DIV_SHIFT 0 + +/* UARTCLKDIV, address 0x4004 8098 */ +#define UARTCLKDIV_DIV_MASK 0x00FF // UART_PCLK clock divider values 0: Disable UART_PCLK. 1: Divide by 1. to 255: Divide by 255. +#define UARTCLKDIV_DIV_SHIFT 0 + +/* SSP1CLKDIV, address 0x4004 809C */ +#define SSP1CLKDIV_DIV_MASK 0x00FF // SPI1_PCLK clock divider values 0: Disable SPI1_PCLK. 1: Divide by 1. to 255: Divide by 255. +#define SSP1CLKDIV_DIV_SHIFT 0 + +/* WDTCLKSEL, address 0x4004 80D0 */ +#define WDTCLKSEL_SEL_MASK 0x0003 // WDT clock source +#define WDTCLKSEL_SEL_SHIFT 0 + +/* WDTCLKUEN, address 0x4004 80D4 */ +#define WDTCLKUEN_ENA (1 << 0) // Enable WDT clock source update + +/* WDTCLKDIV, address 0x4004 80D8 */ +#define WDTCLKDIV_DIV_MASK 0x00FF // WDT clock divider values 0: Disable WDCLK. 1: Divide by 1. to 255: Divide by 255. +#define WDTCLKDIV_DIV_SHIFT 0 + +/* CLKOUTCLKSEL, address 0x4004 80E0 */ +#define CLKOUTCLKSEL_SEL_MASK 0x0003 // CLKOUT clock source +#define CLKOUTCLKSEL_SEL_SHIFT 0 + +/* CLKOUTUEN, address 0x4004 80E4 */ +#define CLKOUTUEN_ENA (1 << 0) // Enable CLKOUT clock source update 0 + +/* CLKOUTCLKDIV, address 0x4004 80E8 */ +#define CLKOUTCLKDIV_DIV_MASK 0x00FF // Clock output divider values 0: Disable CLKOUT. 1: Divide by 1. to 255: Divide by 255. +#define CLKOUTCLKDIV_DIV_SHIFT 0 + +/* PIOPORCAP0, address 0x4004 8100 */ +#define PIOPORCAP0_CAPPIO0_N_MASK 0x0FFF // Raw reset status input PIO0_n: PIO0_11 to PIO0_0 +#define PIOPORCAP0_CAPPIO0_N_SHIFT 0 +#define PIOPORCAP0_CAPPIO1_N_MASK 0xFFF000 // Raw reset status input PIO1_n: PIO1_11 to PIO1_0 +#define PIOPORCAP0_CAPPIO1_N_SHIFT 12 +#define PIOPORCAP0_CAPPIO2_N_MASK 0xFF000000 // Raw reset status input PIO2_n: PIO2_7 to PIO2_0 +#define PIOPORCAP0_CAPPIO2_N_SHIFT 24 + +/* PIOPORCAP1, address 0x4004 8104 */ +#define PIOPORCAP1_CAPPIO2_8 (1 << 0) // Raw reset status input PIO2_8 +#define PIOPORCAP1_CAPPIO2_9 (1 << 1) // Raw reset status input PIO2_9 +#define PIOPORCAP1_CAPPIO2_10 (1 << 2) // Raw reset status input PIO2_10 +#define PIOPORCAP1_CAPPIO2_11 (1 << 3) // Raw reset status input PIO2_11 +#define PIOPORCAP1_CAPPIO3_0 (1 << 4) // Raw reset status input PIO3_0 +#define PIOPORCAP1_CAPPIO3_1 (1 << 5) // Raw reset status input PIO3_1 +#define PIOPORCAP1_CAPPIO3_2 (1 << 6) // Raw reset status input PIO3_2 +#define PIOPORCAP1_CAPPIO3_3 (1 << 7) // Raw reset status input PIO3_3 +#define PIOPORCAP1_CAPPIO3_4 (1 << 8) // Raw reset status input PIO3_4 +#define PIOPORCAP1_CAPPIO3_5 (1 << 9) // Raw reset status input PIO3_5 + +/* BODCTRL, address 0x4004 8150 */ +#define BODCTRL_BODRSTLEV_MASK 0x0003 // BOD reset level +#define BODCTRL_BODRSTLEV_SHIFT 0 +#define BODCTRL_BODINTVAL_MASK 0x000C // BOD interrupt level +#define BODCTRL_BODINTVAL_SHIFT 2 +#define BODCTRL_BODRSTENA (1 << 4) // BOD reset enable + +/* SYSTCKCAL, address 0x4004 8154 */ +#define SYSTCKCAL_CAL_MASK 0x3FFFFFF // System tick timer calibration value +#define SYSTCKCAL_CAL_SHIFT 0 + +/* NMISRC, address 0x4004 8174 */ +#define NMISRC_IRQNO_MASK 0x001F // The IRQ number of the interrupt that acts as the Non-Maskable Interrupt 0 (NMI) if bit 31 in this register is 1. See Table 54 for the list of interrupt sources and their IRQ numbers. +#define NMISRC_IRQNO_SHIFT 0 +#define NMISRC_NMIEN (1 << 31) // Write a 1 to this bit to enable the Non-Maskable Interrupt (NMI) source selected by bits 4:0. + +/* STARTAPRP0, address 0x4004 8200 */ +#define STARTAPRP0_APRPIO0_N_MASK 0x0FFF // Edge select for start logic input PIO0_n: PIO0_11 to PIO0_0 0 = Falling edge 1 = Rising edge +#define STARTAPRP0_APRPIO0_N_SHIFT 0 +#define STARTAPRP0_APRPIO1_0 (1 << 12) // Edge select for start logic input PIO1_0 0 = Falling edge 1 = Rising edge Reserved. Do not write a 1 to reserved bits in this register. + +/* STARTERP0, address 0x4004 8204 */ +#define STARTERP0_ERPIO0_N_MASK 0x0FFF // Enable start signal for start logic input PIO0_n: PIO0_11 to PIO0_0 0 = Disabled 1 = Enabled +#define STARTERP0_ERPIO0_N_SHIFT 0 +#define STARTERP0_ERPIO1_0 (1 << 12) // Enable start signal for start logic input PIO1_0 0 = Disabled 1 = Enabled Reserved. Do not write a 1 to reserved bits in this register. + +/* STARTRSRP0CLR, address 0x4004 8208 */ +#define STARTRSRP0CLR_RSRPIO0_N_MASK 0x0FFF // Start signal reset for start logic input PIO0_n:PIO0_11 to PIO0_0 0 = Do nothing. 1 = Writing 1 resets the start signal. +#define STARTRSRP0CLR_RSRPIO0_N_SHIFT 0 +#define STARTRSRP0CLR_RSRPIO1_0 (1 << 12) // Start signal reset for start logic input PIO1_0 0 = Do nothing. 1 = Writing 1 resets the start signal. + +/* STARTSRP0, address 0x4004 820C */ +#define STARTSRP0_SRPIO0_N_MASK 0x0FFF // Start signal status for start logic input PIO0_n: PIO0_11 to PIO0_0 0 = No start signal received. 1 = Start signal pending. +#define STARTSRP0_SRPIO0_N_SHIFT 0 +#define STARTSRP0_SRPIO1_0 (1 << 12) // Start signal status for start logic input PIO1_0 0 = No start signal received. 1 = Start signal pending. + +/* PDSLEEPCFG, address 0x4004 8230 */ +#define PDSLEEPCFG_BOD_PD (1 << 3) // BOD power-down control in Deep-sleep mode, see Table 40. +#define PDSLEEPCFG_WDTOSC_PD (1 << 6) // Watchdog oscillator power control in Deep-sleep mode, see Table 40. + +/* PDAWAKECFG, address 0x4004 8234 */ +#define PDAWAKECFG_IRCOUT_PD (1 << 0) // IRC oscillator output wake-up configuration +#define PDAWAKECFG_IRC_PD (1 << 1) // IRC oscillator power-down wake-up configuration +#define PDAWAKECFG_FLASH_PD (1 << 2) // Flash wake-up configuration +#define PDAWAKECFG_BOD_PD (1 << 3) // BOD wake-up configuration +#define PDAWAKECFG_ADC_PD (1 << 4) // ADC wake-up configuration +#define PDAWAKECFG_SYSOSC_PD (1 << 5) // System oscillator wake-up configuration +#define PDAWAKECFG_WDTOSC_PD (1 << 6) // Watchdog oscillator wake-up configuration +#define PDAWAKECFG_SYSPLL_PD (1 << 7) // System PLL wake-up configuration + +/* PDRUNCFG, address 0x4004 8238 */ +#define PDRUNCFG_IRCOUT_PD (1 << 0) // IRC oscillator output power-down +#define PDRUNCFG_IRC_PD (1 << 1) // IRC oscillator power-down +#define PDRUNCFG_FLASH_PD (1 << 2) // Flash power-down +#define PDRUNCFG_BOD_PD (1 << 3) // BOD power-down +#define PDRUNCFG_ADC_PD (1 << 4) // ADC power-down +#define PDRUNCFG_SYSOSC_PD (1 << 5) // System oscillator power-down +#define PDRUNCFG_WDTOSC_PD (1 << 6) // Watchdog oscillator power-down +#define PDRUNCFG_SYSPLL_PD (1 << 7) // System PLL power-down + +/* DEVICE_ID, address 0x4004 83F4 */ +#define DEVICE_ID_DEVICEID_MASK 0xFFFFFFFF // Part ID numbers for LPC111x/LPC11Cxx parts +#define DEVICE_ID_DEVICEID_SHIFT 0 + +/* FLASHCFG, address 0x4003 C010 */ +#define FLASHCFG_FLASHTIM_MASK 0x0003 // Flash memory access time. FLASHTIM +1 is equal to the number of system clocks used for flash access. +#define FLASHCFG_FLASHTIM_SHIFT 0 + +/* PCON, address 0x4003 8000 */ +#define PCON_DPDEN (1 << 1) // Deep power-down mode enable +#define PCON_SLEEPFLAG (1 << 8) // Sleep mode flag +#define PCON_DPDFLAG (1 << 11) // Deep power-down flag + +/* GPREG0 - GPREG3, address 0x4003 8004 to 0x4003 8010 */ +#define GPREGn_GPDATA_MASK 0xFFFFFFFF // Data retained during Deep power-down mode. +#define GPREGn_GPDATA_SHIFT 0 + +/* GPREG4, address 0x4003 8014 */ +#define GPREG4_WAKEUPHYS (1 << 10) // WAKEUP pin hysteresis enable +#define GPREG4_GPDATA_MASK 0xFFFFF800 // Data retained during Deep power-down mode. +#define GPREG4_GPDATA_SHIFT 11 + +/* IOCON_PIO2_6, address 0x4004 4000 */ +#define IOCON_PIO2_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_6_FUNC_SHIFT 0 +#define IOCON_PIO2_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_6_MODE_SHIFT 3 +#define IOCON_PIO2_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_6_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_0, address 0x4004 4008 */ +#define IOCON_PIO2_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_0_FUNC_SHIFT 0 +#define IOCON_PIO2_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_0_MODE_SHIFT 3 +#define IOCON_PIO2_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_0_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_RESET_PIO0_0, address 0x4004 400C */ +#define IOCON_RESET_PIO0_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_RESET_PIO0_0_FUNC_SHIFT 0 +#define IOCON_RESET_PIO0_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_RESET_PIO0_0_MODE_SHIFT 3 +#define IOCON_RESET_PIO0_0_HYS (1 << 5) // Hysteresis. +#define IOCON_RESET_PIO0_0_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_1, address 0x4004 4010 */ +#define IOCON_PIO0_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_1_FUNC_SHIFT 0 +#define IOCON_PIO0_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_1_MODE_SHIFT 3 +#define IOCON_PIO0_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_8, address 0x4004 4014 */ +#define IOCON_PIO1_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_8_FUNC_SHIFT 0 +#define IOCON_PIO1_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_8_MODE_SHIFT 3 +#define IOCON_PIO1_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_8_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_2, address 0x4004 401C */ +#define IOCON_PIO0_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_2_FUNC_SHIFT 0 +#define IOCON_PIO0_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_2_MODE_SHIFT 3 +#define IOCON_PIO0_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_2_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_7, address 0x4004 4020 */ +#define IOCON_PIO2_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_7_FUNC_SHIFT 0 +#define IOCON_PIO2_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_7_MODE_SHIFT 3 +#define IOCON_PIO2_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_7_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_8, address 0x4004 4024 */ +#define IOCON_PIO2_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_8_FUNC_SHIFT 0 +#define IOCON_PIO2_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_8_MODE_SHIFT 3 +#define IOCON_PIO2_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_8_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_1, address 0x4004 4028 */ +#define IOCON_PIO2_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_1_FUNC_SHIFT 0 +#define IOCON_PIO2_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_1_MODE_SHIFT 3 +#define IOCON_PIO2_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_3, address 0x4004 402C */ +#define IOCON_PIO0_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_3_FUNC_SHIFT 0 +#define IOCON_PIO0_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_3_MODE_SHIFT 3 +#define IOCON_PIO0_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_4, address 0x4004 4030 */ +#define IOCON_PIO0_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_4_FUNC_SHIFT 0 +#define IOCON_PIO0_4_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, 00 default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_4_I2CMODE_SHIFT 8 + +/* IOCON_PIO0_5, address 0x4004 4034 */ +#define IOCON_PIO0_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_5_FUNC_SHIFT 0 +#define IOCON_PIO0_5_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_5_I2CMODE_SHIFT 8 + +/* IOCON_PIO1_9, address 0x4004 4038 */ +#define IOCON_PIO1_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_9_FUNC_SHIFT 0 +#define IOCON_PIO1_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_9_MODE_SHIFT 3 +#define IOCON_PIO1_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_9_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_4, address 0x4004 403C */ +#define IOCON_PIO3_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_4_FUNC_SHIFT 0 +#define IOCON_PIO3_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_4_MODE_SHIFT 3 +#define IOCON_PIO3_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_4_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_4, address 0x4004 4040 */ +#define IOCON_PIO2_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_4_FUNC_SHIFT 0 +#define IOCON_PIO2_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_4_MODE_SHIFT 3 +#define IOCON_PIO2_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_4_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_5, address 0x4004 4044 */ +#define IOCON_PIO2_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_5_FUNC_SHIFT 0 +#define IOCON_PIO2_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_5_MODE_SHIFT 3 +#define IOCON_PIO2_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_5, address 0x4004 4048 */ +#define IOCON_PIO3_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_5_FUNC_SHIFT 0 +#define IOCON_PIO3_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_5_MODE_SHIFT 3 +#define IOCON_PIO3_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_5_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_6, address 0x4004 404C */ +#define IOCON_PIO0_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_6_FUNC_SHIFT 0 +#define IOCON_PIO0_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_6_MODE_SHIFT 3 +#define IOCON_PIO0_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_6_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_7, address 0x4004 4050 */ +#define IOCON_PIO0_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_7_FUNC_SHIFT 0 +#define IOCON_PIO0_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_7_MODE_SHIFT 3 +#define IOCON_PIO0_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_7_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_9, address 0x4004 4054 */ +#define IOCON_PIO2_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_9_FUNC_SHIFT 0 +#define IOCON_PIO2_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_9_MODE_SHIFT 3 +#define IOCON_PIO2_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_9_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_10, address 0x4004 4058 */ +#define IOCON_PIO2_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_10_FUNC_SHIFT 0 +#define IOCON_PIO2_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_10_MODE_SHIFT 3 +#define IOCON_PIO2_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_10_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_2, address 0x4004 405C */ +#define IOCON_PIO2_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_2_FUNC_SHIFT 0 +#define IOCON_PIO2_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_2_MODE_SHIFT 3 +#define IOCON_PIO2_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_8, address 0x4004 4060 */ +#define IOCON_PIO0_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_8_FUNC_SHIFT 0 +#define IOCON_PIO0_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_8_MODE_SHIFT 3 +#define IOCON_PIO0_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_8_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_9, address 0x4004 4064 */ +#define IOCON_PIO0_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_9_FUNC_SHIFT 0 +#define IOCON_PIO0_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_9_MODE_SHIFT 3 +#define IOCON_PIO0_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_9_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_SWCLK_PIO0_10, address 0x4004 4068 */ +#define IOCON_SWCLK_PIO0_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWCLK_PIO0_10_FUNC_SHIFT 0 +#define IOCON_SWCLK_PIO0_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWCLK_PIO0_10_MODE_SHIFT 3 +#define IOCON_SWCLK_PIO0_10_HYS (1 << 5) // Hysteresis. +#define IOCON_SWCLK_PIO0_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_10, address 0x4004 406C */ +#define IOCON_PIO1_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_10_FUNC_SHIFT 0 +#define IOCON_PIO1_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_10_MODE_SHIFT 3 +#define IOCON_PIO1_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_10_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_10_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_11, address 0x4004 4070 */ +#define IOCON_PIO2_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_11_FUNC_SHIFT 0 +#define IOCON_PIO2_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_11_MODE_SHIFT 3 +#define IOCON_PIO2_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_11_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_R_PIO0_11, address 0x4004 4074 */ +#define IOCON_R_PIO0_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO0_11_FUNC_SHIFT 0 +#define IOCON_R_PIO0_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO0_11_MODE_SHIFT 3 +#define IOCON_R_PIO0_11_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO0_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO0_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_0, address 0x4004 4078 */ +#define IOCON_R_PIO1_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_0_FUNC_SHIFT 0 +#define IOCON_R_PIO1_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_0_MODE_SHIFT 3 +#define IOCON_R_PIO1_0_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_0_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_0_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_R_PIO1_1, address 0x4004 407C */ +#define IOCON_R_PIO1_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_1_FUNC_SHIFT 0 +#define IOCON_R_PIO1_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_1_MODE_SHIFT 3 +#define IOCON_R_PIO1_1_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_1_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_R_PIO1_2, address 0x4004 4080 */ +#define IOCON_R_PIO1_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_2_FUNC_SHIFT 0 +#define IOCON_R_PIO1_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_2_MODE_SHIFT 3 +#define IOCON_R_PIO1_2_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_2_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_2_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_0, address 0x4004 4084 */ +#define IOCON_PIO3_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_0_FUNC_SHIFT 0 +#define IOCON_PIO3_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_0_MODE_SHIFT 3 +#define IOCON_PIO3_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_1, address 0x4004 4088 */ +#define IOCON_PIO3_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_1_FUNC_SHIFT 0 +#define IOCON_PIO3_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_1_MODE_SHIFT 3 +#define IOCON_PIO3_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_3, address 0x4004 408C */ +#define IOCON_PIO2_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_3_FUNC_SHIFT 0 +#define IOCON_PIO2_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_3_MODE_SHIFT 3 +#define IOCON_PIO2_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_3_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_SWDIO_PIO1_3, address 0x4004 4090 */ +#define IOCON_SWDIO_PIO1_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWDIO_PIO1_3_FUNC_SHIFT 0 +#define IOCON_SWDIO_PIO1_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWDIO_PIO1_3_MODE_SHIFT 3 +#define IOCON_SWDIO_PIO1_3_HYS (1 << 5) // Hysteresis. +#define IOCON_SWDIO_PIO1_3_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_SWDIO_PIO1_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_4, address 0x4004 4094 */ +#define IOCON_PIO1_4_FUNC_MASK 0x0007 // Selects pin function. This pin functions as WAKEUP pin if the 000 LPC111x/LPC11Cxx is in Deep power-down mode regardless of the value of FUNC. All other values are reserved. +#define IOCON_PIO1_4_FUNC_SHIFT 0 +#define IOCON_PIO1_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_4_MODE_SHIFT 3 +#define IOCON_PIO1_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_4_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_4_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_11, address 0x4004 4098 */ +#define IOCON_PIO1_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_11_FUNC_SHIFT 0 +#define IOCON_PIO1_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_11_MODE_SHIFT 3 +#define IOCON_PIO1_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_11_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_2, address 0x4004 409C */ +#define IOCON_PIO3_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_2_FUNC_SHIFT 0 +#define IOCON_PIO3_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_2_MODE_SHIFT 3 +#define IOCON_PIO3_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_5, address 0x4004 40A0 */ +#define IOCON_PIO1_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_5_FUNC_SHIFT 0 +#define IOCON_PIO1_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_5_MODE_SHIFT 3 +#define IOCON_PIO1_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_5_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_6, address 0x4004 40A4 */ +#define IOCON_PIO1_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_6_FUNC_SHIFT 0 +#define IOCON_PIO1_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_6_MODE_SHIFT 3 +#define IOCON_PIO1_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_6_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_7, address 0x4004 40A8 */ +#define IOCON_PIO1_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_7_FUNC_SHIFT 0 +#define IOCON_PIO1_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_7_MODE_SHIFT 3 +#define IOCON_PIO1_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_7_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_3, address 0x4004 40AC */ +#define IOCON_PIO3_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_3_FUNC_SHIFT 0 +#define IOCON_PIO3_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_3_MODE_SHIFT 3 +#define IOCON_PIO3_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_3_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_SCK_LOC, address 0x4004 40B0 */ +#define IOCON_SCK_LOC_SCKLOC_MASK 0x0003 // Selects pin location for SCK0 function. +#define IOCON_SCK_LOC_SCKLOC_SHIFT 0 + +/* IOCON_DSR_LOC, address 0x4004 40B4 */ +#define IOCON_DSR_LOC_DSRLOC_MASK 0x0003 // elects pin location for DSR function. +#define IOCON_DSR_LOC_DSRLOC_SHIFT 0 + +/* IOCON_DCD_LOC, address 0x4004 40B8 */ +#define IOCON_DCD_LOC_DCDLOC_MASK 0x0003 // Selects pin location for DCD function. +#define IOCON_DCD_LOC_DCDLOC_SHIFT 0 + +/* IOCON_RI_LOC, address 0x4004 40BC */ +#define IOCON_RI_LOC_RILOC_MASK 0x0003 // Selects pin location for RI function. +#define IOCON_RI_LOC_RILOC_SHIFT 0 + +/* IOCON_PIO2_6, address 0x4004 4000 */ +#define IOCON_PIO2_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_6_FUNC_SHIFT 0 +#define IOCON_PIO2_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_6_MODE_SHIFT 3 +#define IOCON_PIO2_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_6_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_0, address 0x4004 4008 */ +#define IOCON_PIO2_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_0_FUNC_SHIFT 0 +#define IOCON_PIO2_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_0_MODE_SHIFT 3 +#define IOCON_PIO2_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_RESET_PIO0_0, address 0x4004 400C */ +#define IOCON_RESET_PIO0_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_RESET_PIO0_0_FUNC_SHIFT 0 +#define IOCON_RESET_PIO0_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_RESET_PIO0_0_MODE_SHIFT 3 +#define IOCON_RESET_PIO0_0_HYS (1 << 5) // Hysteresis. +#define IOCON_RESET_PIO0_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_1, address 0x4004 4010 */ +#define IOCON_PIO0_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_1_FUNC_SHIFT 0 +#define IOCON_PIO0_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_1_MODE_SHIFT 3 +#define IOCON_PIO0_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_8, address 0x4004 4014 */ +#define IOCON_PIO1_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_8_FUNC_SHIFT 0 +#define IOCON_PIO1_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_8_MODE_SHIFT 3 +#define IOCON_PIO1_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_8_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_2, address 0x4004 401C */ +#define IOCON_PIO0_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_2_FUNC_SHIFT 0 +#define IOCON_PIO0_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_2_MODE_SHIFT 3 +#define IOCON_PIO0_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_7, address 0x4004 4020 */ +#define IOCON_PIO2_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_7_FUNC_SHIFT 0 +#define IOCON_PIO2_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_7_MODE_SHIFT 3 +#define IOCON_PIO2_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_7_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_8, address 0x4004 4024 */ +#define IOCON_PIO2_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_8_FUNC_SHIFT 0 +#define IOCON_PIO2_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_8_MODE_SHIFT 3 +#define IOCON_PIO2_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_8_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_1, address 0x4004 4028 */ +#define IOCON_PIO2_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_1_FUNC_SHIFT 0 +#define IOCON_PIO2_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_1_MODE_SHIFT 3 +#define IOCON_PIO2_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_3, address 0x4004 402C */ +#define IOCON_PIO0_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_3_FUNC_SHIFT 0 +#define IOCON_PIO0_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_3_MODE_SHIFT 3 +#define IOCON_PIO0_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_4, address 0x4004 4030 */ +#define IOCON_PIO0_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_4_FUNC_SHIFT 0 +#define IOCON_PIO0_4_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, 00 default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_4_I2CMODE_SHIFT 8 + +/* IOCON_PIO0_5, address 0x4004 4034 */ +#define IOCON_PIO0_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_5_FUNC_SHIFT 0 +#define IOCON_PIO0_5_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_5_I2CMODE_SHIFT 8 + +/* IOCON_PIO1_9, address 0x4004 4038 */ +#define IOCON_PIO1_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_9_FUNC_SHIFT 0 +#define IOCON_PIO1_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_9_MODE_SHIFT 3 +#define IOCON_PIO1_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_9_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_4, address 0x4004 403C */ +#define IOCON_PIO3_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_4_FUNC_SHIFT 0 +#define IOCON_PIO3_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_4_MODE_SHIFT 3 +#define IOCON_PIO3_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_4_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_4, address 0x4004 4040 */ +#define IOCON_PIO2_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_4_FUNC_SHIFT 0 +#define IOCON_PIO2_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_4_MODE_SHIFT 3 +#define IOCON_PIO2_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_4_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_5, address 0x4004 4044 */ +#define IOCON_PIO2_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_5_FUNC_SHIFT 0 +#define IOCON_PIO2_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_5_MODE_SHIFT 3 +#define IOCON_PIO2_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_5, address 0x4004 4048 */ +#define IOCON_PIO3_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_5_FUNC_SHIFT 0 +#define IOCON_PIO3_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_5_MODE_SHIFT 3 +#define IOCON_PIO3_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_6, address 0x4004 404C */ +#define IOCON_PIO0_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_6_FUNC_SHIFT 0 +#define IOCON_PIO0_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_6_MODE_SHIFT 3 +#define IOCON_PIO0_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_6_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_7, address 0x4004 4050 */ +#define IOCON_PIO0_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_7_FUNC_SHIFT 0 +#define IOCON_PIO0_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_7_MODE_SHIFT 3 +#define IOCON_PIO0_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_7_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_9, address 0x4004 4054 */ +#define IOCON_PIO2_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_9_FUNC_SHIFT 0 +#define IOCON_PIO2_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_9_MODE_SHIFT 3 +#define IOCON_PIO2_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_9_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_10, address 0x4004 4058 */ +#define IOCON_PIO2_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_10_FUNC_SHIFT 0 +#define IOCON_PIO2_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_10_MODE_SHIFT 3 +#define IOCON_PIO2_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_2, address 0x4004 405C */ +#define IOCON_PIO2_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_2_FUNC_SHIFT 0 +#define IOCON_PIO2_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_2_MODE_SHIFT 3 +#define IOCON_PIO2_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_8, address 0x4004 4060 */ +#define IOCON_PIO0_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_8_FUNC_SHIFT 0 +#define IOCON_PIO0_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_8_MODE_SHIFT 3 +#define IOCON_PIO0_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_8_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_9, address 0x4004 4064 */ +#define IOCON_PIO0_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_9_FUNC_SHIFT 0 +#define IOCON_PIO0_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_9_MODE_SHIFT 3 +#define IOCON_PIO0_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_9_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_SWCLK_PIO0_10, address 0x4004 4068 */ +#define IOCON_SWCLK_PIO0_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWCLK_PIO0_10_FUNC_SHIFT 0 +#define IOCON_SWCLK_PIO0_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWCLK_PIO0_10_MODE_SHIFT 3 +#define IOCON_SWCLK_PIO0_10_HYS (1 << 5) // Hysteresis. +#define IOCON_SWCLK_PIO0_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_10, address 0x4004 406C */ +#define IOCON_PIO1_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_10_FUNC_SHIFT 0 +#define IOCON_PIO1_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_10_MODE_SHIFT 3 +#define IOCON_PIO1_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_10_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_11, address 0x4004 4070 */ +#define IOCON_PIO2_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_11_FUNC_SHIFT 0 +#define IOCON_PIO2_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_11_MODE_SHIFT 3 +#define IOCON_PIO2_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO0_11, address 0x4004 4074 */ +#define IOCON_R_PIO0_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO0_11_FUNC_SHIFT 0 +#define IOCON_R_PIO0_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO0_11_MODE_SHIFT 3 +#define IOCON_R_PIO0_11_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO0_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO0_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_0, address 0x4004 4078 */ +#define IOCON_R_PIO1_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_0_FUNC_SHIFT 0 +#define IOCON_R_PIO1_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_0_MODE_SHIFT 3 +#define IOCON_R_PIO1_0_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_0_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_1, address 0x4004 407C */ +#define IOCON_R_PIO1_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_1_FUNC_SHIFT 0 +#define IOCON_R_PIO1_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_1_MODE_SHIFT 3 +#define IOCON_R_PIO1_1_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_1_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_2, address 0x4004 4080 */ +#define IOCON_R_PIO1_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_2_FUNC_SHIFT 0 +#define IOCON_R_PIO1_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_2_MODE_SHIFT 3 +#define IOCON_R_PIO1_2_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_2_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_0, address 0x4004 4084 */ +#define IOCON_PIO3_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_0_FUNC_SHIFT 0 +#define IOCON_PIO3_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_0_MODE_SHIFT 3 +#define IOCON_PIO3_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_1, address 0x4004 4088 */ +#define IOCON_PIO3_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_1_FUNC_SHIFT 0 +#define IOCON_PIO3_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_1_MODE_SHIFT 3 +#define IOCON_PIO3_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_3, address 0x4004 408C */ +#define IOCON_PIO2_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_3_FUNC_SHIFT 0 +#define IOCON_PIO2_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_3_MODE_SHIFT 3 +#define IOCON_PIO2_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_SWDIO_PIO1_3, address 0x4004 4090 */ +#define IOCON_SWDIO_PIO1_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWDIO_PIO1_3_FUNC_SHIFT 0 +#define IOCON_SWDIO_PIO1_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWDIO_PIO1_3_MODE_SHIFT 3 +#define IOCON_SWDIO_PIO1_3_HYS (1 << 5) // Hysteresis. +#define IOCON_SWDIO_PIO1_3_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_SWDIO_PIO1_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_4, address 0x4004 4094 */ +#define IOCON_PIO1_4_FUNC_MASK 0x0007 // Selects pin function. This pin functions as WAKEUP pin if the 000 LPC111x/LPC11Cxx is in Deep power-down mode regardless of the value of FUNC. All other values are reserved. +#define IOCON_PIO1_4_FUNC_SHIFT 0 +#define IOCON_PIO1_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_4_MODE_SHIFT 3 +#define IOCON_PIO1_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_4_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_4_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_11, address 0x4004 4098 */ +#define IOCON_PIO1_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_11_FUNC_SHIFT 0 +#define IOCON_PIO1_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_11_MODE_SHIFT 3 +#define IOCON_PIO1_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_2, address 0x4004 409C */ +#define IOCON_PIO3_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_2_FUNC_SHIFT 0 +#define IOCON_PIO3_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_2_MODE_SHIFT 3 +#define IOCON_PIO3_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_5, address 0x4004 40A0 */ +#define IOCON_PIO1_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_5_FUNC_SHIFT 0 +#define IOCON_PIO1_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_5_MODE_SHIFT 3 +#define IOCON_PIO1_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_6, address 0x4004 40A4 */ +#define IOCON_PIO1_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_6_FUNC_SHIFT 0 +#define IOCON_PIO1_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_6_MODE_SHIFT 3 +#define IOCON_PIO1_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_6_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_7, address 0x4004 40A8 */ +#define IOCON_PIO1_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_7_FUNC_SHIFT 0 +#define IOCON_PIO1_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_7_MODE_SHIFT 3 +#define IOCON_PIO1_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_7_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_3, address 0x4004 40AC */ +#define IOCON_PIO3_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_3_FUNC_SHIFT 0 +#define IOCON_PIO3_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_3_MODE_SHIFT 3 +#define IOCON_PIO3_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_SCK0_LOC, address 0x4004 40B0 */ +#define IOCON_SCK0_LOC_SCKLOC_MASK 0x0003 // Selects pin location for SCK0 function. +#define IOCON_SCK0_LOC_SCKLOC_SHIFT 0 + +/* IOCON_DSR_LOC, address 0x4004 40B4 */ +#define IOCON_DSR_LOC_DSRLOC_MASK 0x0003 // elects pin location for DSR function. +#define IOCON_DSR_LOC_DSRLOC_SHIFT 0 + +/* IOCON_DCD_LOC, address 0x4004 40B8 */ +#define IOCON_DCD_LOC_DCDLOC_MASK 0x0003 // Selects pin location for DCD function. +#define IOCON_DCD_LOC_DCDLOC_SHIFT 0 + +/* IOCON_RI_LOC, address 0x4004 40BC */ +#define IOCON_RI_LOC_RILOC_MASK 0x0003 // Selects pin location for RI function. +#define IOCON_RI_LOC_RILOC_SHIFT 0 + +/* IOCON_SSEL1_LOC, address 0x4004 4018 */ +#define IOCON_SSEL1_LOC_SSEL1LOC_MASK 0x0003 // Selects pin location for SSEL1 function. +#define IOCON_SSEL1_LOC_SSEL1LOC_SHIFT 0 + +/* IOCON_CT16B0_CAP0_LOC, address 0x4004 40C0 */ +#define IOCON_CT16B0_CAP0_LOC_CT16B0_CAP0LOC_MASK 0x0003 // Selects pin location for CT16B0_CAP0 function. +#define IOCON_CT16B0_CAP0_LOC_CT16B0_CAP0LOC_SHIFT 0 + +/* IOCON_SCK1_LOC, address 0x4004 40C4 */ +#define IOCON_SCK1_LOC_SCK1LOC_MASK 0x0003 // Selects pin location for SCK1 function. +#define IOCON_SCK1_LOC_SCK1LOC_SHIFT 0 + +/* IOCON_MISO1_LOC, address 0x4004 40C8 */ +#define IOCON_MISO1_LOC_MISO1LOC_MASK 0x0003 // Selects pin location for the MISO1 function. +#define IOCON_MISO1_LOC_MISO1LOC_SHIFT 0 + +/* IOCON_MOSI1_LOC, address 0x4004 40CC */ +#define IOCON_MOSI1_LOC_MOSI1LOC_MASK 0x0003 // Selects pin location for the MOSI1 function. +#define IOCON_MOSI1_LOC_MOSI1LOC_SHIFT 0 + +/* IOCON_CT32B0_CAP0_LOC, address 0x4004 40D0 */ +#define IOCON_CT32B0_CAP0_LOC_CT32B0_CAP0LOC_MASK 0x0003 // Selects pin location for the CT32B0_CAP0 function. +#define IOCON_CT32B0_CAP0_LOC_CT32B0_CAP0LOC_SHIFT 0 + +/* IOCON_RXD_LOC, address 0x4004 40D4 */ +#define IOCON_RXD_LOC_RXDLOC_MASK 0x0003 // Selects pin location for the RXD function. +#define IOCON_RXD_LOC_RXDLOC_SHIFT 0 + +/* GPIO0DIR, address 0x5000 8000 to GPIO3DIR, address 0x5003 8000 */ +#define GPIO0DIR_IO_MASK 0x0FFF // Selects pin x as input or output (x = 0 to 11). 0 = Pin PIOn_x is configured as input. 1 = Pin PIOn_x is configured as output. +#define GPIO0DIR_IO_SHIFT 0 + +/* GPIO0IS, address 0x5000 8004 to GPIO3IS, address 0x5003 8004 */ +#define GPIO0IS_ISENSE_MASK 0x0FFF // Selects interrupt on pin x as level or edge sensitive (x = 0 to 0x00 11). 0 = Interrupt on pin PIOn_x is configured as edge sensitive. 1 = Interrupt on pin PIOn_x is configured as level sensitive. +#define GPIO0IS_ISENSE_SHIFT 0 + +/* GPIO0IBE, address 0x5000 8008 to GPIO3IBE, address 0x5003 8008 */ +#define GPIO0IBE_IBE_MASK 0x0FFF // Selects interrupt on pin x to be triggered on both edges (x = 0 0x00 to 11). 0 = Interrupt on pin PIOn_x is controlled through register GPIOnIEV. 1 = Both edges on pin PIOn_x trigger an interrupt. +#define GPIO0IBE_IBE_SHIFT 0 + +/* GPIO0IEV, address 0x5000 800C to GPIO3IEV, address 0x5003 800C */ +#define GPIO0IEV_IEV_MASK 0x0FFF // Selects interrupt on pin x to be triggered rising or falling edges (x = 0 to 11). 0 = Depending on setting in register GPIOnIS (see Table 175), falling edges or LOW level on pin PIOn_x trigger an interrupt. 1 = Depending on setting in register GPIOnIS (see Table 175), rising edges or HIGH level on pin PIOn_x trigger an interrupt. +#define GPIO0IEV_IEV_SHIFT 0 + +/* GPIO0IE, address 0x5000 8010 to GPIO3IE, address 0x5003 8010 */ +#define GPIO0IE_MASK_MASK 0x0FFF // Selects interrupt on pin x to be masked (x = 0 to 11). 0 = Interrupt on pin PIOn_x is masked. 1 = Interrupt on pin PIOn_x is not masked. +#define GPIO0IE_MASK_SHIFT 0 + +/* GPIO0RIS, address 0x5000 8014 to GPIO3RIS, address 0x5003 8014 */ +#define GPIO0RIS_RAWST_MASK 0x0FFF // Raw interrupt status (x = 0 to 11). 0 = No interrupt on pin PIOn_x. 1 = Interrupt requirements met on PIOn_x. +#define GPIO0RIS_RAWST_SHIFT 0 + +/* GPIO0MIS, address 0x5000 8018 to GPIO3MIS, address 0x5003 8018 */ +#define GPIO0MIS_MASK_MASK 0x0FFF // Selects interrupt on pin x to be masked (x = 0 to 11). 0 = No interrupt or interrupt masked on pin PIOn_x. 1 = Interrupt on PIOn_x. +#define GPIO0MIS_MASK_SHIFT 0 + +/* GPIO0IC, address 0x5000 801C to GPIO3IC, address 0x5003 801C */ +#define GPIO0IC_CLR_MASK 0x0FFF // Selects interrupt on pin x to be cleared (x = 0 to 11). Clears 0x00 the interrupt edge detection logic. This register is write-only. Remark: The synchronizer between the GPIO and the NVIC blocks causes a delay of 2 clocks. It is recommended to add two NOPs after the clear of the interrupt edge detection logic before the exit of the interrupt service routine. 0 = No effect. 1 = Clears edge detection logic for pin PIOn_x. +#define GPIO0IC_CLR_SHIFT 0 + +/* U0IIR - address 0x4004 8008, Read Only */ +#define U0IIR_INTSTATUS (1 << 0) // Interrupt status. Note that U0IIR[0] is active low. The pending interrupt can be determined by evaluating U0IIR[3:1]. +#define U0IIR_INTID_MASK 0x000E // Interrupt identification. U0IER[3:1] identifies an interrupt 0 corresponding to the UART Rx FIFO. All other combinations of U0IER[3:1] not listed below are reserved (100,101,111). +#define U0IIR_INTID_SHIFT 1 +#define U0IIR_FIFOENABLE_MASK 0x00C0 // These bits are equivalent to U0FCR[0]. +#define U0IIR_FIFOENABLE_SHIFT 6 +#define U0IIR_ABEOINT (1 << 8) // End of auto-baud interrupt. True if auto-baud has finished successfully and interrupt is enabled. +#define U0IIR_ABTOINT (1 << 9) // Auto-baud time-out interrupt. True if auto-baud has timed out and interrupt is enabled. Reserved, user software should not write ones to reserved bits. The value read from a reserved bit is not defined. + +/* U0FCR - address 0x4000 8008, Write Only */ +#define U0FCR_FIFOEN (1 << 0) // FIFO Enable +#define U0FCR_RXFIFORES (1 << 1) // RX FIFO Reset +#define U0FCR_TXFIFORES (1 << 2) // TX FIFO Reset +#define U0FCR_RXTL_MASK 0x00C0 // RX Trigger Level. These two bits determine how many 0 receiver UART FIFO characters must be written before an interrupt is activated. +#define U0FCR_RXTL_SHIFT 6 + +/* U0LCR - address 0x4000 800C */ +#define U0LCR_WLS_MASK 0x0003 // Word Length Select +#define U0LCR_WLS_SHIFT 0 +#define U0LCR_SBS (1 << 2) // Stop Bit Select +#define U0LCR_PE (1 << 3) // Parity Enable +#define U0LCR_PS_MASK 0x0030 // Parity Select 0x0 Odd parity. Number of 1s in the transmitted character and the attached parity bit will be odd. 0x1 Even Parity. Number of 1s in the transmitted character and the attached parity bit will be even. 0x2 Forced 1 stick parity. 0x3 Forced 0 stick parity. +#define U0LCR_PS_SHIFT 4 +#define U0LCR_BC (1 << 6) // Break Control +#define U0LCR_DLAB (1 << 7) // Divisor Latch Access Bit + +/* U0MCR - address 0x4000 8010 */ +#define U0MCR_DTRC (1 << 0) // DTR Control. Source for modem output pin, DTR. This bit reads as 0 when modem loopback mode is active. +#define U0MCR_RTSC (1 << 1) // RTS Control. Source for modem output pin RTS. This bit reads as 0 0 when modem loopback mode is active. +#define U0MCR_LMS (1 << 4) // Loopback Mode Select. The modem loopback mode provides a 0 mechanism to perform diagnostic loopback testing. Serial data from the transmitter is connected internally to serial input of the receiver. Input pin, RXD, has no effect on loopback and output pin, TXD is held in marking state. The four modem inputs (CTS, DSR, RI and DCD) are disconnected externally. Externally, the modem outputs (RTS, DTR) are set inactive. Internally, the four modem outputs are connected to the four modem inputs. As a result of these connections, the upper four bits of the U0MSR will be driven by the lower four bits of the U0MCR rather than the four modem inputs in normal mode. This permits modem status interrupts to be generated in loopback mode by writing the lower four bits of U0MCR. +#define U0MCR_RTSEN (1 << 6) // RTS flow control +#define U0MCR_CTSEN (1 << 7) // CTS flow control + +/* U0LSR - address 0x4000 8014, Read Only */ +#define U0LSR_RDR (1 << 0) // Receiver Data Ready. U0LSR[0] is set when the U0RBR holds 0 an unread character and is cleared when the UART RBR FIFO is empty. +#define U0LSR_OE (1 << 1) // Overrun Error. The overrun error condition is set as soon as it 0 occurs. A U0LSR read clears U0LSR[1]. U0LSR[1] is set when UART RSR has a new character assembled and the UART RBR FIFO is full. In this case, the UART RBR FIFO will not be overwritten and the character in the UART RSR will be lost. +#define U0LSR_PE (1 << 2) // Parity Error. When the parity bit of a received character is in the wrong state, a parity error occurs. A U0LSR read clears U0LSR[2]. Time of parity error detection is dependent on U0FCR[0]. Note: A parity error is associated with the character at the top of the UART RBR FIFO. +#define U0LSR_FE (1 << 3) // Framing Error. When the stop bit of a received character is a 0 logic 0, a framing error occurs. A U0LSR read clears U0LSR[3]. The time of the framing error detection is dependent on U0FCR0. Upon detection of a framing error, the RX will attempt to re-synchronize to the data and assume that the bad stop bit is actually an early start bit. However, it cannot be assumed that the next received byte will be correct even if there is no Framing Error. Note: A framing error is associated with the character at the top of the UART RBR FIFO. +#define U0LSR_BI (1 << 4) // Break Interrupt. When RXD1 is held in the spacing state (all zeros) for one full character transmission (start, data, parity, stop), a break interrupt occurs. Once the break condition has been detected, the receiver goes idle until RXD1 goes to marking state (all ones). A U0LSR read clears this status bit. The time of break detection is dependent on U0FCR[0]. Note: The break interrupt is associated with the character at the top of the UART RBR FIFO. +#define U0LSR_THRE (1 << 5) // Transmitter Holding Register Empty. THRE is set immediately 1 upon detection of an empty UART THR and is cleared on a U0THR write. +#define U0LSR_TEMT (1 << 6) // Transmitter Empty. TEMT is set when both U0THR and 1 U0TSR are empty; TEMT is cleared when either the U0TSR or the U0THR contain valid data. This bit is updated as soon as 50 % of the first stop bit has been transmitted or a byte has been written into the THR. +#define U0LSR_RXFE (1 << 7) // Error in RX FIFO. U0LSR[7] is set when a character with a RX 0 error such as framing error, parity error or break interrupt, is loaded into the U0RBR. This bit is cleared when the U0LSR register is read and there are no subsequent errors in the UART FIFO. + +/* U0MSR - address 0x4000 8018 */ +#define U0MSR_DCTS (1 << 0) // Delta CTS. Set upon state change of input CTS. Cleared on a U0MSR read. 0 No change detected on modem input CTS. 1 State change detected on modem input CTS. +#define U0MSR_DDSR (1 << 1) // Delta DSR. Set upon state change of input DSR. Cleared on a U0MSR read. 0 No change detected on modem input DSR. 1 State change detected on modem input DSR. +#define U0MSR_TERI (1 << 2) // Trailing Edge RI. Set upon low to high transition of input RI. Cleared 0 on a U0MSR read. 0 No change detected on modem input, RI. 1 Low-to-high transition detected on RI. +#define U0MSR_DDCD (1 << 3) // Delta DCD. Set upon state change of input DCD. Cleared on a U0MSR read. 0 No change detected on modem input DCD. 1 State change detected on modem input DCD. +#define U0MSR_CTS (1 << 4) // Clear To Send State. Complement of input signal CTS. This bit is connected to U0MCR[1] in modem loopback mode. +#define U0MSR_DSR (1 << 5) // Data Set Ready State. Complement of input signal DSR. This bit is connected to U0MCR[0] in modem loopback mode. +#define U0MSR_RI (1 << 6) // Ring Indicator State. Complement of input RI. This bit is connected to U0MCR[2] in modem loopback mode. +#define U0MSR_DCD (1 << 7) // Data Carrier Detect State. Complement of input DCD. This bit is connected to U0MCR[3] in modem loopback mode. + +/* U0SCR - address 0x4000 801C */ +#define U0SCR_PAD_MASK 0x00FF // A readable, writable byte. +#define U0SCR_PAD_SHIFT 0 + +/* U0ACR - address 0x4000 8020 */ +#define U0ACR_START (1 << 0) // Start bit. This bit is automatically cleared after auto-baud completion. +#define U0ACR_MODE (1 << 1) // Auto-baud mode select +#define U0ACR_AUTORESTART (1 << 2) // Restart enable +#define U0ACR_ABEOINTCLR (1 << 8) // End of auto-baud interrupt clear (write only accessible) +#define U0ACR_ABTOINTCLR (1 << 9) // Auto-baud time-out interrupt clear (write only accessible) + +/* U0TER - address 0x4000 8030 */ +#define U0TER_TXEN (1 << 7) // When this bit is 1, as it is after a Reset, data written to the THR 1 is output on the TXD pin as soon as any preceding data has been sent. If this bit cleared to 0 while a character is being sent, the transmission of that character is completed, but no further characters are sent until this bit is set again. In other words, a 0 in this bit blocks the transfer of characters from the THR or TX FIFO into the transmit shift register. Software can clear this bit when it detects that the a hardware-handshaking TX-permit signal (CTS) has gone false, or with software handshaking, when it receives an XOFF character (DC3). Software can set this bit again when it detects that the TX-permit signal has gone true, or when it receives an XON (DC1) character. Reserved + +/* U0RS485CTRL - address 0x4000 804C */ +#define U0RS485CTRL_NMMEN (1 << 0) // NMM enable. +#define U0RS485CTRL_RXDIS (1 << 1) // Receiver enable. +#define U0RS485CTRL_AADEN (1 << 2) // AAD enable. +#define U0RS485CTRL_SEL (1 << 3) // Select direction control pin +#define U0RS485CTRL_DCTRL (1 << 4) // Auto direction control enable. +#define U0RS485CTRL_OINV (1 << 5) // Polarity control. This bit reverses the polarity of the direction control signal on the RTS (or DTR) pin. + +/* U0RS485ADRMATCH - address 0x4000 8050 */ +#define U0RS485ADRMATCH_ADRMATCH_MASK 0x00FF // Contains the address match value. 0 +#define U0RS485ADRMATCH_ADRMATCH_SHIFT 0 + +/* U0RS485DLY - address 0x4000 8054 */ +#define U0RS485DLY_DLY_MASK 0x00FF // Contains the direction control (RTS or DTR) delay value. This register works in conjunction with an 8-bit counter. +#define U0RS485DLY_DLY_SHIFT 0 + +/* SSP0CR0 - address 0x4004 0000, SSP1CR0 - address 0x4005 8000 */ +#define SSP0CR0_DSS_MASK 0x000F // Data Size Select. This field controls the number of bits transferred in each frame. Values 0000-0010 are not supported and should not be used. +#define SSP0CR0_DSS_SHIFT 0 +#define SSP0CR0_FRF_MASK 0x0030 // Frame Format. +#define SSP0CR0_FRF_SHIFT 4 +#define SSP0CR0_CPOL (1 << 6) // Clock Out Polarity. This bit is only used in SPI mode. +#define SSP0CR0_CPHA (1 << 7) // Clock Out Phase. This bit is only used in SPI mode. +#define SSP0CR0_SCR_MASK 0xFF00 // Serial Clock Rate. The number of prescaler output clocks per 0x00 bit on the bus, minus one. Given that CPSDVSR is the prescale divider, and the APB clock PCLK clocks the prescaler, the bit frequency is PCLK / (CPSDVSR [SCR+1]). Reserved +#define SSP0CR0_SCR_SHIFT 8 + +/* SSP0CR1 - address 0x4004 0004, SSP1CR1 - address 0x4005 8004 */ +#define SSP0CR1_LBM (1 << 0) // Loop Back Mode. +#define SSP0CR1_SSE (1 << 1) // SPI Enable. +#define SSP0CR1_MS (1 << 2) // Master/Slave Mode.This bit can only be written when the SSE bit is 0. +#define SSP0CR1_SOD (1 << 3) // Slave Output Disable. This bit is relevant only in slave 0 mode (MS = 1). If it is 1, this blocks this SPI controller from driving the transmit data line (MISO). + +/* SSP0DR - address 0x4004 0008, SSP1DR - address 0x4005 8008 */ +#define SSP0DR_DATA_MASK 0xFFFF // Write: software can write data to be sent in a future frame to this 0x0000 register whenever the TNF bit in the Status register is 1, indicating that the Tx FIFO is not full. If the Tx FIFO was previously empty and the SPI controller is not busy on the bus, transmission of the data will begin immediately. Otherwise the data written to this register will be sent as soon as all previous data has been sent (and received). If the data length is less than 16 bit, software must right-justify the data written to this register. Read: software can read data from this register whenever the RNE bit in the Status register is 1, indicating that the Rx FIFO is not empty. When software reads this register, the SPI controller returns data from the least recent frame in the Rx FIFO. If the data length is less than 16 bit, the data is right-justified in this field with higher order bits filled with 0s. Reserved. +#define SSP0DR_DATA_SHIFT 0 + +/* SSP0SR - address 0x4004 000C, SSP1SR - address 0x4005 800C */ +#define SSP0SR_TFE (1 << 0) // Transmit FIFO Empty. This bit is 1 is the Transmit FIFO is empty, 0 if not. +#define SSP0SR_TNF (1 << 1) // Transmit FIFO Not Full. This bit is 0 if the Tx FIFO is full, 1 if not. 1 +#define SSP0SR_RNE (1 << 2) // Receive FIFO Not Empty. This bit is 0 if the Receive FIFO is empty, 1 if not. +#define SSP0SR_RFF (1 << 3) // Receive FIFO Full. This bit is 1 if the Receive FIFO is full, 0 if not. +#define SSP0SR_BSY (1 << 4) // Busy. This bit is 0 if the SPI controller is idle, 1 if it is currently sending/receiving a frame and/or the Tx FIFO is not empty. + +/* SSP0CPSR - address 0x4004 0010, SSP1CPSR - address 0x4005 8010 */ +#define SSP0CPSR_CPSDVSR_MASK 0x00FF // This even value between 2 and 254, by which SPI_PCLK is divided to yield the prescaler output clock. Bit 0 always reads as 0. +#define SSP0CPSR_CPSDVSR_SHIFT 0 + +/* SSP0IMSC - address 0x4004 0014, SSP1IMSC - address 0x4005 8014 */ +#define SSP0IMSC_RORIM (1 << 0) // Software should set this bit to enable interrupt when a Receive 0 Overrun occurs, that is, when the Rx FIFO is full and another frame is completely received. The ARM spec implies that the preceding frame data is overwritten by the new frame data when this occurs. +#define SSP0IMSC_RTIM (1 << 1) // Software should set this bit to enable interrupt when a Receive Time-out condition occurs. A Receive Time-out occurs when the Rx FIFO is not empty, and no has not been read for a time-out period. The time-out period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). +#define SSP0IMSC_RXIM (1 << 2) // Software should set this bit to enable interrupt when the Rx FIFO is at 0 least half full. +#define SSP0IMSC_TXIM (1 << 3) // Software should set this bit to enable interrupt when the Tx FIFO is at 0 least half empty. + +/* SSP0RIS - address 0x4004 0018, SSP1RIS - address 0x4005 8018 */ +#define SSP0RIS_RORRIS (1 << 0) // This bit is 1 if another frame was completely received while the 0 RxFIFO was full. The ARM spec implies that the preceding frame data is overwritten by the new frame data when this occurs. +#define SSP0RIS_RTRIS (1 << 1) // This bit is 1 if the Rx FIFO is not empty, and has not been read 0 for a time-out period. The time-out period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). +#define SSP0RIS_RXRIS (1 << 2) // This bit is 1 if the Rx FIFO is at least half full. +#define SSP0RIS_TXRIS (1 << 3) // This bit is 1 if the Tx FIFO is at least half empty. + +/* SSP0MIS - address 0x4004 001C, SSP1MIS - address 0x4005 801C */ +#define SSP0MIS_RORMIS (1 << 0) // This bit is 1 if another frame was completely received while the 0 RxFIFO was full, and this interrupt is enabled. +#define SSP0MIS_RTMIS (1 << 1) // This bit is 1 if the Rx FIFO is not empty, has not been read for a time-out period, and this interrupt is enabled. The time-out period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). +#define SSP0MIS_RXMIS (1 << 2) // This bit is 1 if the Rx FIFO is at least half full, and this interrupt 0 is enabled. +#define SSP0MIS_TXMIS (1 << 3) // This bit is 1 if the Tx FIFO is at least half empty, and this interrupt is enabled. + +/* SSP0ICR - address 0x4004 0020, SSP1ICR - address 0x4005 8020 */ +#define SSP0ICR_RORIC (1 << 0) // Writing a 1 to this bit clears the "frame was received when RxFIFO was full" interrupt. +#define SSP0ICR_RTIC (1 << 1) // Writing a 1 to this bit clears the Rx FIFO was not empty and has not been read for a timeout period interrupt. The timeout period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). + +/* I2C0CONSET - address 0x4000 0000 */ +#define I2C0CONSET_AA (1 << 2) // Assert acknowledge flag. +#define I2C0CONSET_SI (1 << 3) // I2C interrupt flag. +#define I2C0CONSET_STO (1 << 4) // STOP flag. +#define I2C0CONSET_STA (1 << 5) // START flag. +#define I2C0CONSET_I2EN (1 << 6) // I2C interface enable. Reserved. The value read from a reserved bit is not defined. + +/* I2C0STAT - 0x4000 0004 */ +#define I2C0STAT_STATUS_MASK 0x00F8 // These bits give the actual status information about the I2 C interface. Reserved. The value read from a reserved bit is not defined. +#define I2C0STAT_STATUS_SHIFT 3 + +/* I2C0DAT - 0x4000 0008 */ +#define I2C0DAT_DATA_MASK 0x00FF // This register holds data values that have been received or are to 0 be transmitted. Reserved. The value read from a reserved bit is not defined. +#define I2C0DAT_DATA_SHIFT 0 + +/* I2C0ADR0 - 0x4000 000C */ +#define I2C0ADR0_GC (1 << 0) // General Call enable bit. +#define I2C0ADR0_ADDRESS_MASK 0x00FE // The I2C device address for slave mode. Reserved. The value read from a reserved bit is not defined. +#define I2C0ADR0_ADDRESS_SHIFT 1 + +/* I2C0SCLH - address 0x4000 0010 */ +#define I2C0SCLH_SCLH_MASK 0xFFFF // Count for SCL HIGH time period selection. +#define I2C0SCLH_SCLH_SHIFT 0 + +/* I2C0SCLL - 0x4000 0014 */ +#define I2C0SCLL_SCLL_MASK 0xFFFF // Count for SCL low time period selection. +#define I2C0SCLL_SCLL_SHIFT 0 + +/* I2C0CONCLR - 0x4000 0018 */ +#define I2C0CONCLR_AAC (1 << 2) // Assert acknowledge Clear bit. +#define I2C0CONCLR_SIC (1 << 3) // I2C interrupt Clear bit. +#define I2C0CONCLR_STAC (1 << 5) // START flag Clear bit. +#define I2C0CONCLR_I2ENC (1 << 6) // I2C interface Disable bit. Reserved. The value read from a reserved bit is not defined. + +/* I2C0MMCTRL - 0x4000 001C */ +#define I2C0MMCTRL_MM_ENA (1 << 0) // Monitor mode enable. +#define I2C0MMCTRL_ENA_SCL (1 << 1) // SCL output enable. + +/* I2C0DATA_BUFFER - 0x4000 002C */ +#define I2C0DATA_BUFFER_DATA_MASK 0x00FF // This register holds contents of the 8 MSBs of the DAT shift register. Reserved. The value read from a reserved bit is not defined. +#define I2C0DATA_BUFFER_DATA_SHIFT 0 + +/* CANCNTL, address 0x4005 0000 */ +#define CANCNTL_INIT (1 << 0) // Initialization +#define CANCNTL_IE (1 << 1) // Module interrupt enable +#define CANCNTL_SIE (1 << 2) // Status change interrupt enable +#define CANCNTL_EIE (1 << 3) // Error interrupt enable +#define CANCNTL_DAR (1 << 5) // Disable automatic retransmission +#define CANCNTL_CCE (1 << 6) // Configuration change enable +#define CANCNTL_TEST (1 << 7) // Test mode enable + +/* CANSTAT, address 0x4005 0004 */ +#define CANSTAT_LEC_MASK 0x0007 // Last error code Type of the last error to occur on the CAN bus.The LEC field holds a code which indicates the type of the last error to occur on the CAN bus. This field will be cleared to `0' when a message has been transferred (reception or transmission) without error. The unused code `111' may be written by the CPU to check for updates. +#define CANSTAT_LEC_SHIFT 0 +#define CANSTAT_TXOK (1 << 3) // Transmitted a message successfully This bit must be reset by the CPU. It is never reset by the CAN controller. +#define CANSTAT_RXOK (1 << 4) // Received a message successfully This bit must be reset by the CPU. It is never reset by the CAN controller. +#define CANSTAT_EPASS (1 << 5) // Error passive +#define CANSTAT_EWARN (1 << 6) // Warning status +#define CANSTAT_BOFF (1 << 7) // Busoff status + +/* CANEC, address 0x4005 0008 */ +#define CANEC_TEC_MASK 0x00FF // Transmit error counter Current value of the transmit error counter (maximum value 255) +#define CANEC_TEC_SHIFT 0 +#define CANEC_REC_MASK 0x7F00 // Receive error counter Current value of the receive error counter (maximum value 127). +#define CANEC_REC_SHIFT 8 +#define CANEC_RP (1 << 15) // Receive error passive + +/* CANBT, address 0x4005 000C */ +#define CANBT_BRP_MASK 0x003F // Baud rate prescaler The value by which the oscillator frequency is divided for generating the bit time quanta. The bit time is built up from a multiple of this quanta. Valid values for the Baud Rate Prescaler are 0 to 63.[1] +#define CANBT_BRP_SHIFT 0 +#define CANBT_SJW_MASK 0x00C0 // (Re)synchronization jump width Valid programmed values are 0 to 3.[1] +#define CANBT_SJW_SHIFT 6 +#define CANBT_TSEG1_MASK 0x0F00 // Time segment before the sample point Valid values are 1 to 15.[1] +#define CANBT_TSEG1_SHIFT 8 +#define CANBT_TSEG2_MASK 0x7000 // Time segment after the sample point Valid values are 0 to 7.[1] +#define CANBT_TSEG2_SHIFT 12 + +/* CANINT, address 0x4005 0010 */ +#define CANINT_INTID_MASK 0xFFFF // 0x0000 = No interrupt is pending. 0 0x0001 - 0x0020 = Number of message object which caused the interrupt. 0x0021 - 0x7FFF = Unused 0x8000 = Status interrupt 0x8001 - 0xFFFF = Unused +#define CANINT_INTID_SHIFT 0 + +/* CANTEST, address 0x4005 0014 */ +#define CANTEST_BASIC (1 << 2) // Basic mode +#define CANTEST_SILENT (1 << 3) // Silent mode +#define CANTEST_LBACK (1 << 4) // Loop back mode +#define CANTEST_TX_MASK 0x0060 // Control of CAN_TXD pins +#define CANTEST_TX_SHIFT 5 +#define CANTEST_RX (1 << 7) // Monitors the actual value of the CAN_RXD pin. + +/* CANBRPE, address 0x4005 0018 */ +#define CANBRPE_BRPE_MASK 0x000F // Baud rate prescaler extension By programming BRPE the Baud Rate Prescaler can be extended to values up to 1023. Hardware interprets the value as the value of BRPE (MSBs) and BRP (LSBs) plus one. Allowed values are 0 to 15. +#define CANBRPE_BRPE_SHIFT 0 + +/* CANIF1_CMDREQ, address 0x4005 0020 and CANIF2_CMDREQ, address 0x4005 0080 */ +#define CANIFn_CMDREQ_MN_MASK 0x003F // Message number 0x01 - 0x20 = Valid message numbers. The message object in the message RAM is selected for data transfer. 0x00 = Not a valid message number. This value is interpreted as 0x20.[1] 0x21 - 0x3F = Not a valid message number. This value is interpreted as 0x01 - 0x1F.[1] +#define CANIFn_CMDREQ_MN_SHIFT 0 +#define CANIFn_CMDREQ_BUSY (1 << 15) // BUSY flag + +/* CANIF1_CMDMSK, address 0x4005 0024 and CANIF2_CMDMSK, address 0x4005 0084 */ +#define CANIFn_CMDMSK_DATA_B (1 << 0) // Access data bytes 4-7 +#define CANIFn_CMDMSK_DATA_A (1 << 1) // Access data bytes 0-3 +#define CANIFn_CMDMSK_TXRQST (1 << 2) // Access transmission request bit (Write direction) +#define CANIFn_CMDMSK_NEWDAT (1 << 2) // Access new data bit (Read direction) +#define CANIFn_CMDMSK_CLRINTPND (1 << 3) // This bit is ignored in the write direction. +#define CANIFn_CMDMSK_CTRL (1 << 4) // Access control bits +#define CANIFn_CMDMSK_ARB (1 << 5) // Access arbitration bits +#define CANIFn_CMDMSK_MASK (1 << 6) // Access mask bits +#define CANIFn_CMDMSK_WR (1 << 7) // Write transfer Transfer data from the selected message buffer registers to the message object addressed by the command request register CANIFn_CMDREQ. +#define CANIFn_CMDMSK_RD (0 << 7) // Read transfer Read data from the selected message buffer registers to the message object addressed by the command request register CANIFn_CMDREQ. + +/* CANIF1_MSK1, address 0x4005 0028 and CANIF2_MASK1, address 0x4005 0088 */ +#define CANIFn_MSK1_MSK_MASK 0xFFFF // Identifier mask +#define CANIFn_MSK1_MSK_SHIFT 0 + +/* CANIF1_MSK2, address 0x4005 002C and CANIF2_MASK2, address 0x4005 008C */ +#define CANIFn_MSK2_MSK_MASK 0x1FFF // Identifier mask +#define CANIFn_MSK2_MSK_SHIFT 0 +#define CANIFn_MSK2_MDIR (1 << 14) // Mask message direction +#define CANIFn_MSK2_MXTD (1 << 15) // Mask extend identifier + +/* CANIF1_ARB1, address 0x4005 0030 and CANIF2_ARB1, address 0x4005 0090 */ +#define CANIFn_ARB1_ID_MASK 0xFFFF // Message identifier 29-bit identifier (extended frame) 11-bit identifier (standard frame) +#define CANIFn_ARB1_ID_SHIFT 0 + +/* CANIF1_ARB2, address 0x4005 0034 and CANIF2_ARB2, address 0x4005 0094 */ +#define CANIFn_ARB2_ID_MASK 0x1FFF // Message identifier 29-bit identifier (extended frame) 11-bit identifier (standard frame) +#define CANIFn_ARB2_ID_SHIFT 0 +#define CANIFn_ARB2_DIR (1 << 13) // Message direction +#define CANIFn_ARB2_XTD (1 << 14) // Extend identifier +#define CANIFn_ARB2_MSGVAL (1 << 15) // Message valid Remark: The CPU must reset the MSGVAL bit of all unused Messages Objects during the initialization before it resets bit INIT in the CAN Control Register. This bit must also be reset before the identifier ID28:0, the control bits XTD, DIR, or the Data Length Code DLC3:0 are modified, or if the Messages Object is no longer required. + +/* CANIF1_MCTRL, address 0x4005 0038 and CANIF2_MCTRL, address 0x4005 0098 */ +#define CANIFn_MCTRL_DLC_MASK 0x000F // Data length code Remark: The Data Length Code of a Message Object must be defined the same as in all the corresponding objects with the same identifier at other nodes. When the Message Handler stores a data frame, it will write the DLC to the value given by the received message. 0000 - 1000 = Data frame has 0 - 8 data bytes. 1001 - 1111 = Data frame has 8 data bytes. +#define CANIFn_MCTRL_DLC_SHIFT 0 +#define CANIFn_MCTRL_EOB (1 << 7) // End of buffer +#define CANIFn_MCTRL_TXRQST (1 << 8) // Transmit request +#define CANIFn_MCTRL_RMTEN (1 << 9) // Remote enable +#define CANIFn_MCTRL_RXIE (1 << 10) // Receive interrupt enable +#define CANIFn_MCTRL_TXIE (1 << 11) // Transmit interrupt enable +#define CANIFn_MCTRL_UMASK (1 << 12) // Use acceptance mask Remark: If UMASK is set to 1, the message object's mask bits have to be programmed during initialization of the message object before MAGVAL is set to 1. +#define CANIFn_MCTRL_INTPND (1 << 13) // Interrupt pending +#define CANIFn_MCTRL_MSGLST (1 << 14) // Message lost (only valid for message objects in the direction receive). +#define CANIFn_MCTRL_NEWDAT (1 << 15) // New data + +/* CANIF1_DA1, address 0x4005 003C and CANIF2_DA1, address 0x4005 009C */ +#define CANIFn_DA1_DATA0_MASK 0x00FF // Data byte 0 +#define CANIFn_DA1_DATA0_SHIFT 0 +#define CANIFn_DA1_DATA1_MASK 0xFF00 // Data byte 1 +#define CANIFn_DA1_DATA1_SHIFT 8 + +/* CANIF1_DA2, address 0x4005 0040 and CANIF2_DA2, address 0x4005 00A0 */ +#define CANIFn_DA2_DATA2_MASK 0x00FF // Data byte 2 +#define CANIFn_DA2_DATA2_SHIFT 0 +#define CANIFn_DA2_DATA3_MASK 0xFF00 // Data byte 3 +#define CANIFn_DA2_DATA3_SHIFT 8 + +/* CANIF1_DB1, address 0x4005 0044 and CANIF2_DB1, address 0x4005 00A4 */ +#define CANIFn_DB1_DATA4_MASK 0x00FF // Data byte 4 +#define CANIFn_DB1_DATA4_SHIFT 0 +#define CANIFn_DB1_DATA5_MASK 0xFF00 // Data byte 5 +#define CANIFn_DB1_DATA5_SHIFT 8 + +/* CANIF1_DB2, address 0x4005 0048 and CANIF2_DB2, address 0x4005 00A8 */ +#define CANIFn_DB2_DATA6_MASK 0x00FF // Data byte 6 +#define CANIFn_DB2_DATA6_SHIFT 0 +#define CANIFn_DB2_DATA7_MASK 0xFF00 // Data byte 7 +#define CANIFn_DB2_DATA7_SHIFT 8 + +/* CANTXREQ1, address 0x4005 0100 */ +#define CANTXREQ1_TXRQST_MASK 0xFFFF // Transmission request bit of message objects 16 to 1. 0 = This message object is not waiting for transmission. 1 = The transmission of this message object is requested and not yet done. Reserved +#define CANTXREQ1_TXRQST_SHIFT 0 + +/* CANTXREQ2, address 0x4005 0104 */ +#define CANTXREQ2_TXRQST_MASK 0xFFFF // Transmission request bit of message objects 32 to 17. 0 = This message object is not waiting for transmission. 1 = The transmission of this message object is requested and not yet done. Reserved +#define CANTXREQ2_TXRQST_SHIFT 0 + +/* CANND1, address 0x4005 0120 */ +#define CANND1_NEWDAT_MASK 0xFFFF // New data bits of message objects 16 to 1. 0 = No new data has been written into the data portion of this Message Object by the Message Handler since last time this flag was cleared by the CPU. 1 = The Message Handler or the CPU has written new data into the data portion of this Message Object. +#define CANND1_NEWDAT_SHIFT 0 + +/* CANND2, address 0x4005 0124 */ +#define CANND2_NEWDAT_MASK 0xFFFF // New data bits of message objects 32 to 17. 0 = No new data has been written into the data portion of this Message Object by the Message Handler since last time this flag was cleared by the CPU. 1 = The Message Handler or the CPU has written new data into the data portion of this Message Object. +#define CANND2_NEWDAT_SHIFT 0 + +/* CANIR1, address 0x4005 0140 */ +#define CANIR1_INTPND_INTERRUPT_MASK 0xFFFF // pending bits of message objects 16 to 1. essage object is ignored by the message essage object is the source of an interrupt. Reserved +#define CANIR1_INTPND_INTERRUPT_SHIFT 0 + +/* CANIR2, addresses 0x4005 0144 */ +#define CANIR2_INTPND_MASK 0xFFFF // Interrupt pending bits of message objects 32 to 17. 0 = This message object is ignored by the message handler. 1 = This message object is the source of an interrupt. Reserved +#define CANIR2_INTPND_SHIFT 0 + +/* CANMSGV1, addresses 0x4005 0160 */ +#define CANMSGV1_MSGVAL_MASK 0xFFFF // Message valid bits of message objects 16 to 1. 0 = This message object is ignored by the message handler. 1 = This message object is configured and should be considered by the message handler. Reserved +#define CANMSGV1_MSGVAL_SHIFT 0 + +/* CANMSGV2, address 0x4005 0164 */ +#define CANMSGV2_MSGVAL_MASK 0xFFFF // Message valid bits of message objects 32 to 17. 0 = This message object is ignored by the message handler. 1 = This message object is configured and should be considered by the message handler. Reserved +#define CANMSGV2_MSGVAL_SHIFT 0 + +/* CANCLKDIV, address 0x4005 0180 */ +#define CANCLKDIV_CLKDIVVAL_MASK 0x000F // Clock divider value. CAN_CLK = PCLK/(CLKDIVVAL +1) 0000: CAN_CLK = PCLK divided by 1. 0001: CAN_CLK = PCLK divided by 2. 0010: CAN_CLK = PCLK divided by 3 0011: CAN_CLK = PCLK divided by 4. ... 1111: CAN_CLK = PCLK divided by 16. +#define CANCLKDIV_CLKDIVVAL_SHIFT 0 + +/* TMR16B0IR - address 0x4000 C000 and TMR16B1IR - address 0x4001 0000 */ +#define TMR16B0IR_MR0 (1 << 0) // Interrupt flag for match channel 0. +#define TMR16B0IR_MR1 (1 << 1) // Interrupt flag for match channel 1. +#define TMR16B0IR_MR2 (1 << 2) // Interrupt flag for match channel 2. +#define TMR16B0IR_MR3 (1 << 3) // Interrupt flag for match channel 3. +#define TMR16B0IR_CR0 (1 << 4) // Interrupt flag for capture channel 0 event. + +/* TMR16B0TCR - address 0x4000 C004 and TMR16B1TCR - address 0x4001 0004 */ +#define TMR16B0TCR_CEN (1 << 0) // Counter Enable. When one, the Timer Counter and Prescale Counter are enabled for counting. When zero, the counters are disabled. +#define TMR16B0TCR_CRST (1 << 1) // Counter Reset. When one, the Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR16B0TC, address 0x4000 C008 and TMR16B1TC 0x4001 0008 */ +#define TMR16B0TC_TC_MASK 0xFFFF // Timer counter value. +#define TMR16B0TC_TC_SHIFT 0 + +/* TMR16B0PR, address 0x4000 C00C and TMR16B1PR 0x4001 000C */ +#define TMR16B0PR_PR_MASK 0xFFFF // Prescale max value. +#define TMR16B0PR_PR_SHIFT 0 + +/* TMR16B0PC, address 0x4001 C010 and TMR16B1PC 0x4000 0010 */ +#define TMR16B0PC_PC_MASK 0xFFFF // Prescale counter value. +#define TMR16B0PC_PC_SHIFT 0 + +/* TMR16B0MCR - address 0x4000 C014 and TMR16B1MCR - address 0x4001 0014 */ +#define TMR16B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR16B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR16B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR16B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR16B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR16B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR16B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR16B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR16B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR16B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR16B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR16B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR16B0MR0 to 3, addresses 0x4000 C018 to 24 and TMR16B1MR0 to 3, addresses 0x4001 0018 to 24 */ +#define TMR16B0MR0_to_3_MATCH_MASK 0xFFFF // Timer counter match value. +#define TMR16B0MR0_to_3_MATCH_SHIFT 0 + +/* TMR16B0CCR - address 0x4000 C028 and TMR16B1CCR - address 0x4001 0028 */ +#define TMR16B0CCR_CAP0RE (1 << 0) // Capture on CT16Bn_CAP0 rising edge: a sequence of 0 then 1 on CT16Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0FE (1 << 1) // Capture on CT16Bn_CAP0 falling edge: a sequence of 1 then 0 on CT16Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0I (1 << 2) // Interrupt on CT16Bn_CAP0 event: a CR0 load due to a CT16Bn_CAP0 event will generate an interrupt. + +/* TMR16B0CR0, address 0x4000 C02C and TMR16B1CR0, address 0x4001 002C */ +#define TMR16B0CR0_CAP_MASK 0xFFFF // Timer counter capture value. +#define TMR16B0CR0_CAP_SHIFT 0 + +/* TMR16B0EMR - address 0x4000 C03C and TMR16B1EMR - address 0x4001 003C */ +#define TMR16B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT16B0_MAT0/CT16B1_MAT0, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT16B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT16B0_MAT1/CT16B1_MAT1, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT16B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output match channel 2, whether or not 0 this output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. Note that on counter/timer 0 this match channel is not pinned out. This bit is driven to the CT16B1_MAT2 pin if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output of match channel 3. When a match 0 occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. There is no output pin available for this channel on either of the 16-bit timers. +#define TMR16B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR16B0EMR_EMC0_SHIFT 4 +#define TMR16B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR16B0EMR_EMC1_SHIFT 6 +#define TMR16B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR16B0EMR_EMC2_SHIFT 8 +#define TMR16B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR16B0EMR_EMC3_SHIFT 10 + +/* TMR16B0CTCR - address 0x4000 C070 and TMR16B1CTCR - address 0x4001 0070 */ +#define TMR16B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK 00 edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). +#define TMR16B0CTCR_CTM_SHIFT 0 + +/* TMR16B0PWMC - address 0x4000 C074 and TMR16B1PWMC- address 0x4001 0074 */ +#define TMR16B0PWMC_PWMEN0 (1 << 0) // PWM channel0 enable +#define TMR16B0PWMC_PWMEN1 (1 << 1) // PWM channel1 enable +#define TMR16B0PWMC_PWMEN2 (1 << 2) // PWM channel2 enable +#define TMR16B0PWMC_PWMEN3 (1 << 3) // PWM channel3 enable Note: It is recommended to use match channel 3 to set the PWM cycle because it is not pinned out. + +/* TMR16B0IR - address 0x4000 C000 and TMR16B1IR - address 0x4001 0000 */ +#define TMR16B0IR_MR0INT (1 << 0) // Interrupt flag for match channel 0. +#define TMR16B0IR_MR1INT (1 << 1) // Interrupt flag for match channel 1. +#define TMR16B0IR_MR2INT (1 << 2) // Interrupt flag for match channel 2. +#define TMR16B0IR_MR3INT (1 << 3) // Interrupt flag for match channel 3. +#define TMR16B0IR_CR0INT (1 << 4) // Interrupt flag for capture channel 0 event. +#define TMR16B0IR_CR1INT (1 << 5) // Interrupt flag for capture channel 1 event. + +/* TMR16B0TCR - address 0x4000 C004 and TMR16B1TCR - address 0x4001 0004 */ +#define TMR16B0TCR_CEN (1 << 0) // Counter Enable. When one, the Timer Counter and Prescale Counter are enabled for counting. When zero, the counters are disabled. +#define TMR16B0TCR_CRST (1 << 1) // Counter Reset. When one, the Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR16B0TC, address 0x4000 C008 and TMR16B1TC 0x4001 0008 */ +#define TMR16B0TC_TC_MASK 0xFFFF // Timer counter value. +#define TMR16B0TC_TC_SHIFT 0 + +/* TMR16B0PR, address 0x4000 C00C and TMR16B1PR 0x4001 000C */ +#define TMR16B0PR_PR_MASK 0xFFFF // Prescale max value. +#define TMR16B0PR_PR_SHIFT 0 + +/* TMR16B0PC, address 0x4001 C010 and TMR16B1PC 0x4000 0010 */ +#define TMR16B0PC_PC_MASK 0xFFFF // Prescale counter value. +#define TMR16B0PC_PC_SHIFT 0 + +/* TMR16B0MCR - address 0x4000 C014 and TMR16B1MCR - address 0x4001 0014 */ +#define TMR16B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR16B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR16B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR16B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR16B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR16B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR16B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR16B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR16B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR16B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR16B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR16B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR16B0MR0 to 3, addresses 0x4000 C018 to 24 and TMR16B1MR0 to 3, addresses 0x4001 0018 to 24 */ +#define TMR16B0MR0_to_3_MATCH_MASK 0xFFFF // Timer counter match value. +#define TMR16B0MR0_to_3_MATCH_SHIFT 0 + +/* TMR16B0CCR - address 0x4000 C028 and TMR16B1CCR - address 0x4001 0028 */ +#define TMR16B0CCR_CAP0RE (1 << 0) // Capture on CT16Bn_CAP0 rising edge: a sequence of 0 then 1 on CT16Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0FE (1 << 1) // Capture on CT16Bn_CAP0 falling edge: a sequence of 1 then 0 on CT16Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0I (1 << 2) // Interrupt on CT16Bn_CAP0 event: a CR0 load due to a CT16Bn_CAP0 event will generate an interrupt. +#define TMR16B0CCR_CAP1RE (1 << 3) // Capture on CT16Bn_CAP1 rising edge: a sequence of 0 then 1 on CT16Bn_CAP1 will cause CR1 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP1FE (1 << 4) // Capture on CT16Bn_CAP1 falling edge: a sequence of 1 then 0 on CT16Bn_CAP1 will 0 cause CR1 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP1I (1 << 5) // Interrupt on CT16Bn_CAP1 event: a CR1 load due to a CT16Bn_CAP1 event will generate an interrupt. + +/* TMR16B0EMR - address 0x4000 C03C and TMR16B1EMR - address 0x4001 003C */ +#define TMR16B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT16B0_MAT0/CT16B1_MAT0, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT16B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT16B0_MAT1/CT16B1_MAT1, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT16B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output match channel 2, whether or not 0 this output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. Note that on counter/timer 0 this match channel is not pinned out. This bit is driven to the CT16B1_MAT2 pin if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output of match channel 3. When a match 0 occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. There is no output pin available for this channel on either of the 16-bit timers. +#define TMR16B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR16B0EMR_EMC0_SHIFT 4 +#define TMR16B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR16B0EMR_EMC1_SHIFT 6 +#define TMR16B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR16B0EMR_EMC2_SHIFT 8 +#define TMR16B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR16B0EMR_EMC3_SHIFT 10 + +/* TMR16B0CTCR - address 0x4000 C070 and TMR16B1CTCR - address 0x4001 0070 */ +#define TMR16B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK 00 edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). +#define TMR16B0CTCR_CTM_SHIFT 0 +#define TMR16B0CTCR_SELCC_MASK 0x00E0 // When bit 4 is one, these bits select which capture input edge 0 will cause the timer and prescaler to be cleared. These bits have no effect when bit 4 is zero. +#define TMR16B0CTCR_SELCC_SHIFT 5 + +/* TMR16B0PWMC - address 0x4000 C074 and TMR16B1PWMC- address 0x4001 0074 */ +#define TMR16B0PWMC_PWMEN0 (1 << 0) // PWM channel0 enable +#define TMR16B0PWMC_PWMEN1 (1 << 1) // PWM channel1 enable +#define TMR16B0PWMC_PWMEN2 (1 << 2) // PWM channel2 enable +#define TMR16B0PWMC_PWMEN3 (1 << 3) // PWM channel3 enable Note: It is recommended to use match channel 3 to set the PWM cycle because it is not pinned out. + +/* TMR32B0IR - address 0x4001 4000 and TMR32B1IR - address 0x4001 8000 */ +#define TMR32B0IR_MR0_INTERRUPT (1 << 0) // Interrupt flag for match channel 0. +#define TMR32B0IR_MR1_INTERRUPT (1 << 1) // Interrupt flag for match channel 1. +#define TMR32B0IR_MR2_INTERRUPT (1 << 2) // Interrupt flag for match channel 2. +#define TMR32B0IR_MR3_INTERRUPT (1 << 3) // Interrupt flag for match channel 3. +#define TMR32B0IR_CR0_INTERRUPT (1 << 4) // Interrupt flag for capture channel 0 event. + +/* TMR32B0TCR - address 0x4001 4004 and TMR32B1TCR - address 0x4001 8004 */ +#define TMR32B0TCR_CEN (1 << 0) // When one, the Timer Counter and Prescale Counter are 0 enabled for counting. When zero, the counters are disabled. +#define TMR32B0TCR_CRST (1 << 1) // When one, the Timer Counter and the Prescale Counter 0 are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR32B0TC, address 0x4001 4008 and TMR32B1TC 0x4001 8008 */ +#define TMR32B0TC_TC_MASK 0xFFFFFFFF // Timer counter value. +#define TMR32B0TC_TC_SHIFT 0 + +/* TMR32B0PR, address 0x4001 400C and TMR32B1PR 0x4001 800C */ +#define TMR32B0PR_PR_MASK 0xFFFFFFFF // Prescale value. +#define TMR32B0PR_PR_SHIFT 0 + +/* TMR32B0PC, address 0x4001 4010 and TMR32B1PC 0x4001 8010 */ +#define TMR32B0PC_PC_MASK 0xFFFFFFFF // Prescale counter value. +#define TMR32B0PC_PC_SHIFT 0 + +/* TMR32B0MCR - address 0x4001 4014 and TMR32B1MCR - address 0x4001 8014 */ +#define TMR32B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR32B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR32B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR32B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR32B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR32B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR32B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR32B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR32B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR32B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR32B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR32B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR32B0MR0 to 3, addresses 0x4001 4018 to 24 and TMR32B1MR0 to 3, addresses 0x4001 8018 to 24 */ +#define TMR32B0MRn_MATCH_MASK 0xFFFFFFFF // Timer counter match value. +#define TMR32B0MRn_MATCH_SHIFT 0 + +/* TMR32B0CCR - address 0x4001 4028 and TMR32B1CCR - address 0x4001 8028 */ +#define TMR32B0CCR_CAP0RE (1 << 0) // Capture on CT32Bn_CAP0 rising edge: a sequence of 0 then 1 on CT32Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0FE (1 << 1) // Capture on CT32Bn_CAP0 falling edge: a sequence of 1 then 0 on CT32Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0I (1 << 2) // Interrupt on CT32Bn_CAP0 event: a CR0 load due to a CT32Bn_CAP0 event will generate an interrupt. + +/* TMR32B0CR0, addresses 0x4001 402C and TMR32B1CR0, addresses 0x4001 802C */ +#define TMR32B0CR0_CAP_MASK 0xFFFFFFFF // Timer counter capture value. +#define TMR32B0CR0_CAP_SHIFT 0 + +/* TMR32B0EMR - address 0x4001 403C and TMR32B1EMR - address0x4001 803C */ +#define TMR32B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT32Bn_MAT0, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT32B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT32Bn_MAT1, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT32B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output CT32Bn_MAT2, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. This bit is driven to the CT32B0_MAT2/CT16B1_MAT2 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output CT32Bn_MAT3, whether or not this output is connected to its pin. When a match occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. This bit is driven to the CT32B0_MAT3/CT16B1_MAT3 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR32B0EMR_EMC0_SHIFT 4 +#define TMR32B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR32B0EMR_EMC1_SHIFT 6 +#define TMR32B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR32B0EMR_EMC2_SHIFT 8 +#define TMR32B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR32B0EMR_EMC3_SHIFT 10 + +/* TMR32B0CTCR - address 0x4001 4070 and TMR32B1TCR - address 0x4001 8070 */ +#define TMR32B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). Timer Mode: every rising PCLK edge +#define TMR32B0CTCR_CTM_SHIFT 0 +#define TMR32B0CTCR_CIS_MASK 0x000C // Count Input Select. When bits 1:0 in this register are not 00, these bits select which CAP pin is sampled for clocking: +#define TMR32B0CTCR_CIS_SHIFT 2 + +/* TMR32B0PWMC - 0x4001 4074 and TMR32B1PWMC - 0x4001 8074 */ +#define TMR32B0PWMC_PWMEN0 (1 << 0) // PWM channel 0 enable +#define TMR32B0PWMC_PWMEN1 (1 << 1) // PWM channel 1 enable +#define TMR32B0PWMC_PWMEN2 (1 << 2) // PWM channel 2 enable +#define TMR32B0PWMC_PWMEN3 (1 << 3) // PWM channel 3 enable Note: It is recommended to use match channel 3 to set the PWM cycle. + +/* TMR32B0IR - address 0x4001 4000 and TMR32B1IR - address 0x4001 8000 */ +#define TMR32B0IR_MR0INT (1 << 0) // Interrupt flag for match channel 0. +#define TMR32B0IR_MR1INT (1 << 1) // Interrupt flag for match channel 1. +#define TMR32B0IR_MR2INT (1 << 2) // Interrupt flag for match channel 2. +#define TMR32B0IR_MR3INT (1 << 3) // Interrupt flag for match channel 3. +#define TMR32B0IR_CR0INT (1 << 4) // Interrupt flag for capture channel 0 event. +#define TMR32B0IR_CR1INT (1 << 5) // Interrupt flag for capture channel 1 event. + +/* TMR32B0TCR - address 0x4001 4004 and TMR32B1TCR - address 0x4001 8004 */ +#define TMR32B0TCR_CEN (1 << 0) // When one, the Timer Counter and Prescale Counter are 0 enabled for counting. When zero, the counters are disabled. +#define TMR32B0TCR_CRST (1 << 1) // When one, the Timer Counter and the Prescale Counter 0 are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR32B0TC, address 0x4001 4008 and TMR32B1TC 0x4001 8008 */ +#define TMR32B0TC_TC_MASK 0xFFFFFFFF // Timer counter value. +#define TMR32B0TC_TC_SHIFT 0 + +/* TMR32B0PR, address 0x4001 400C and TMR32B1PR 0x4001 800C */ +#define TMR32B0PR_PR_MASK 0xFFFFFFFF // Prescale value. +#define TMR32B0PR_PR_SHIFT 0 + +/* TMR32B0PC, address 0x4001 4010 and TMR32B1PC 0x4001 8010 */ +#define TMR32B0PC_PC_MASK 0xFFFFFFFF // Prescale counter value. +#define TMR32B0PC_PC_SHIFT 0 + +/* TMR32B0MCR - address 0x4001 4014 and TMR32B1MCR - address 0x4001 8014 */ +#define TMR32B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR32B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR32B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR32B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR32B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR32B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR32B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR32B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR32B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR32B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR32B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR32B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR32B0MR0 to 3, addresses 0x4001 4018 to 24 and TMR32B1MR0 to 3, addresses 0x4001 8018 to 24 */ +#define TMR32B0MRn_MATCH_MASK 0xFFFFFFFF // Timer counter match value. +#define TMR32B0MRn_MATCH_SHIFT 0 + +/* TMR32B0CCR - address 0x4001 4028 and TMR32B1CCR - address 0x4001 8028 */ +#define TMR32B0CCR_CAP0RE (1 << 0) // Capture on CT32Bn_CAP0 rising edge: a sequence of 0 then 1 on CT32Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0FE (1 << 1) // Capture on CT32Bn_CAP0 falling edge: a sequence of 1 then 0 on CT32Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0I (1 << 2) // Interrupt on CT32Bn_CAP0 event: a CR0 load due to a CT32Bn_CAP0 event will generate an interrupt. +#define TMR32B0CCR_CAP1RE (1 << 3) // Capture on CT32Bn_CAP1 rising edge: a sequence of 0 then 1 on CT32Bn_CAP1 will cause CR1 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP1FE (1 << 4) // Capture on CT32Bn_CAP1 falling edge: a sequence of 1 then 0 on CT32Bn_CAP1 will 0 cause CR1 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP1I (1 << 5) // Interrupt on CT32Bn_CAP1 event: a CR1 load due to a CT32Bn_CAP1 event will generate an interrupt. + +/* TMR32B0EMR - address 0x4001 403C and TMR32B1EMR - address0x4001 803C */ +#define TMR32B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT32Bn_MAT0, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT32B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT32Bn_MAT1, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT32B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output CT32Bn_MAT2, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. This bit is driven to the CT32B0_MAT2/CT16B1_MAT2 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output CT32Bn_MAT3, whether or not this output is connected to its pin. When a match occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. This bit is driven to the CT32B0_MAT3/CT16B1_MAT3 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR32B0EMR_EMC0_SHIFT 4 +#define TMR32B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR32B0EMR_EMC1_SHIFT 6 +#define TMR32B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR32B0EMR_EMC2_SHIFT 8 +#define TMR32B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR32B0EMR_EMC3_SHIFT 10 + +/* TMR32B0CTCR - address 0x4001 4070 and TMR32B1TCR - address 0x4001 8070 */ +#define TMR32B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). Timer Mode: every rising PCLK edge +#define TMR32B0CTCR_CTM_SHIFT 0 +#define TMR32B0CTCR_CIS_MASK 0x000C // Count Input Select. When bits 1:0 in this register are not 00, these bits select which CAP pin is sampled for clocking: +#define TMR32B0CTCR_CIS_SHIFT 2 +#define TMR32B0CTCR_ENCC (1 << 4) // Setting this bit to one enables clearing of the timer and the prescaler when the capture-edge event specified in bits 7:5 occurs. +#define TMR32B0CTCR_SELCC_MASK 0x00E0 // When bit 4 is one, these bits select which capture input edge 0 will cause the timer and prescaler to be cleared. These bits have no effect when bit 4 is zero. +#define TMR32B0CTCR_SELCC_SHIFT 5 + +/* TMR32B0PWMC - 0x4001 4074 and TMR32B1PWMC - 0x4001 8074 */ +#define TMR32B0PWMC_PWMEN0 (1 << 0) // PWM channel 0 enable +#define TMR32B0PWMC_PWMEN1 (1 << 1) // PWM channel 1 enable +#define TMR32B0PWMC_PWMEN2 (1 << 2) // PWM channel 2 enable +#define TMR32B0PWMC_PWMEN3 (1 << 3) // PWM channel 3 enable Note: It is recommended to use match channel 3 to set the PWM cycle. + +/* WDMOD - 0x4000 4000 */ +#define WDMOD_WDEN (1 << 0) // Watchdog enable bit. This bit is Set Only. Remark: Setting this bit to one also locks the watchdog clock source. Once the watchdog timer is enabled, the watchdog timer clock source cannot be changed. If the watchdog timer is needed in Deep-sleep mode, the watchdog clock source must be changed to the watchdog oscillator before setting this bit to one. +#define WDMOD_WDRESET (1 << 1) // Watchdog reset enable bit. This bit is Set Only. +#define WDMOD_WDTOF (1 << 2) // Watchdog time-out flag. Set when the watchdog timer times out, by a feed error, or by events associated with WDPROTECT, cleared by software. Causes a chip reset if WDRESET = 1. +#define WDMOD_WDINT (1 << 3) // Watchdog interrupt flag. Set when the timer reaches the value in WDWARNINT. Cleared by software. +#define WDMOD_WDPROTECT (1 << 4) // Watchdog update mode. This bit is Set Only. + +/* WDTC - 0x4000 4004 */ +#define WDTC_COUNT_MASK 0xFFFFFF // Watchdog time-out interval. +#define WDTC_COUNT_SHIFT 0 + +/* WDFEED - 0x4000 4008 */ +#define WDFEED_FEED_MASK 0x00FF // Feed value should be 0xAA followed by 0x55. +#define WDFEED_FEED_SHIFT 0 + +/* WDTV - 0x4000 400C */ +#define WDTV_COUNT_MASK 0xFFFFFF // Counter timer value. +#define WDTV_COUNT_SHIFT 0 + +/* WDWARNINT - 0x4000 4014 */ +#define WDWARNINT_WARNINT_MASK 0x03FF // Watchdog warning interrupt compare value. +#define WDWARNINT_WARNINT_SHIFT 0 + +/* WDWINDOW - 0x4000 4018 */ +#define WDWINDOW_WINDOW_MASK 0xFFFFFF // Watchdog window value. +#define WDWINDOW_WINDOW_SHIFT 0 + +/* WDMOD - address 0x4000 4000 */ +#define WDMOD_WDEN (1 << 0) // WDEN Watchdog enable bit (Set Only). When 1, the watchdog timer is running. Remark: Setting this bit to one also locks the watchdog clock source. Once the watchdog timer is enabled, the watchdog timer clock source cannot be changed. If the watchdog timer is needed in Deep-sleep mode, the watchdog clock source must be changed to the watchdog oscillator before setting this bit to one. The clock source lock feature is not available on all parts, see Section 23.1). +#define WDMOD_WDRESET_WDRESET (1 << 1) // Watchdog reset enable bit (Set Only). When 1, og time-out will cause a chip reset. +#define WDMOD_WDTOF (1 << 2) // WDTOF Watchdog time-out flag. Set when the watchdog +#define WDMOD_WDINT (1 << 3) // WDINT Watchdog interrupt flag (Read Only, not clearable by software). + +/* WDTC - address 0x4000 4004 */ +#define WDTC_COUNT_MASK 0xFFFFFF // Watchdog time-out interval. +#define WDTC_COUNT_SHIFT 0 + +/* WDFEED - address 0x4000 4008 */ +#define WDFEED_FEED_MASK 0x00FF // Feed value should be 0xAA followed by 0x55. +#define WDFEED_FEED_SHIFT 0 + +/* WDTV - address 0x4000 000C */ +#define WDTV_COUNT_MASK 0xFFFFFF // Counter timer value. +#define WDTV_COUNT_SHIFT 0 + +/* SYST_CSR - 0xE000 E010 */ +#define SYST_CSR_ENABLE (1 << 0) // System Tick counter enable. When 1, the counter is enabled. When 0, the counter is disabled. +#define SYST_CSR_TICKINT (1 << 1) // System Tick interrupt enable. When 1, the System Tick interrupt 0 is enabled. When 0, the System Tick interrupt is disabled. When enabled, the interrupt is generated when the System Tick counter counts down to 0. +#define SYST_CSR_CLKSOURCE (1 << 2) // System Tick clock source selection. When 1, the system clock (CPU) clock is selected. When 0, the system clock/2 is selected as the reference clock. +#define SYST_CSR_COUNTFLAG (1 << 16) // Returns 1 if the SysTick timer counted to 0 since the last read of this register. Reserved, user software should not write ones to reserved bits. The value read from a reserved bit is not defined. + +/* SYST_RVR - 0xE000 E014 */ +#define SYST_RVR_RELOAD_MASK 0xFFFFFF // This is the value that is loaded into the System Tick counter when it 0 counts down to 0. +#define SYST_RVR_RELOAD_SHIFT 0 + +/* SYST_CVR - 0xE000 E018 */ +#define SYST_CVR_CURRENT_MASK 0xFFFFFF // Reading this register returns the current value of the System Tick counter. Writing any value clears the System Tick counter and the COUNTFLAG bit in STCTRL. +#define SYST_CVR_CURRENT_SHIFT 0 + +/* SYST_CALIB - 0xE000 E01C */ +#define SYST_CALIB_TENMS_MASK 0xFFFFFF // See Table 461. +#define SYST_CALIB_TENMS_SHIFT 0 +#define SYST_CALIB_SKEW (1 << 30) // See Table 461. +#define SYST_CALIB_NOREF (1 << 31) // See Table 461. + +/* AD0CR - address 0x4001 C000 */ +#define AD0CR_SEL_MASK 0x00FF // Selects which of the AD7:0 pins is (are) to be sampled and converted. Bit 0 selects Pin 0x00 AD0, bit 1 selects pin AD1,..., and bit 7 selects pin AD7. In software-controlled mode (BURST = 0), only one channel can be selected, i.e. only one of these bits should be 1. In hardware scan mode (BURST = 1), any numbers of channels can be selected, i.e any or all bits can be set to 1. If all bits are set to 0, channel 0 is selected automatically (SEL = 0x01). +#define AD0CR_SEL_SHIFT 0 +#define AD0CR_CLKDIV_MASK 0xFF00 // The APB clock (PCLK) is divided by CLKDIV +1 to produce the clock for the ADC, which 0 should be less than or equal to 4.5 MHz. Typically, software should program the smallest value in this field that yields a clock of 4.5 MHz or slightly less, but in certain cases (such as a high-impedance analog source) a slower clock may be desirable. +#define AD0CR_CLKDIV_SHIFT 8 +#define AD0CR_BURST (1 << 16) // Burst mode Remark: If BURST is set to 1, the ADGINTEN bit in the AD0INTEN register (Table 365) must be set to 0. +#define AD0CR_CLKS_MASK 0xE0000 // This field selects the number of clocks used for each conversion in Burst mode, and the number of bits of accuracy of the result in the LS bits of ADDR, between 11 clocks (10 bits) and 4 clocks (3 bits). +#define AD0CR_CLKS_SHIFT 17 +#define AD0CR_START_MASK 0x7000000 // When the BURST bit is 0, these bits control whether and when an A/D conversion is started: +#define AD0CR_START_SHIFT 24 +#define AD0CR_EDGE (1 << 27) // This bit is significant only when the START field contains 010-111. In these cases: + +/* AD0GDR - address 0x4001 C004 */ +#define AD0GDR_V_VREF_MASK 0xFFC0 // When DONE is 1, this field contains a binary fraction representing X the voltage on the ADn pin selected by the SEL field, divided by the voltage on the VDD pin. Zero in the field indicates that the voltage on the ADn pin was less than, equal to, or close to that on VSS, while 0x3FF indicates that the voltage on ADn was close to, equal to, or greater than that on VREF. +#define AD0GDR_V_VREF_SHIFT 6 +#define AD0GDR_CHN_MASK 0x7000000 // These bits contain the channel from which the result bits V_VREF X were converted. +#define AD0GDR_CHN_SHIFT 24 +#define AD0GDR_OVERRUN (1 << 30) // This bit is 1 in burst mode if the results of one or more conversions 0 was (were) lost and overwritten before the conversion that produced the result in the V_VREF bits. +#define AD0GDR_DONE (1 << 31) // This bit is set to 1 when an A/D conversion completes. It is cleared 0 when this register is read and when the ADCR is written. If the ADCR is written while a conversion is still in progress, this bit is set and a new conversion is started. + +/* AD0INTEN - address 0x4001 C00C */ +#define AD0INTEN_ADINTEN_MASK 0x00FF // These bits allow control over which A/D channels generate 0x00 interrupts for conversion completion. When bit 0 is one, completion of a conversion on A/D channel 0 will generate an interrupt, when bit 1 is one, completion of a conversion on A/D channel 1 will generate an interrupt, etc. +#define AD0INTEN_ADINTEN_SHIFT 0 +#define AD0INTEN_ADGINTEN (1 << 8) // When 1, enables the global DONE flag in ADDR to generate an interrupt. When 0, only the individual A/D channels enabled by ADINTEN 7:0 will generate interrupts. Remark: This bit must be set to 0 in burst mode (BURST = 1 in the AD0CR register). Reserved. Unused, always 0. + +/* AD0DR0 to AD0DR7 - addresses 0x4001 C010 to 0x4001 C02C */ +#define AD0DRn_V_VREF_MASK 0xFFC0 // When DONE is 1, this field contains a binary fraction representing the NA voltage on the ADn pin, divided by the voltage on the VREF pin. Zero in the field indicates that the voltage on the ADn pin was less than, equal to, or close to that on VREF, while 0x3FF indicates that the voltage on AD input was close to, equal to, or greater than that on VREF. Reserved. +#define AD0DRn_V_VREF_SHIFT 6 +#define AD0DRn_OVERRUN (1 << 30) // This bit is 1 in burst mode if the results of one or more conversions was (were) lost and overwritten before the conversion that produced the result in the V_VREF bits.This bit is cleared by reading this register. +#define AD0DRn_DONE (1 << 31) // This bit is set to 1 when an A/D conversion completes. It is cleared when this register is read. + +/* AD0STAT - address 0x4001 C030 */ +#define AD0STAT_DONE_MASK 0x00FF // These bits mirror the DONE status flags that appear in the result register for each A/D channel n. +#define AD0STAT_DONE_SHIFT 0 +#define AD0STAT_OVERRUN_MASK 0xFF00 // These bits mirror the OVERRRUN status flags that appear in the result register for each A/D channel n. Reading ADSTAT allows checking the status of all A/D channels simultaneously. +#define AD0STAT_OVERRUN_SHIFT 8 +#define AD0STAT_ADINT (1 << 16) // This bit is the A/D interrupt flag. It is one when any of the individual A/D channel Done flags is asserted and enabled to contribute to the A/D interrupt via the ADINTEN register. Reserved. Unused, always 0. + +/* FLASHCFG, address 0x4003 C010 */ +#define FLASHCFG_FLASHTIM_MASK 0x0003 // Flash memory access time. FLASHTIM +1 is equal to the number of system clocks used for flash access. +#define FLASHCFG_FLASHTIM_SHIFT 0 + +/* FMSSTART - 0x4003 C020 */ +#define FMSSTART_START_MASK 0x1FFFF // Signature generation start address (corresponds to AHB byte address bits[20:4]). +#define FMSSTART_START_SHIFT 0 + +/* FMSSTOP - 0x4003 C024 */ +#define FMSSTOP_STOP_MASK 0x1FFFF // BIST stop address divided by 16 (corresponds to AHB byte address [20:4]). +#define FMSSTOP_STOP_SHIFT 0 +#define FMSSTOP_SIG_START (1 << 17) // Start control bit for signature generation. + +/* FMSTAT - 0x4003 CFE0 */ +#define FMSTAT_SIG_DONE (1 << 2) // When 1, a previously started signature generation has 0 completed. See FMSTATCLR register description for clearing this flag. + +/* FMSTATCLR - 0x0x4003 CFE8 */ +#define FMSTATCLR_SIG_DONE_CLR (1 << 2) // Writing a 1 to this bits clears the signature generation completion flag (SIG_DONE) in the FMSTAT register. + + +#endif diff --git a/mbed-cmsis.h b/mbed-cmsis.h new file mode 100644 index 0000000..519a132 --- /dev/null +++ b/mbed-cmsis.h @@ -0,0 +1,26 @@ +/* mbed Microcontroller Library - CMSIS + * Copyright (C) 2009-2011 ARM Limited. All rights reserved. + * + * A generic CMSIS include header, pulling in LPC11U24 specifics + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ + +#ifndef MBED_CMSIS_H +#define MBED_CMSIS_H + +#include "mbed-LPC11xx.h" +#include "mbed-cmsis_nvic.h" +#include "mbed-bitfields.h" + +#endif diff --git a/mbed-cmsis_nvic.h b/mbed-cmsis_nvic.h new file mode 100644 index 0000000..b9bd4ec --- /dev/null +++ b/mbed-cmsis_nvic.h @@ -0,0 +1,63 @@ +/* mbed Microcontroller Library + * CMSIS-style functionality to support dynamic vectors + ******************************************************************************* + * Copyright (c) 2011 ARM Limited. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of ARM Limited 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 THE COPYRIGHT HOLDER OR 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. + ******************************************************************************* + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis_nvic.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ + +#ifndef MBED_CMSIS_NVIC_H +#define MBED_CMSIS_NVIC_H + +#include "mbed-cmsis.h" + +#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals +#define NVIC_USER_IRQ_OFFSET 16 + +#ifdef __cplusplus +extern "C" { +#endif + +void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); +uint32_t NVIC_GetVector(IRQn_Type IRQn); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-core_cm0.h b/mbed-core_cm0.h new file mode 100644 index 0000000..2b96184 --- /dev/null +++ b/mbed-core_cm0.h @@ -0,0 +1,694 @@ +/**************************************************************************//** + * @file core_cm0.h + * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File + * @version V3.20 + * @date 25. February 2013 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2013 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. + ---------------------------------------------------------------------------*/ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/core_cm0.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ + + +#if defined ( __ICCARM__ ) + #pragma system_include /* treat file as system include file for MISRA check */ +#endif + +#ifdef __cplusplus + extern "C" { +#endif + +#ifndef __CORE_CM0_H_GENERIC +#define __CORE_CM0_H_GENERIC + +/** \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 CM0 definitions */ +#define __CM0_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */ +#define __CM0_CMSIS_VERSION_SUB (0x20) /*!< [15:0] CMSIS HAL sub version */ +#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | \ + __CM0_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 ( __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 ( __GNUC__ ) + #define __ASM __asm /*!< asm keyword for GNU Compiler */ + #define __INLINE inline /*!< inline keyword for GNU 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 + +#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 ( __ICCARM__ ) + #if defined __ARMVFP__ + #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 ( __TASKING__ ) + #if defined __FPU_VFP__ + #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" + #endif +#endif + +#include /* standard types definitions */ +#include "mbed-core_cmInstr.h" /* Core Instruction Access */ +#include "mbed-core_cmFunc.h" /* Core Function Access */ + +#endif /* __CORE_CM0_H_GENERIC */ + +#ifndef __CMSIS_GENERIC + +#ifndef __CORE_CM0_H_DEPENDANT +#define __CORE_CM0_H_DEPENDANT + +/* check device defines and use defaults */ +#if defined __CHECK_DEVICE_DEFINES + #ifndef __CM0_REV + #define __CM0_REV 0x0000 + #warning "__CM0_REV 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 + ******************************************************************************/ +/** \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 */ + uint32_t RESERVED0; + __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 */ + +/* 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_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */ + +/*@} end of group CMSIS_SysTick */ + + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) + \brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) + are only accessible over DAP and not via processor. Therefore + they are not covered by the Cortex-M0 header file. + @{ + */ +/*@} end of group CMSIS_CoreDebug */ + + +/** \ingroup CMSIS_core_register + \defgroup CMSIS_core_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 */ + + +/*@} */ + + + +/******************************************************************************* + * 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 */ + + + + +#endif /* __CORE_CM0_H_DEPENDANT */ + +#endif /* __CMSIS_GENERIC */ + +#ifdef __cplusplus +} +#endif diff --git a/mbed-core_cmFunc.h b/mbed-core_cmFunc.h new file mode 100644 index 0000000..85178e2 --- /dev/null +++ b/mbed-core_cmFunc.h @@ -0,0 +1,645 @@ +/**************************************************************************//** + * @file core_cmFunc.h + * @brief CMSIS Cortex-M Core Function Access Header File + * @version V3.20 + * @date 25. February 2013 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2013 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. + ---------------------------------------------------------------------------*/ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/core_cmFunc.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ + + +#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) + +/** \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) */ + + +#if (__CORTEX_M == 0x04) + +/** \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) */ + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ + +#include + + +#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ +/* TI CCS specific functions */ + +#include + + +#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) + +/** \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) */ + + +#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 instrinsics, + * Including the CMSIS ones. + */ + +#endif + +/*@} end of CMSIS_Core_RegAccFunctions */ + + +#endif /* __CORE_CMFUNC_H */ diff --git a/mbed-core_cmInstr.h b/mbed-core_cmInstr.h new file mode 100644 index 0000000..f5e029b --- /dev/null +++ b/mbed-core_cmInstr.h @@ -0,0 +1,697 @@ +/**************************************************************************//** + * @file core_cmInstr.h + * @brief CMSIS Cortex-M Core Instruction Access Header File + * @version V3.20 + * @date 05. March 2013 + * + * @note + * + ******************************************************************************/ +/* Copyright (c) 2009 - 2013 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. + ---------------------------------------------------------------------------*/ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/core_cmInstr.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ + + +#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) + +/** \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 performs a exclusive LDR command 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 performs a exclusive LDR command 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 performs a exclusive LDR command 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 performs a exclusive STR command 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 performs a exclusive STR command 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 performs a exclusive STR command 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 + +#endif /* (__CORTEX_M >= 0x03) */ + + + +#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ +/* IAR iccarm specific functions */ + +#include + + +#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ +/* TI CCS specific functions */ + +#include + + +#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) + +/** \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 performs a exclusive LDR command 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(result); +} + + +/** \brief LDR Exclusive (16 bit) + + This function performs a exclusive LDR command 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(result); +} + + +/** \brief LDR Exclusive (32 bit) + + This function performs a exclusive LDR command 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 performs a exclusive STR command 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" (value) ); + return(result); +} + + +/** \brief STR Exclusive (16 bit) + + This function performs a exclusive STR command 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" (value) ); + return(result); +} + + +/** \brief STR Exclusive (32 bit) + + This function performs a exclusive STR command 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(result); +} + +#endif /* (__CORTEX_M >= 0x03) */ + + + + +#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. + */ + +#endif + +/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ + +#endif /* __CORE_CMINSTR_H */ diff --git a/mbed-device.h b/mbed-device.h new file mode 100644 index 0000000..d8a1bc6 --- /dev/null +++ b/mbed-device.h @@ -0,0 +1,71 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/device.h + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef MBED_DEVICE_H +#define MBED_DEVICE_H + +#define DEVICE_PORTIN 1 +#define DEVICE_PORTOUT 1 +#define DEVICE_PORTINOUT 1 + +#define DEVICE_INTERRUPTIN 1 + +#define DEVICE_ANALOGIN 1 +#define DEVICE_ANALOGOUT 0 + +#define DEVICE_SERIAL 1 + +#define DEVICE_I2C 1 +#define DEVICE_I2CSLAVE 1 + +#define DEVICE_SPI 1 +#define DEVICE_SPISLAVE 1 + +#define DEVICE_CAN 0 + +#define DEVICE_RTC 0 + +#define DEVICE_ETHERNET 0 + +#define DEVICE_PWMOUT 1 + +#define DEVICE_SEMIHOST 0 +#define DEVICE_LOCALFILESYSTEM 0 +#define DEVICE_ID_LENGTH 32 +#define DEVICE_MAC_OFFSET 20 + +#define DEVICE_SLEEP 1 + +#define DEVICE_DEBUG_AWARENESS 0 + +#define DEVICE_STDIO_MESSAGES 1 + +#define DEVICE_ERROR_PATTERN 1 + +#include "mbed-objects.h" + +#endif diff --git a/mbed-error.c b/mbed-error.c new file mode 100644 index 0000000..ca72c6d --- /dev/null +++ b/mbed-error.c @@ -0,0 +1,49 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/common/error.c. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. + - Wrapped the whole file in #ifdef __ARMEL__ to not cause conflicts with + AVR builds. +*/ +#ifdef __ARMEL__ +#include +#include +#include "mbed-device.h" +#include "mbed-toolchain.h" +#include "mbed-mbed_error.h" +#if DEVICE_STDIO_MESSAGES +#include +#endif + +WEAK void error(const char* format, ...) { +#if DEVICE_STDIO_MESSAGES + va_list arg; + va_start(arg, format); + vfprintf(stderr, format, arg); + va_end(arg); +#endif + exit(1); +} +#endif /* __ARMEL__ */ diff --git a/mbed-gpio_object.h b/mbed-gpio_object.h new file mode 100644 index 0000000..24df410 --- /dev/null +++ b/mbed-gpio_object.h @@ -0,0 +1,66 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/mbed/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/gpio_object.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef MBED_GPIO_OBJECT_H +#define MBED_GPIO_OBJECT_H + +#include "mbed-mbed_assert.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + __I uint32_t *reg_mask_read; + __IO uint32_t *reg_dir; + __IO uint32_t *reg_write; +} gpio_t; + +static inline void gpio_write(gpio_t *obj, int value) { + MBED_ASSERT(obj->pin != (PinName)NC); + uint32_t pin_number = ((obj->pin & 0x0F00) >> 8); + if (value) + *obj->reg_write |= (1 << pin_number); + else + *obj->reg_write &= ~(1 << pin_number); +} + +static inline int gpio_read(gpio_t *obj) { + MBED_ASSERT(obj->pin != (PinName)NC); + return ((*obj->reg_mask_read) ? 1 : 0); +} + +static inline int gpio_is_connected(const gpio_t *obj) { + return obj->pin != (PinName)NC; +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-mbed_assert.h b/mbed-mbed_assert.h new file mode 100644 index 0000000..d93d0bc --- /dev/null +++ b/mbed-mbed_assert.h @@ -0,0 +1,59 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/api/mbed_assert.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ +#ifndef MBED_ASSERT_H +#define MBED_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** Internal mbed assert function which is invoked when MBED_ASSERT macro failes. + * This function is active only if NDEBUG is not defined prior to including this + * assert header file. + * In case of MBED_ASSERT failing condition, the assertation message is printed + * to stderr and mbed_die() is called. + * @param expr Expresion to be checked. + * @param file File where assertation failed. + * @param line Failing assertation line number. + */ +void mbed_assert_internal(const char *expr, const char *file, int line); + +#ifdef __cplusplus +} +#endif + +#ifdef NDEBUG +#define MBED_ASSERT(expr) ((void)0) + +#else +#define MBED_ASSERT(expr) \ +do { \ + if (!(expr)) { \ + mbed_assert_internal(#expr, __FILE__, __LINE__); \ + } \ +} while (0) +#endif + +#endif diff --git a/mbed-mbed_error.h b/mbed-mbed_error.h new file mode 100644 index 0000000..8b72480 --- /dev/null +++ b/mbed-mbed_error.h @@ -0,0 +1,75 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/home/mah/RepRap/mbed/libraries/mbed/api/mbed_error.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ +#ifndef MBED_ERROR_H +#define MBED_ERROR_H + +/** To generate a fatal compile-time error, you can use the pre-processor #error directive. + * + * @code + * #error "That shouldn't have happened!" + * @endcode + * + * If the compiler evaluates this line, it will report the error and stop the compile. + * + * For example, you could use this to check some user-defined compile-time variables: + * + * @code + * #define NUM_PORTS 7 + * #if (NUM_PORTS > 4) + * #error "NUM_PORTS must be less than 4" + * #endif + * @endcode + * + * Reporting Run-Time Errors: + * To generate a fatal run-time error, you can use the mbed error() function. + * + * @code + * error("That shouldn't have happened!"); + * @endcode + * + * If the mbed running the program executes this function, it will print the + * message via the USB serial port, and then die with the blue lights of death! + * + * The message can use printf-style formatting, so you can report variables in the + * message too. For example, you could use this to check a run-time condition: + * + * @code + * if(x >= 5) { + * error("expected x to be less than 5, but got %d", x); + * } + * #endcode + */ + +#ifdef __cplusplus +extern "C" { +#endif + +void error(const char* format, ...); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-objects.h b/mbed-objects.h new file mode 100644 index 0000000..52dc8ab --- /dev/null +++ b/mbed-objects.h @@ -0,0 +1,86 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/objects.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef MBED_OBJECTS_H +#define MBED_OBJECTS_H + +#include "mbed-cmsis.h" +#include "mbed-PortNames.h" +#include "mbed-PeripheralNames.h" +#include "mbed-PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct gpio_irq_s { + uint32_t ch; + PinName pin; + __I uint32_t *reg_mask_read; +}; + +struct port_s { + __IO uint32_t *reg_dir; + __IO uint32_t *reg_data; + PortName port; + uint32_t mask; +}; + +struct pwmout_s { + PWMName pwm; +}; + +struct serial_s { + LPC_UART_TypeDef *uart; + int index; +}; + +struct analogin_s { + ADCName adc; +}; + +struct i2c_s { + LPC_I2C_TypeDef *i2c; +}; + +struct spi_s { + LPC_SSP_TypeDef *spi; +}; + +#if DEVICE_CAN +struct can_s { + int index; +}; +#endif + +#include "mbed-gpio_object.h" + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-pinmap.c b/mbed-pinmap.c new file mode 100644 index 0000000..0af9733 --- /dev/null +++ b/mbed-pinmap.c @@ -0,0 +1,62 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/pinmap.c. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. + - Wrapped the whole file in #ifdef __ARMEL__ to not cause conflicts with + AVR builds. +*/ +#ifdef __ARMEL__ +#include "mbed-mbed_assert.h" +#include "mbed-pinmap.h" +#include "mbed-mbed_error.h" + +void pin_function(PinName pin, int function) { + MBED_ASSERT(pin != (PinName)NC); + uint32_t offset = (uint32_t)pin & 0xff; + __IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset); + + // pin function bits: [2:0] -> 111 = (0x7) + *reg = (*reg & ~0x7) | (function & 0x7); +} + +void pin_mode(PinName pin, PinMode mode) { + MBED_ASSERT(pin != (PinName)NC); + uint32_t offset = (uint32_t)pin & 0xff; + uint32_t drain = ((uint32_t)mode & (uint32_t)OpenDrain) >> 2; + + __IO uint32_t *reg = (__IO uint32_t*)(LPC_IOCON_BASE + offset); + uint32_t tmp = *reg; + + // pin mode bits: [4:3] -> 11000 = (0x3 << 3) + tmp &= ~(0x3 << 3); + tmp |= (mode & 0x3) << 3; + + // drain + tmp &= ~(0x1 << 10); + tmp |= drain << 10; + + *reg = tmp; +} +#endif /* __ARMEL__ */ diff --git a/mbed-pinmap.h b/mbed-pinmap.h new file mode 100644 index 0000000..f141e3b --- /dev/null +++ b/mbed-pinmap.h @@ -0,0 +1,55 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/hal/pinmap.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ +#ifndef MBED_PINMAP_H +#define MBED_PINMAP_H + +#include "mbed-PinNames.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct { + PinName pin; + int peripheral; + int function; +} PinMap; + +void pin_function(PinName pin, int function); +void pin_mode (PinName pin, PinMode mode); + +uint32_t pinmap_peripheral(PinName pin, const PinMap* map); +uint32_t pinmap_merge (uint32_t a, uint32_t b); +void pinmap_pinout (PinName pin, const PinMap *map); +uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mbed-pinmap_common.c b/mbed-pinmap_common.c new file mode 100644 index 0000000..ed874d3 --- /dev/null +++ b/mbed-pinmap_common.c @@ -0,0 +1,85 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/common/pinmap_common.c. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. + - Wrapped the whole file in #ifdef __ARMEL__ to not cause conflicts with + AVR builds. +*/ +#ifdef __ARMEL__ +#include "mbed-pinmap.h" +#include "mbed-mbed_error.h" + +void pinmap_pinout(PinName pin, const PinMap *map) { + if (pin == NC) + return; + + while (map->pin != NC) { + if (map->pin == pin) { + pin_function(pin, map->function); + + pin_mode(pin, PullNone); + return; + } + map++; + } + error("could not pinout"); +} + +uint32_t pinmap_merge(uint32_t a, uint32_t b) { + // both are the same (inc both NC) + if (a == b) + return a; + + // one (or both) is not connected + if (a == (uint32_t)NC) + return b; + if (b == (uint32_t)NC) + return a; + + // mis-match error case + error("pinmap mis-match"); + return (uint32_t)NC; +} + +uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { + while (map->pin != NC) { + if (map->pin == pin) + return map->peripheral; + map++; + } + return (uint32_t)NC; +} + +uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { + uint32_t peripheral = (uint32_t)NC; + + if (pin == (PinName)NC) + return (uint32_t)NC; + peripheral = pinmap_find_peripheral(pin, map); + if ((uint32_t)NC == peripheral) // no mapping available + error("pinmap not found for peripheral"); + return peripheral; +} +#endif /* __ARMEL__ */ diff --git a/mbed-serial_api.c b/mbed-serial_api.c new file mode 100644 index 0000000..aad4031 --- /dev/null +++ b/mbed-serial_api.c @@ -0,0 +1,319 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// math.h required for floating point operations for baud rate calculation +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/serial_api.c. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. + - Wrapped the whole file in #ifdef __ARMEL__ to not cause conflicts with + AVR builds. + - Prefixed function names with mbed_ to not conflict with Teacup names. + - Fixed mbed_uart0_irq() function prototype. +*/ +#ifdef __ARMEL__ +#include "mbed-mbed_assert.h" +#include +#include +#include + +#include "mbed-serial_api.h" +#include "mbed-cmsis.h" +#include "mbed-pinmap.h" + +/****************************************************************************** + * INITIALIZATION + ******************************************************************************/ +#define UART_NUM 1 + +static const PinMap PinMap_UART_TX[] = { + {P2_8 , UART_0, 0x02}, + {P3_5 , UART_0, 0x02}, + {P3_0 , UART_0, 0x03}, + {P1_7 , UART_0, 0x01}, + {NC , NC , 0x00} +}; + +static const PinMap PinMap_UART_RX[] = { + {P2_7 , UART_0, 0x02}, + {P3_4 , UART_0, 0x02}, + {P3_1 , UART_0, 0x03}, + {P1_6 , UART_0, 0x01}, + {NC , NC , 0x00} +}; + +static uint32_t serial_irq_ids[UART_NUM] = {0}; +static uart_irq_handler irq_handler; + +int stdio_uart_inited = 0; +serial_t stdio_uart; + +void mbed_serial_init(serial_t *obj, PinName tx, PinName rx) { + int is_stdio_uart = 0; + + // determine the UART to use + UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX); + UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX); + UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx); + MBED_ASSERT((int)uart != NC); + + obj->uart = (LPC_UART_TypeDef *)uart; + LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); + + // enable fifos and default rx trigger level + obj->uart->FCR = 1 << 0 // FIFO Enable - 0 = Disables, 1 = Enabled + | 0 << 1 // Rx Fifo Reset + | 0 << 2 // Tx Fifo Reset + | 0 << 6; // Rx irq trigger level - 0 = 1 char, 1 = 4 chars, 2 = 8 chars, 3 = 14 chars + + // disable irqs + obj->uart->IER = 0 << 0 // Rx Data available irq enable + | 0 << 1 // Tx Fifo empty irq enable + | 0 << 2; // Rx Line Status irq enable + + // set default baud rate and format + mbed_serial_baud (obj, 9600); + mbed_serial_format(obj, 8, ParityNone, 1); + + // pinout the chosen uart + pinmap_pinout(tx, PinMap_UART_TX); + pinmap_pinout(rx, PinMap_UART_RX); + + // set rx/tx pins in PullUp mode + if (tx != NC) { + pin_mode(tx, PullUp); + } + if (rx != NC) { + pin_mode(rx, PullUp); + } + + switch (uart) { + case UART_0: obj->index = 0; break; + } + + is_stdio_uart = (uart == STDIO_UART) ? (1) : (0); + + if (is_stdio_uart) { + stdio_uart_inited = 1; + memcpy(&stdio_uart, obj, sizeof(serial_t)); + } +} + +void mbed_serial_free(serial_t *obj) { + serial_irq_ids[obj->index] = 0; +} + +// serial_baud +// set the baud rate, taking in to account the current SystemFrequency +void mbed_serial_baud(serial_t *obj, int baudrate) { + LPC_SYSCON->UARTCLKDIV = 0x1; + uint32_t PCLK = SystemCoreClock; + // First we check to see if the basic divide with no DivAddVal/MulVal + // ratio gives us an integer result. If it does, we set DivAddVal = 0, + // MulVal = 1. Otherwise, we search the valid ratio value range to find + // the closest match. This could be more elegant, using search methods + // and/or lookup tables, but the brute force method is not that much + // slower, and is more maintainable. + uint16_t DL = PCLK / (16 * baudrate); + + uint8_t DivAddVal = 0; + uint8_t MulVal = 1; + int hit = 0; + uint16_t dlv; + uint8_t mv, dav; + if ((PCLK % (16 * baudrate)) != 0) { // Checking for zero remainder + int err_best = baudrate, b; + for (mv = 1; mv < 16 && !hit; mv++) + { + for (dav = 0; dav < mv; dav++) + { + // baudrate = PCLK / (16 * dlv * (1 + (DivAdd / Mul)) + // solving for dlv, we get dlv = mul * PCLK / (16 * baudrate * (divadd + mul)) + // mul has 4 bits, PCLK has 27 so we have 1 bit headroom which can be used for rounding + // for many values of mul and PCLK we have 2 or more bits of headroom which can be used to improve precision + // note: X / 32 doesn't round correctly. Instead, we use ((X / 16) + 1) / 2 for correct rounding + + if ((mv * PCLK * 2) & 0x80000000) // 1 bit headroom + dlv = ((((2 * mv * PCLK) / (baudrate * (dav + mv))) / 16) + 1) / 2; + else // 2 bits headroom, use more precision + dlv = ((((4 * mv * PCLK) / (baudrate * (dav + mv))) / 32) + 1) / 2; + + // datasheet says if DLL==DLM==0, then 1 is used instead since divide by zero is ungood + if (dlv == 0) + dlv = 1; + + // datasheet says if dav > 0 then DL must be >= 2 + if ((dav > 0) && (dlv < 2)) + dlv = 2; + + // integer rearrangement of the baudrate equation (with rounding) + b = ((PCLK * mv / (dlv * (dav + mv) * 8)) + 1) / 2; + + // check to see how we went + b = abs(b - baudrate); + if (b < err_best) + { + err_best = b; + + DL = dlv; + MulVal = mv; + DivAddVal = dav; + + if (b == baudrate) + { + hit = 1; + break; + } + } + } + } + } + + // set LCR[DLAB] to enable writing to divider registers + obj->uart->LCR |= (1 << 7); + + // set divider values + obj->uart->DLM = (DL >> 8) & 0xFF; + obj->uart->DLL = (DL >> 0) & 0xFF; + obj->uart->FDR = (uint32_t) DivAddVal << 0 + | (uint32_t) MulVal << 4; + + // clear LCR[DLAB] + obj->uart->LCR &= ~(1 << 7); +} + +void mbed_serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits) { + MBED_ASSERT((stop_bits == 1) || (stop_bits == 2)); // 0: 1 stop bits, 1: 2 stop bits + MBED_ASSERT((data_bits > 4) && (data_bits < 9)); // 0: 5 data bits ... 3: 8 data bits + MBED_ASSERT((parity == ParityNone) || (parity == ParityOdd) || (parity == ParityEven) || + (parity == ParityForced1) || (parity == ParityForced0)); + + stop_bits -= 1; + data_bits -= 5; + + int parity_enable, parity_select; + switch (parity) { + case ParityNone: parity_enable = 0; parity_select = 0; break; + case ParityOdd : parity_enable = 1; parity_select = 0; break; + case ParityEven: parity_enable = 1; parity_select = 1; break; + case ParityForced1: parity_enable = 1; parity_select = 2; break; + case ParityForced0: parity_enable = 1; parity_select = 3; break; + default: + break; + } + + obj->uart->LCR = data_bits << 0 + | stop_bits << 2 + | parity_enable << 3 + | parity_select << 4; +} + +/****************************************************************************** + * INTERRUPTS HANDLING + ******************************************************************************/ +static inline void mbed_uart_irq(uint32_t iir, uint32_t index) { + // [Chapter 14] LPC17xx UART0/2/3: UARTn Interrupt Handling + SerialIrq irq_type; + switch (iir) { + case 1: irq_type = TxIrq; break; + case 2: irq_type = RxIrq; break; + default: return; + } + + if (serial_irq_ids[index] != 0) + irq_handler(serial_irq_ids[index], irq_type); +} + +void mbed_uart0_irq(void) {mbed_uart_irq((LPC_UART->IIR >> 1) & 0x7, 0);} + +void mbed_serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id) { + irq_handler = handler; + serial_irq_ids[obj->index] = id; +} + +void mbed_serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable) { + IRQn_Type irq_n = (IRQn_Type)0; + uint32_t vector = 0; + switch ((int)obj->uart) { + case UART_0: + irq_n=UART_IRQn; + vector = (uint32_t)&mbed_uart0_irq; + break; + default: + return; + } + + if (enable) { + obj->uart->IER |= 1 << irq; + NVIC_SetVector(irq_n, vector); + NVIC_EnableIRQ(irq_n); + } else { // disable + int all_disabled = 0; + SerialIrq other_irq = (irq == RxIrq) ? (TxIrq) : (RxIrq); + + obj->uart->IER &= ~(1 << irq); + all_disabled = (obj->uart->IER & (1 << other_irq)) == 0; + + if (all_disabled) + NVIC_DisableIRQ(irq_n); + } +} + +/****************************************************************************** + * READ/WRITE + ******************************************************************************/ +int mbed_serial_getc(serial_t *obj) { + while (!mbed_serial_readable(obj)); + return obj->uart->RBR; +} + +void mbed_serial_putc(serial_t *obj, int c) { + while (!mbed_serial_writable(obj)); + obj->uart->THR = c; +} + +int mbed_serial_readable(serial_t *obj) { + return obj->uart->LSR & 0x01; +} + +int mbed_serial_writable(serial_t *obj) { + return obj->uart->LSR & 0x20; +} + +void mbed_serial_clear(serial_t *obj) { + obj->uart->FCR = 1 << 1 // rx FIFO reset + | 1 << 2 // tx FIFO reset + | 0 << 6; // interrupt depth +} + +void mbed_serial_pinout_tx(PinName tx) { + pinmap_pinout(tx, PinMap_UART_TX); +} + +void mbed_serial_break_clear(serial_t *obj) { + obj->uart->LCR &= ~(1 << 6); +} + +void mbed_serial_break_set(serial_t *obj) { + obj->uart->LCR |= 1 << 6; +} +#endif /* __ARMEL__ */ diff --git a/mbed-serial_api.h b/mbed-serial_api.h new file mode 100644 index 0000000..777fe25 --- /dev/null +++ b/mbed-serial_api.h @@ -0,0 +1,91 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/hal/serial_api.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. + - Prefixed function names with mbed_ to not conflict with Teacup names. +*/ +#ifndef MBED_SERIAL_API_H +#define MBED_SERIAL_API_H + +#include "mbed-device.h" + +#if DEVICE_SERIAL + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + ParityNone = 0, + ParityOdd = 1, + ParityEven = 2, + ParityForced1 = 3, + ParityForced0 = 4 +} SerialParity; + +typedef enum { + RxIrq, + TxIrq +} SerialIrq; + +typedef enum { + FlowControlNone, + FlowControlRTS, + FlowControlCTS, + FlowControlRTSCTS +} FlowControl; + +typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event); + +typedef struct serial_s serial_t; + +void mbed_serial_init (serial_t *obj, PinName tx, PinName rx); +void mbed_serial_free (serial_t *obj); +void mbed_serial_baud (serial_t *obj, int baudrate); +void mbed_serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits); + +void mbed_serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id); +void mbed_serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable); + +int mbed_serial_getc (serial_t *obj); +void mbed_serial_putc (serial_t *obj, int c); +int mbed_serial_readable (serial_t *obj); +int mbed_serial_writable (serial_t *obj); +void mbed_serial_clear (serial_t *obj); + +void mbed_serial_break_set (serial_t *obj); +void mbed_serial_break_clear(serial_t *obj); + +void mbed_serial_pinout_tx(PinName tx); + +void mbed_serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow); + +#ifdef __cplusplus +} +#endif + +#endif + +#endif diff --git a/mbed-system_LPC11xx.c b/mbed-system_LPC11xx.c new file mode 100644 index 0000000..d1b712e --- /dev/null +++ b/mbed-system_LPC11xx.c @@ -0,0 +1,383 @@ +/**************************************************************************//** + * @file system_LPC11xx.c + * @brief CMSIS Cortex-M0 Device Peripheral Access Layer Source File + * for the NXP LPC11xx/LPC11Cxx Devices + * @version V1.10 + * @date 24. November 2010 + * + * @note + * Copyright (C) 2009-2010 ARM Limited. All rights reserved. + * + * @par + * ARM Limited (ARM) is supplying this software for use with Cortex-M + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * @par + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11XX/system_LPC11xx.c. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. + - Wrapped the whole file in #ifdef __ARMEL__ to not cause conflicts with + AVR builds. +*/ + +#ifdef __ARMEL__ + +#include +#include "mbed-LPC11xx.h" + +/* +//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------ +*/ + +/*--------------------- Clock Configuration ---------------------------------- +// +// Clock Configuration +// System Oscillator Control Register (SYSOSCCTRL) +// BYPASS: System Oscillator Bypass Enable +// If enabled then PLL input (sys_osc_clk) is fed +// directly from XTALIN and XTALOUT pins. +// FREQRANGE: System Oscillator Frequency Range +// Determines frequency range for Low-power oscillator. +// <0=> 1 - 20 MHz +// <1=> 15 - 25 MHz +// +// +// Watchdog Oscillator Control Register (WDTOSCCTRL) +// DIVSEL: Select Divider for Fclkana +// wdt_osc_clk = Fclkana/ (2 * (1 + DIVSEL)) +// <0-31> +// FREQSEL: Select Watchdog Oscillator Analog Output Frequency (Fclkana) +// <0=> Undefined +// <1=> 0.5 MHz +// <2=> 0.8 MHz +// <3=> 1.1 MHz +// <4=> 1.4 MHz +// <5=> 1.6 MHz +// <6=> 1.8 MHz +// <7=> 2.0 MHz +// <8=> 2.2 MHz +// <9=> 2.4 MHz +// <10=> 2.6 MHz +// <11=> 2.7 MHz +// <12=> 2.9 MHz +// <13=> 3.1 MHz +// <14=> 3.2 MHz +// <15=> 3.4 MHz +// +// +// System PLL Control Register (SYSPLLCTRL) +// F_clkout = M * F_clkin = F_CCO / (2 * P) +// F_clkin must be in the range of 10 MHz to 25 MHz +// F_CCO must be in the range of 156 MHz to 320 MHz +// MSEL: Feedback Divider Selection +// M = MSEL + 1 +// <0-31> +// PSEL: Post Divider Selection +// <0=> P = 1 +// <1=> P = 2 +// <2=> P = 4 +// <3=> P = 8 +// +// +// System PLL Clock Source Select Register (SYSPLLCLKSEL) +// SEL: System PLL Clock Source +// <0=> IRC Oscillator +// <1=> System Oscillator +// <2=> Reserved +// <3=> Reserved +// +// +// Main Clock Source Select Register (MAINCLKSEL) +// SEL: Clock Source for Main Clock +// <0=> IRC Oscillator +// <1=> Input Clock to System PLL +// <2=> WDT Oscillator +// <3=> System PLL Clock Out +// +// +// System AHB Clock Divider Register (SYSAHBCLKDIV) +// DIV: System AHB Clock Divider +// Divides main clock to provide system clock to core, memories, and peripherals. +// 0 = is disabled +// <0-255> +// +// +*/ +#define CLOCK_SETUP 1 +#define SYSOSCCTRL_Val 0x00000000 // Reset: 0x000 +#define WDTOSCCTRL_Val 0x00000000 // Reset: 0x000 +#define SYSPLLCTRL_Val 0x00000023 // Reset: 0x000 +#define SYSPLLCLKSEL_Val 0x00000000 // Reset: 0x000 // Define as using IRC +#define MAINCLKSEL_Val 0x00000003 // Reset: 0x000 // Define as using System PLL clock out +#define SYSAHBCLKDIV_Val 0x00000001 // Reset: 0x001 + +/* +//-------- <<< end of configuration section >>> ------------------------------ +*/ + +/*---------------------------------------------------------------------------- + Check the register settings + *----------------------------------------------------------------------------*/ +#define CHECK_RANGE(val, min, max) ((val < min) || (val > max)) +#define CHECK_RSVD(val, mask) (val & mask) + +/* Clock Configuration -------------------------------------------------------*/ +#if (CHECK_RSVD((SYSOSCCTRL_Val), ~0x00000003)) + #error "SYSOSCCTRL: Invalid values of reserved bits!" +#endif + +#if (CHECK_RSVD((WDTOSCCTRL_Val), ~0x000001FF)) + #error "WDTOSCCTRL: Invalid values of reserved bits!" +#endif + +#if (CHECK_RANGE((SYSPLLCLKSEL_Val), 0, 2)) + #error "SYSPLLCLKSEL: Value out of range!" +#endif + +#if (CHECK_RSVD((SYSPLLCTRL_Val), ~0x000001FF)) + #error "SYSPLLCTRL: Invalid values of reserved bits!" +#endif + +#if (CHECK_RSVD((MAINCLKSEL_Val), ~0x00000003)) + #error "MAINCLKSEL: Invalid values of reserved bits!" +#endif + +#if (CHECK_RANGE((SYSAHBCLKDIV_Val), 0, 255)) + #error "SYSAHBCLKDIV: Value out of range!" +#endif + + +/*---------------------------------------------------------------------------- + DEFINES + *----------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------- + Define clocks + *----------------------------------------------------------------------------*/ +#define __XTAL (12000000UL) /* Oscillator frequency */ +#define __SYS_OSC_CLK ( __XTAL) /* Main oscillator frequency */ +#define __IRC_OSC_CLK (12000000UL) /* Internal RC oscillator frequency */ + + +#define __FREQSEL ((WDTOSCCTRL_Val >> 5) & 0x0F) +#define __DIVSEL (((WDTOSCCTRL_Val & 0x1F) << 1) + 2) + +#if (CLOCK_SETUP) /* Clock Setup */ + #if (__FREQSEL == 0) + #define __WDT_OSC_CLK ( 0) /* undefined */ + #elif (__FREQSEL == 1) + #define __WDT_OSC_CLK ( 500000 / __DIVSEL) + #elif (__FREQSEL == 2) + #define __WDT_OSC_CLK ( 800000 / __DIVSEL) + #elif (__FREQSEL == 3) + #define __WDT_OSC_CLK (1100000 / __DIVSEL) + #elif (__FREQSEL == 4) + #define __WDT_OSC_CLK (1400000 / __DIVSEL) + #elif (__FREQSEL == 5) + #define __WDT_OSC_CLK (1600000 / __DIVSEL) + #elif (__FREQSEL == 6) + #define __WDT_OSC_CLK (1800000 / __DIVSEL) + #elif (__FREQSEL == 7) + #define __WDT_OSC_CLK (2000000 / __DIVSEL) + #elif (__FREQSEL == 8) + #define __WDT_OSC_CLK (2200000 / __DIVSEL) + #elif (__FREQSEL == 9) + #define __WDT_OSC_CLK (2400000 / __DIVSEL) + #elif (__FREQSEL == 10) + #define __WDT_OSC_CLK (2600000 / __DIVSEL) + #elif (__FREQSEL == 11) + #define __WDT_OSC_CLK (2700000 / __DIVSEL) + #elif (__FREQSEL == 12) + #define __WDT_OSC_CLK (2900000 / __DIVSEL) + #elif (__FREQSEL == 13) + #define __WDT_OSC_CLK (3100000 / __DIVSEL) + #elif (__FREQSEL == 14) + #define __WDT_OSC_CLK (3200000 / __DIVSEL) + #else + #define __WDT_OSC_CLK (3400000 / __DIVSEL) + #endif + + /* sys_pllclkin calculation */ + #if ((SYSPLLCLKSEL_Val & 0x03) == 0) + #define __SYS_PLLCLKIN (__IRC_OSC_CLK) + #elif ((SYSPLLCLKSEL_Val & 0x03) == 1) + #define __SYS_PLLCLKIN (__SYS_OSC_CLK) + #else + #define __SYS_PLLCLKIN (0) + #endif + + #define __SYS_PLLCLKOUT (__SYS_PLLCLKIN * ((SYSPLLCTRL_Val & 0x01F) + 1)) + + /* main clock calculation */ + #if ((MAINCLKSEL_Val & 0x03) == 0) + #define __MAIN_CLOCK (__IRC_OSC_CLK) + #elif ((MAINCLKSEL_Val & 0x03) == 1) + #define __MAIN_CLOCK (__SYS_PLLCLKIN) + #elif ((MAINCLKSEL_Val & 0x03) == 2) + #if (__FREQSEL == 0) + #error "MAINCLKSEL: WDT Oscillator selected but FREQSEL is undefined!" + #else + #define __MAIN_CLOCK (__WDT_OSC_CLK) + #endif + #elif ((MAINCLKSEL_Val & 0x03) == 3) + #define __MAIN_CLOCK (__SYS_PLLCLKOUT) + #else + #define __MAIN_CLOCK (0) + #endif + + #define __SYSTEM_CLOCK (__MAIN_CLOCK / SYSAHBCLKDIV_Val) + +#else + #define __SYSTEM_CLOCK (__IRC_OSC_CLK) +#endif // CLOCK_SETUP + + +/*---------------------------------------------------------------------------- + Clock Variable definitions + *----------------------------------------------------------------------------*/ +uint32_t SystemCoreClock = __SYSTEM_CLOCK;/*!< System Clock Frequency (Core Clock)*/ + + +/*---------------------------------------------------------------------------- + Clock functions + *----------------------------------------------------------------------------*/ +void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */ +{ + uint32_t wdt_osc = 0; + + /* Determine clock frequency according to clock register values */ + switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F) { + case 0: wdt_osc = 0; break; + case 1: wdt_osc = 500000; break; + case 2: wdt_osc = 800000; break; + case 3: wdt_osc = 1100000; break; + case 4: wdt_osc = 1400000; break; + case 5: wdt_osc = 1600000; break; + case 6: wdt_osc = 1800000; break; + case 7: wdt_osc = 2000000; break; + case 8: wdt_osc = 2200000; break; + case 9: wdt_osc = 2400000; break; + case 10: wdt_osc = 2600000; break; + case 11: wdt_osc = 2700000; break; + case 12: wdt_osc = 2900000; break; + case 13: wdt_osc = 3100000; break; + case 14: wdt_osc = 3200000; break; + case 15: wdt_osc = 3400000; break; + } + wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2; + + switch (LPC_SYSCON->MAINCLKSEL & 0x03) { + case 0: /* Internal RC oscillator */ + SystemCoreClock = __IRC_OSC_CLK; + break; + case 1: /* Input Clock to System PLL */ + switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { + case 0: /* Internal RC oscillator */ + SystemCoreClock = __IRC_OSC_CLK; + break; + case 1: /* System oscillator */ + SystemCoreClock = __SYS_OSC_CLK; + break; + case 2: /* Reserved */ + case 3: /* Reserved */ + SystemCoreClock = 0; + break; + } + break; + case 2: /* WDT Oscillator */ + SystemCoreClock = wdt_osc; + break; + case 3: /* System PLL Clock Out */ + switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) { + case 0: /* Internal RC oscillator */ + if (LPC_SYSCON->SYSPLLCTRL & 0x180) { + SystemCoreClock = __IRC_OSC_CLK; + } else { + SystemCoreClock = __IRC_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); + } + break; + case 1: /* System oscillator */ + if (LPC_SYSCON->SYSPLLCTRL & 0x180) { + SystemCoreClock = __SYS_OSC_CLK; + } else { + SystemCoreClock = __SYS_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1); + } + break; + case 2: /* Reserved */ + case 3: /* Reserved */ + SystemCoreClock = 0; + break; + } + break; + } + + SystemCoreClock /= LPC_SYSCON->SYSAHBCLKDIV; + +} + +/** + * Initialize the system + * + * @param none + * @return none + * + * @brief Setup the microcontroller system. + * Initialize the System. + */ +void SystemInit (void) { + volatile uint32_t i; + +#if (CLOCK_SETUP) /* Clock Setup */ + +#if ((SYSPLLCLKSEL_Val & 0x03) == 1) + LPC_SYSCON->PDRUNCFG &= ~(1 << 5); /* Power-up System Osc */ + LPC_SYSCON->SYSOSCCTRL = SYSOSCCTRL_Val; + for (i = 0; i < 200; i++) __NOP(); +#endif + + LPC_SYSCON->SYSPLLCLKSEL = SYSPLLCLKSEL_Val; /* Select PLL Input */ + LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update Clock Source */ + LPC_SYSCON->SYSPLLCLKUEN = 0x00; /* Toggle Update Register */ + LPC_SYSCON->SYSPLLCLKUEN = 0x01; + while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); /* Wait Until Updated */ +#if ((MAINCLKSEL_Val & 0x03) == 3) /* Main Clock is PLL Out */ + LPC_SYSCON->SYSPLLCTRL = SYSPLLCTRL_Val; + LPC_SYSCON->PDRUNCFG &= ~(1 << 7); /* Power-up SYSPLL */ + while (!(LPC_SYSCON->SYSPLLSTAT & 0x01)); /* Wait Until PLL Locked */ +#endif + +#if (((MAINCLKSEL_Val & 0x03) == 2) ) + LPC_SYSCON->WDTOSCCTRL = WDTOSCCTRL_Val; + LPC_SYSCON->PDRUNCFG &= ~(1 << 6); /* Power-up WDT Clock */ + for (i = 0; i < 200; i++) __NOP(); +#endif + + LPC_SYSCON->MAINCLKSEL = MAINCLKSEL_Val; /* Select PLL Clock Output */ + LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */ + LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */ + LPC_SYSCON->MAINCLKUEN = 0x01; + while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */ + + LPC_SYSCON->SYSAHBCLKDIV = SYSAHBCLKDIV_Val; +#endif + /* System clock to the IOCON needs to be enabled or + most of the I/O related peripherals won't work. */ + LPC_SYSCON->SYSAHBCLKCTRL |= (1<<16); +} +#endif /* __ARMEL__ */ diff --git a/mbed-system_LPC11xx.h b/mbed-system_LPC11xx.h new file mode 100644 index 0000000..9326539 --- /dev/null +++ b/mbed-system_LPC11xx.h @@ -0,0 +1,76 @@ +/**************************************************************************//** + * @file system_LPC11xx.h + * @brief CMSIS Cortex-M0 Device Peripheral Access Layer Header File + * for the NXP LPC11xx/LPC11Cxx Device Series + * @version V1.10 + * @date 24. November 2010 + * + * @note + * Copyright (C) 2009-2010 ARM Limited. All rights reserved. + * + * @par + * ARM Limited (ARM) is supplying this software for use with Cortex-M + * processor based microcontrollers. This file can be freely distributed + * within development tools that are supporting such ARM based processors. + * + * @par + * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED + * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. + * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR + * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. + * + ******************************************************************************/ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/system_LPC11xx.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. + + - Prefixed names of #include files with mbed- to match the names of the + copies in the Teacup repo. +*/ + + +#ifndef __SYSTEM_LPC11xx_H +#define __SYSTEM_LPC11xx_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ + + +/** + * Initialize the system + * + * @param none + * @return none + * + * @brief Setup the microcontroller system. + * Initialize the System and update the SystemCoreClock variable. + */ +extern void SystemInit (void); + +/** + * Update SystemCoreClock variable + * + * @param none + * @return none + * + * @brief Updates the SystemCoreClock with current core Clock + * retrieved from cpu registers. + */ +extern void SystemCoreClockUpdate (void); + +#ifdef __cplusplus +} +#endif + +#endif /* __SYSTEM_LPC11xx_H */ diff --git a/mbed-toolchain.h b/mbed-toolchain.h new file mode 100644 index 0000000..1740cbb --- /dev/null +++ b/mbed-toolchain.h @@ -0,0 +1,44 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + Notes for Teacup: + + Copied from $(MBED)/libraries/mbed/api/toolchain.h. + + Used only to get things running quickly. Without serial it's almost + impossible to see wether code changes work. Should go away soon, because + all this MBED stuff is too bloated for Teacup's purposes. +*/ +#ifndef MBED_TOOLCHAIN_H +#define MBED_TOOLCHAIN_H + +#if defined(TOOLCHAIN_ARM) +#include +#endif + +#ifndef FILEHANDLE +typedef int FILEHANDLE; +#endif + +#if defined (__ICCARM__) +# define WEAK __weak +# define PACKED __packed +#else +# define WEAK __attribute__((weak)) +# define PACKED __attribute__((packed)) +#endif + +#endif diff --git a/mendel.c b/mendel.c index 77c195a..dff3c72 100644 --- a/mendel.c +++ b/mendel.c @@ -209,10 +209,12 @@ void init(void) { #ifndef __ARMEL_NOTYET__ // set up watchdog wd_init(); + #endif /* __ARMEL_NOTYET__ */ // set up serial serial_init(); + #ifndef __ARMEL_NOTYET__ // set up G-code parsing gcode_init(); diff --git a/serial-arm.c b/serial-arm.c index c9f4e66..069ab43 100644 --- a/serial-arm.c +++ b/serial-arm.c @@ -8,30 +8,40 @@ #if defined TEACUP_C_INCLUDE && defined __ARMEL__ #include "arduino.h" +#include "mbed-serial_api.h" +serial_t serial_line; + /** Initialise serial subsystem. Set up baud generator and interrupts, clear buffers. */ void serial_init() { + mbed_serial_init(&serial_line, USBTX, USBRX); + mbed_serial_baud(&serial_line, 115200); + mbed_serial_format(&serial_line, 8, ParityNone, 1); } -/** Check how many characters can be read. +/** Check wether characters can be read. + + Other than the AVR implementation this returns not the number of characters + in the line, but only wether there is at least one or not. */ uint8_t serial_rxchars(void) { - return 0; + return mbed_serial_readable(&serial_line); } /** Read one character. */ uint8_t serial_popchar(void) { - return 0; + return mbed_serial_getc(&serial_line); } /** Send one character. */ void serial_writechar(uint8_t data) { + mbed_serial_putc(&serial_line, data); } #endif /* defined TEACUP_C_INCLUDE && defined __ARMEL__ */