float trig LPC2148

my setup is LPC2148

gcc401

newlib116

I built the toolchain with soft-float, etc.

I can compile and link my test code. I can download onto the lpc2148. It will work until I make a call to a trig function (like sin, atan, etc.) It will allow basic float ops. I tested by dividing the double 1.5 by the double 2.5, multiplying by 100 and casting to int and then outputting. That all works fine. When I call the sin() function, the LPC just stops.

When I linked my code, I specified the full path to /usr/local/arm/arm-elf/lib/libm.a (and libc and libg).

It has to be simple something I’m missing.

Are you linking with -lm?

Leon

yes, I have -lm -lc -lgcc

I’ve also tried

using the full paths to the arm-elf, thumb, and interwork versions

like this:

in my arm-elf-gcc link step /usr/loca/arm/arm-elf/lib/libm.a

or

/usr/local/arm/arm-elf/lib/thumb/libm.a

or

/usr/local/arm/arm-elf/lib/interwork/libm.a

The compile seems to work. The linker seems to work. (for arm-elf, thumb, and interwork).

The problem occurs during the execution on the lpc2148.

If I have the following code, the device does not halt.

main() {

float x = 0.1f;

float y = 0.2f;

float z = x/y;

}

If I have the following code, the device halts on reaching the trig function

main() {

float x = 3.14f;

float y = sin(x);

}

Can someone post a link to an OSX toolchain package that works with math functions in arm-elf, thumb, and interwork mode on the LPC2148? I would try that - I’ve built the toolchain like 1million times in a week and I can’t get the correct setup.

When I use a math function, the generated files are much larger. I am wondering if there is issues with my stack size?

main.elf :

section size addr

.text 11316 0

.data 360 1073741824

.bss 80 1073742184

.stack 9216 1073742336

.comment 288 0

.debug_aranges 848 0

.debug_pubnames 869 0

.debug_info 8175 0

.debug_abbrev 3725 0

.debug_line 5245 0

.debug_frame 1244 0

.debug_str 1828 0

.debug_loc 7372 0

.debug_ranges 80 0

Total 50646

and more data

from an LST file, I have this:

58:adctest_WinARM.c **** f0 = (int)(1000.0f * sin(3.14f));^M

73 .loc 1 58 0

74 0044 2748 ldr r0, .L12+20

75 0046 2849 ldr r1, .L12+24

76 0048 FFF7FEFF bl sin

77 004c 274A ldr r2, .L12+28

78 004e 284B ldr r3, .L12+32

79 0050 FFF7FEFF bl __muldf3

80 0054 FFF7FEFF bl __fixdfsi

81 0058 0390 str r0, [sp, #12]

82 .LVL1:

83 005a 2648 ldr r0, .L12+36

84 005c FF23 mov r3, #255

85 005e 8046 mov r8, r0

86 0060 2548 ldr r0, .L12+40

87 0062 9A46 mov sl, r3

88 .LVL2:

89 0064 254B ldr r3, .L12+44

90 0066 0290 str r0, [sp, #8]

91 0068 9946 mov r9, r3

92 .LVL3:

93 .L10:

Some math library internally use malloc. Are you redefining the _sbrk_r syscall?

I tested and sin() works on my LPC2138.

I am not redefining the _sbrk_r syscall. Should I be? Can I upload my source package or should I paste each file into a post?

I’m going to attach all my codes from my test. Would appreciate pointers to my errors. all h,c,s source code and Makefile

If the line in main.c which calls the trig function is removed, the code works somewhat.

startup.h

void Initialize(void);

startup.c

#include "startup.h"

#define MAMCR           *(volatile unsigned int *)0xE01FC000
#define MAMTIM          *(volatile unsigned int *)0xE01FC004

#define PLLCON          *(volatile unsigned int *)0xE01FC080
#define PLLCFG          *(volatile unsigned int *)0xE01FC084
#define PLLSTAT         *(volatile unsigned int *)0xE01FC088
#define PLLFEED         *(volatile unsigned int *)0xE01FC08C

#define PLOCK 0x400

#define VPBDIV          *(volatile unsigned int *)0xE01FC100

void IRQ_Routine(void) __attribute__ ((interrupt("IRQ")));
void FIQ_Routine(void) __attribute__ ((interrupt("FIQ")));
void SWI_Routine(void) __attribute__ ((interrupt("SWI")));
void UNDEF_Routine(void) __attribute__ ((interrupt("UNDEF")));

void IRQ_Routine(void) { while (1); }
void FIQ_Routine(void) { while (1); }
void SWI_Routine(void) { while (1); }
void UNDEF_Routine(void) { while (1); }


static void feed(void)
{
    PLLFEED = 0xAA;
    PLLFEED = 0x55;
} 

void Initialize(void)
{
    PLLCFG = 0x24;
    feed();

    PLLCON = 0x1;
    feed();

    while (!(PLLSTAT & PLOCK));

    PLLCON = 0x3;
    feed();

    MAMTIM = 0x3;
    MAMCR = 0x2;

    VPBDIV = 0x1;
}

crt.s

.set  UND_STACK_SIZE, 0x00000040
.set  ABT_STACK_SIZE, 0x00000040
.set  FIQ_STACK_SIZE, 0x00000040
.set  IRQ_STACK_SIZE, 0X00000040
.set  SVC_STACK_SIZE, 0x00000400

.set  MODE_USR, 0x10
.set  MODE_FIQ, 0x11
.set  MODE_IRQ, 0x12
.set  MODE_SVC, 0x13
.set  MODE_ABT, 0x17
.set  MODE_UND, 0x1B
.set  MODE_SYS, 0x1F

.set  I_BIT, 0x80
.set  F_BIT, 0x40

.text
.arm

.global Reset_Handler
.global _startup
.func   _startup

_startup:

_vectors:       ldr     PC, Reset_Addr
                ldr     PC, Undef_Addr
                ldr     PC, SWI_Addr
                ldr     PC, PAbt_Addr
                ldr     PC, DAbt_Addr
                nop             
                ldr     PC, [PC,#-0xFF0]
                ldr     PC, FIQ_Addr

Reset_Addr:     .word   Reset_Handler           
Undef_Addr:     .word   UNDEF_Routine           
SWI_Addr:       .word   SWI_Routine     
PAbt_Addr:      .word   UNDEF_Routine           
DAbt_Addr:      .word   UNDEF_Routine           
IRQ_Addr:       .word   IRQ_Routine             
FIQ_Addr:       .word   FIQ_Routine             
                .word   0       

Reset_Handler:
                        ldr   r0, =_stack_end
                        msr   CPSR_c, #MODE_UND|I_BIT|F_BIT     
                        mov   sp, r0
                        sub   r0, r0, #UND_STACK_SIZE
                        msr   CPSR_c, #MODE_ABT|I_BIT|F_BIT     
                        mov   sp, r0
                        sub   r0, r0, #ABT_STACK_SIZE
                        msr   CPSR_c, #MODE_FIQ|I_BIT|F_BIT     
                        mov   sp, r0
                        sub   r0, r0, #FIQ_STACK_SIZE
                        msr   CPSR_c, #MODE_IRQ|I_BIT|F_BIT     
                        mov   sp, r0
                        sub   r0, r0, #IRQ_STACK_SIZE
                        msr   CPSR_c, #MODE_SVC|I_BIT|F_BIT     
                        mov   sp, r0
                        sub   r0, r0, #SVC_STACK_SIZE
                        msr   CPSR_c, #MODE_SYS|I_BIT|F_BIT     
                        mov   sp, r0

                ldr     R1, =_etext
                ldr     R2, =_data
                ldr     R3, =_edata
1:                      cmp     R2, R3
                ldrlo   R0, [R1], #4
                strlo   R0, [R2], #4
                blo     1b

                mov     R0, #0
                ldr     R1, =_bss_start
                ldr     R2, =_bss_end
2:                              cmp     R1, R2
                strlo   R0, [R1], #4
                blo     2b

                b       main

.endfunc
.end

console.h

void ConsoleInit(int iDivider);
int putchar(int c);
int puts(char *s);
void rprintf ( char const *format, ... );

#define SCRATCH 12      

#define USE_LONG        
#define USE_STRING     
#define USE_CHAR        
#define USE_INTEGER     
#define USE_HEX         
#define USE_UPPERHEX    
#ifndef USE_HEX
#undef USE_UPPERHEX    
#endif
#define USE_UPPER
                    
#define PADDING    

#define BAUD_RATE 9600

console.c

/*
        Simple console input/output, over serial port #0

        Partially copied from Jim Lynch's tutorial
*/
#include <stdarg.h>

#include "lpc214x.h"
#include "console.h"

/* Initialize Serial Interface       */
void ConsoleInit(int iDivider)
{
    PINSEL0 = (PINSEL0 & ~0x0000000F) | 0x00000005;     /* Enable RxD0 and TxD0              */
    U0LCR = 0x83;               /* 8 bits, no Parity, 1 Stop bit     */
    U0DLL = iDivider & 0xFF;    /* set divider / baud rate */
    U0DLM = iDivider >> 8;
    U0LCR = 0x03;               /* DLAB = 0                          */

    // enable FIFO
    U0FCR = 1;
}

/* Write character to Serial Port    */
int putchar(int ch)
{
    if (ch == '\n') {
        while (!(U0LSR & 0x20));
        U0THR = '\r';
    }
    while (!(U0LSR & 0x20));
    U0THR = ch;
    return ch;
}
int getchar(void)
{                               /* Read character from Serial Port   */
    while (!(U0LSR & 0x01));
    return (U0RBR);
}
int puts(char *s)
{
    while (*s) {
        putchar(*s++);
    }
    putchar('\n');
    return 1;
}

static void myputchar(unsigned char c)
{
        if(c == '\n') putchar('\r');
        putchar(c);
}

void rprintf(char const *format, ...)
{
    unsigned char scratch[SCRATCH];
    unsigned char format_flag;
    unsigned short base;
    unsigned char *ptr;
    unsigned char issigned=0;
    va_list ap;
    
#ifdef USE_LONG
    // #warning "use long"
    unsigned char islong=0;
    unsigned long u_val=0;
    long s_val=0;
#else
    unsigned int u_val=0;
    int s_val=0;
#endif
    
    unsigned char fill;
    unsigned char width;
    
//    ConsoleInit(60000000 / (16 * BAUD_RATE));

    va_start (ap, format);
    for (;;){
        while ((format_flag = *(format++)) != '%'){      // Until '%' or '\0' 
            if (!format_flag){va_end (ap); return;}
            myputchar(format_flag);
        }
        
        issigned=0; //default unsigned
        base = 10;
        
        format_flag = *format++; //get char after '%'
        
#ifdef PADDING
        width=0; //no formatting
        fill=0;  //no formatting
        if(format_flag=='0' || format_flag==' ') //SPACE or ZERO padding  ?
        {
            fill=format_flag;
            format_flag = *format++; //get char after padding char
            if(format_flag>='0' && format_flag<='9')
            {
                width=format_flag-'0';
                format_flag = *format++; //get char after width char
            }
        }
#endif
        
#ifdef USE_LONG
        islong=0; //default int value
#ifdef USE_UPPER
        if(format_flag=='l' || format_flag=='L') //Long value 
#else
            if(format_flag=='l') //Long value 
#endif
            {
                islong=1;
                format_flag = *format++; //get char after 'l' or 'L'
            }
#endif
                switch (format_flag)
                {
#ifdef USE_CHAR
                    case 'c':
#ifdef USE_UPPER
                    case 'C':
#endif
                        format_flag = va_arg(ap,int);
                        // no break -> run into default
#endif
                        
                    default:
                        myputchar(format_flag);
                        continue;
                        
#ifdef USE_STRING
#ifdef USE_UPPER
                    case 'S':
#endif
                    case 's':
                        ptr = (unsigned char*)va_arg(ap,char *);
                        while(*ptr) { myputchar(*ptr); ptr++; }
                            continue;
#endif
                        
#ifdef USE_OCTAL
                    case 'o':
#ifdef USE_UPPER
                    case 'O':
#endif
                        base = 8;
                        myputchar('0');
                        goto CONVERSION_LOOP;
#endif
                        
#ifdef USE_INTEGER //don't use %i, is same as %d
                    case 'i':
#ifdef USE_UPPER
                    case 'I':
#endif
#endif
                    case 'd':
#ifdef USE_UPPER
                    case 'D':
#endif
                        issigned=1;
                        // no break -> run into next case
                    case 'u':
#ifdef USE_UPPER
                    case 'U':
#endif
                        
                        //don't insert some case below this if USE_HEX is undefined !
                        //or put       goto CONVERSION_LOOP;  before next case.
#ifdef USE_HEX
                        goto CONVERSION_LOOP;
                    case 'x':
#ifdef USE_UPPER
                    case 'X':
#endif
                        base = 16;
#endif
                        
                        CONVERSION_LOOP:
                        
                        if(issigned) //Signed types
                        {
#ifdef USE_LONG
                            if(islong) { s_val = va_arg(ap,long); }
                            else { s_val = va_arg(ap,int); }
#else
                            s_val = va_arg(ap,int);
#endif
                            
                            if(s_val < 0) //Value negativ ?
                            {
                                s_val = - s_val; //Make it positiv
                                myputchar('-');    //Output sign
                            }
                            
                            u_val = (unsigned long)s_val;
                        }
                        else //Unsigned types
                        {
#ifdef USE_LONG
                            if(islong) { u_val = va_arg(ap,unsigned long); }
                            else { u_val = va_arg(ap,unsigned int); }
#else
                            u_val = va_arg(ap,unsigned int);
#endif
                        }
                        
                        ptr = scratch + SCRATCH;
                        *--ptr = 0;
                        do
                        {
                            char ch = u_val % base + '0';
#ifdef USE_HEX
                            if (ch > '9')
                            {
                                ch += 'a' - '9' - 1;
#ifdef USE_UPPERHEX
                                ch-=0x20;
#endif
                            }
#endif          
                            *--ptr = ch;
                            u_val /= base;
                            
#ifdef PADDING
                            if(width) width--; //calculate number of padding chars
#endif
                        } while (u_val);
                            
#ifdef PADDING
                            while(width--) *--ptr = fill; //insert padding chars                      
#endif
                                
                                while(*ptr) { myputchar(*ptr); ptr++; }
                }
    }
}

_sbrk_r.c

#include <reent.h>

extern char end[];             
                                

static char *heap_ptr;  

void * _sbrk_r(
    struct _reent *_s_r,
    ptrdiff_t nbytes)
{
 char  *base;           

 if (!heap_ptr){        
    heap_ptr = end;
    }
 base = heap_ptr;       
 heap_ptr += nbytes;    

 return base;   
}

main.c

#include <math.h>
#include "lpc214x.h"
#include "startup.h"
#include "console.h"

int main(void)
{
    int accel_x, accel_y, accel_z;
    int gyro_pitch, gyro_roll;
    
    unsigned int i;

    float f = sin(1.25f);
    
    Initialize();
    ConsoleInit(60000000 / (16 * BAUD_RATE));
    
    rprintf("init done--%d--\n", BAUD_RATE);
    
    IODIR0 |= 1 << 10;          // P0.10 is an output
    IODIR0 |= 1 << 11;          // P0.10 is an output
    IOSET0 = 1 << 10;           //LED off
    IOSET0 = 1 << 11;           //LED off

    while (1) {
        for (i = 0; i < 1000000; i++);
        IOSET0 = 1 << 10;       //LED off
        IOCLR0 = 1 << 11;       //LED on
        rprintf("led1: off  led2: on\n");
    
        for (i = 0; i < 1000000; i++);
        IOCLR0 = 1 << 10;       //LED on
        IOSET0 = 1 << 11;       //LED off
        rprintf("led1: on   led2: off\n");
    
    }
}

Makefile

preferences for cross development

TOOLCHAIN=arm-elf-
CC=$(TOOLCHAIN)gcc
AS=$(TOOLCHAIN)as
LD=$(TOOLCHAIN)ld
OBJCOPY=$(TOOLCHAIN)objcopy
CC=$(TOOLCHAIN)gcc
AS=$(TOOLCHAIN)as
LD=$(TOOLCHAIN)ld
OBJCOPY=$(TOOLCHAIN)objcopy

#flags

CFLAGS = -mcpu=arm7tdmi -g -I. -gdwarf-2 -MD -MP

ASFLAGS =

BASENAME = main

ELFFILE = $(BASENAME).elf
BINARY = $(BASENAME).bin
SREC = $(BASENAME).srec
HEX = $(BASENAME).hex

LSCRIPT = lpc2148-rom.ld


#target
TARGETS = $(ELFFILE) $(BINARY) $(SREC) $(HEX)

OBJS = crt.o startup.o console.o _sbrk_r.o main.o

all:$(TARGETS)


$(ELFFILE): $(OBJS) Makefile
        $(CC) -o $(ELFFILE) -mcpu=arm7tdmi-s  -I. -gdwarf-2 \
        -DROM_RUN -DVECTORS_IN_RAM -Os -Wall -Wcast-align -Wimplicit -Wpointer-arith \
        -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wcast-qual -MD -MP \
        -nostartfiles -Wl,-Map=$(BASENAME).map,--cref -lgcc $(OBJS) -L /usr/local/arm/arm-elf/lib -lm -T $(LSCRIPT)



$(BINARY): $(ELFFILE)
        $(OBJCOPY) -O binary -S $(ELFFILE) $(BINARY)


$(SREC): $(ELFFILE)
        $(OBJCOPY) -O srec -S $(ELFFILE) $(SREC)

$(HEX): $(ELFFILE)
        $(OBJCOPY) -O ihex -S $(ELFFILE) $(HEX)


upload:
        lpc21isp  $(HEX) /dev/ttyUSB0 115200 12000

clean:
        rm -f *.o $(TARGETS)

lpc214x.h

#ifndef __LPC214x_H
#define __LPC214x_H

#define FOSC    12000000UL
#define FCCLK   (FOSC * 5)
#define FCCO    (FCCLK * 4)
#define FPCLK   (FCCLK / 4) * 1


/* Vectored Interrupt Controller (VIC) */
#define VICIRQStatus    (*((volatile unsigned long *) 0xFFFFF000))
#define VICFIQStatus    (*((volatile unsigned long *) 0xFFFFF004))
#define VICRawIntr      (*((volatile unsigned long *) 0xFFFFF008))
#define VICIntSelect    (*((volatile unsigned long *) 0xFFFFF00C))
#define VICIntEnable    (*((volatile unsigned long *) 0xFFFFF010))
#define VICIntEnClr     (*((volatile unsigned long *) 0xFFFFF014))
#define VICSoftInt      (*((volatile unsigned long *) 0xFFFFF018))
#define VICSoftIntClr   (*((volatile unsigned long *) 0xFFFFF01C))
#define VICProtection   (*((volatile unsigned long *) 0xFFFFF020))
#define VICVectAddr     (*((volatile unsigned long *) 0xFFFFF030))
#define VICDefVectAddr  (*((volatile unsigned long *) 0xFFFFF034))
#define VICVectAddr0    (*((volatile unsigned long *) 0xFFFFF100))
#define VICVectAddr1    (*((volatile unsigned long *) 0xFFFFF104))
#define VICVectAddr2    (*((volatile unsigned long *) 0xFFFFF108))
#define VICVectAddr3    (*((volatile unsigned long *) 0xFFFFF10C))
#define VICVectAddr4    (*((volatile unsigned long *) 0xFFFFF110))
#define VICVectAddr5    (*((volatile unsigned long *) 0xFFFFF114))
#define VICVectAddr6    (*((volatile unsigned long *) 0xFFFFF118))
#define VICVectAddr7    (*((volatile unsigned long *) 0xFFFFF11C))
#define VICVectAddr8    (*((volatile unsigned long *) 0xFFFFF120))
#define VICVectAddr9    (*((volatile unsigned long *) 0xFFFFF124))
#define VICVectAddr10   (*((volatile unsigned long *) 0xFFFFF128))
#define VICVectAddr11   (*((volatile unsigned long *) 0xFFFFF12C))
#define VICVectAddr12   (*((volatile unsigned long *) 0xFFFFF130))
#define VICVectAddr13   (*((volatile unsigned long *) 0xFFFFF134))
#define VICVectAddr14   (*((volatile unsigned long *) 0xFFFFF138))
#define VICVectAddr15   (*((volatile unsigned long *) 0xFFFFF13C))
#define VICVectCntl0    (*((volatile unsigned long *) 0xFFFFF200))
#define VICVectCntl1    (*((volatile unsigned long *) 0xFFFFF204))
#define VICVectCntl2    (*((volatile unsigned long *) 0xFFFFF208))
#define VICVectCntl3    (*((volatile unsigned long *) 0xFFFFF20C))
#define VICVectCntl4    (*((volatile unsigned long *) 0xFFFFF210))
#define VICVectCntl5    (*((volatile unsigned long *) 0xFFFFF214))
#define VICVectCntl6    (*((volatile unsigned long *) 0xFFFFF218))
#define VICVectCntl7    (*((volatile unsigned long *) 0xFFFFF21C))
#define VICVectCntl8    (*((volatile unsigned long *) 0xFFFFF220))
#define VICVectCntl9    (*((volatile unsigned long *) 0xFFFFF224))
#define VICVectCntl10   (*((volatile unsigned long *) 0xFFFFF228))
#define VICVectCntl11   (*((volatile unsigned long *) 0xFFFFF22C))
#define VICVectCntl12   (*((volatile unsigned long *) 0xFFFFF230))
#define VICVectCntl13   (*((volatile unsigned long *) 0xFFFFF234))
#define VICVectCntl14   (*((volatile unsigned long *) 0xFFFFF238))
#define VICVectCntl15   (*((volatile unsigned long *) 0xFFFFF23C))

/* Pin Connect Block */
#define PINSEL0         (*((volatile unsigned long *) 0xE002C000))
#define PINSEL1         (*((volatile unsigned long *) 0xE002C004))
#define PINSEL2         (*((volatile unsigned long *) 0xE002C014))

/* General Purpose Input/Output (GPIO) */
#define IOPIN0          (*((volatile unsigned long *) 0xE0028000))
#define IOSET0          (*((volatile unsigned long *) 0xE0028004))
#define IODIR0          (*((volatile unsigned long *) 0xE0028008))
#define IOCLR0          (*((volatile unsigned long *) 0xE002800C))
#define IOPIN1          (*((volatile unsigned long *) 0xE0028010))
#define IOSET1          (*((volatile unsigned long *) 0xE0028014))
#define IODIR1          (*((volatile unsigned long *) 0xE0028018))
#define IOCLR1          (*((volatile unsigned long *) 0xE002801C))
#define IO0PIN          (*((volatile unsigned long *) 0xE0028000))
#define IO0SET          (*((volatile unsigned long *) 0xE0028004))
#define IO0DIR          (*((volatile unsigned long *) 0xE0028008))
#define IO0CLR          (*((volatile unsigned long *) 0xE002800C))
#define IO1PIN          (*((volatile unsigned long *) 0xE0028010))
#define IO1SET          (*((volatile unsigned long *) 0xE0028014))
#define IO1DIR          (*((volatile unsigned long *) 0xE0028018))
#define IO1CLR          (*((volatile unsigned long *) 0xE002801C))
#define FIO0DIR         (*((volatile unsigned long *) 0x3FFFC000))
#define FIO0MASK        (*((volatile unsigned long *) 0x3FFFC010))
#define FIO0PIN         (*((volatile unsigned long *) 0x3FFFC014))
#define FIO0SET         (*((volatile unsigned long *) 0x3FFFC018))
#define FIO0CLR         (*((volatile unsigned long *) 0x3FFFC01C))
#define FIO1DIR         (*((volatile unsigned long *) 0x3FFFC020))
#define FIO1MASK        (*((volatile unsigned long *) 0x3FFFC030))
#define FIO1PIN         (*((volatile unsigned long *) 0x3FFFC034))
#define FIO1SET         (*((volatile unsigned long *) 0x3FFFC038))
#define FIO1CLR         (*((volatile unsigned long *) 0x3FFFC03C))

/* Memory Accelerator Module (MAM) */
#define MAMCR           (*((volatile unsigned char *) 0xE01FC000))
#define MAMTIM          (*((volatile unsigned char *) 0xE01FC004))
#define MEMMAP          (*((volatile unsigned char *) 0xE01FC040))

/* Phase Locked Loop 0 (PLL0) */
#define PLL0CON         (*((volatile unsigned char *) 0xE01FC080))
#define PLL0CFG         (*((volatile unsigned char *) 0xE01FC084))
#define PLL0STAT        (*((volatile unsigned short*) 0xE01FC088))
#define PLL0FEED        (*((volatile unsigned char *) 0xE01FC08C))

/* Phase Locked Loop 1 (PLL1) */
#define PLL1CON         (*((volatile unsigned char *) 0xE01FC0A0))
#define PLL1CFG         (*((volatile unsigned char *) 0xE01FC0A4))
#define PLL1STAT        (*((volatile unsigned short*) 0xE01FC0A8))
#define PLL1FEED        (*((volatile unsigned char *) 0xE01FC0AC))

/* VPB Divider */
#define VPBDIV          (*((volatile unsigned char *) 0xE01FC100))

/* Power Control */
#define PCON            (*((volatile unsigned char *) 0xE01FC0C0))
#define PCONP           (*((volatile unsigned long *) 0xE01FC0C4))

/* External Interrupts */
#define EXTINT          (*((volatile unsigned char *) 0xE01FC140))
#define INTWAKE         (*((volatile unsigned short*) 0xE01FC144))
#define EXTMODE         (*((volatile unsigned char *) 0xE01FC148))
#define EXTPOLAR        (*((volatile unsigned char *) 0xE01FC14C))

/* Reset */
#define RSID            (*((volatile unsigned char *) 0xE01FC180))

/* Code Security / Debugging */
#define CSPR            (*((volatile unsigned char *) 0xE01FC184))

/* System Control Miscellaneous */
#define SCS             (*((volatile unsigned long *) 0xE01FC1A0))

/* Timer 0 */
#define T0IR            (*((volatile unsigned long *) 0xE0004000))
#define T0TCR           (*((volatile unsigned long *) 0xE0004004))
#define T0TC            (*((volatile unsigned long *) 0xE0004008))
#define T0PR            (*((volatile unsigned long *) 0xE000400C))
#define T0PC            (*((volatile unsigned long *) 0xE0004010))
#define T0MCR           (*((volatile unsigned long *) 0xE0004014))
#define T0MR0           (*((volatile unsigned long *) 0xE0004018))
#define T0MR1           (*((volatile unsigned long *) 0xE000401C))
#define T0MR2           (*((volatile unsigned long *) 0xE0004020))
#define T0MR3           (*((volatile unsigned long *) 0xE0004024))
#define T0CCR           (*((volatile unsigned long *) 0xE0004028))
#define T0CR0           (*((volatile unsigned long *) 0xE000402C))
#define T0CR1           (*((volatile unsigned long *) 0xE0004030))
#define T0CR2           (*((volatile unsigned long *) 0xE0004034))
#define T0CR3           (*((volatile unsigned long *) 0xE0004038))
#define T0EMR           (*((volatile unsigned long *) 0xE000403C))
#define T0CTCR          (*((volatile unsigned long *) 0xE0004070))

/* Timer 1 */
#define T1IR            (*((volatile unsigned long *) 0xE0008000))
#define T1TCR           (*((volatile unsigned long *) 0xE0008004))
#define T1TC            (*((volatile unsigned long *) 0xE0008008))
#define T1PR            (*((volatile unsigned long *) 0xE000800C))
#define T1PC            (*((volatile unsigned long *) 0xE0008010))
#define T1MCR           (*((volatile unsigned long *) 0xE0008014))
#define T1MR0           (*((volatile unsigned long *) 0xE0008018))
#define T1MR1           (*((volatile unsigned long *) 0xE000801C))
#define T1MR2           (*((volatile unsigned long *) 0xE0008020))
#define T1MR3           (*((volatile unsigned long *) 0xE0008024))
#define T1CCR           (*((volatile unsigned long *) 0xE0008028))
#define T1CR0           (*((volatile unsigned long *) 0xE000802C))
#define T1CR1           (*((volatile unsigned long *) 0xE0008030))
#define T1CR2           (*((volatile unsigned long *) 0xE0008034))
#define T1CR3           (*((volatile unsigned long *) 0xE0008038))
#define T1EMR           (*((volatile unsigned long *) 0xE000803C))
#define T1CTCR          (*((volatile unsigned long *) 0xE0008070))

/* Pulse Width Modulator (PWM) */
#define PWMIR           (*((volatile unsigned long *) 0xE0014000))
#define PWMTCR          (*((volatile unsigned long *) 0xE0014004))
#define PWMTC           (*((volatile unsigned long *) 0xE0014008))
#define PWMPR           (*((volatile unsigned long *) 0xE001400C))
#define PWMPC           (*((volatile unsigned long *) 0xE0014010))
#define PWMMCR          (*((volatile unsigned long *) 0xE0014014))
#define PWMMR0          (*((volatile unsigned long *) 0xE0014018))
#define PWMMR1          (*((volatile unsigned long *) 0xE001401C))
#define PWMMR2          (*((volatile unsigned long *) 0xE0014020))
#define PWMMR3          (*((volatile unsigned long *) 0xE0014024))
#define PWMMR4          (*((volatile unsigned long *) 0xE0014040))
#define PWMMR5          (*((volatile unsigned long *) 0xE0014044))
#define PWMMR6          (*((volatile unsigned long *) 0xE0014048))
#define PWMPCR          (*((volatile unsigned long *) 0xE001404C))
#define PWMLER          (*((volatile unsigned long *) 0xE0014050))

/* Universal Asynchronous Receiver Transmitter 0 (UART0) */
#define U0RBR           (*((volatile unsigned char *) 0xE000C000))
#define U0THR           (*((volatile unsigned char *) 0xE000C000))
#define U0IER           (*((volatile unsigned long *) 0xE000C004))
#define U0IIR           (*((volatile unsigned long *) 0xE000C008))
#define U0FCR           (*((volatile unsigned char *) 0xE000C008))
#define U0LCR           (*((volatile unsigned char *) 0xE000C00C))
#define U0MCR           (*((volatile unsigned char *) 0xE000C010))
#define U0LSR           (*((volatile unsigned char *) 0xE000C014))
#define U0MSR           (*((volatile unsigned char *) 0xE000C018))
#define U0SCR           (*((volatile unsigned char *) 0xE000C01C))
#define U0DLL           (*((volatile unsigned char *) 0xE000C000))
#define U0DLM           (*((volatile unsigned char *) 0xE000C004))
#define U0ACR           (*((volatile unsigned long *) 0xE000C020))
#define U0FDR           (*((volatile unsigned long *) 0xE000C028))
#define U0TER           (*((volatile unsigned char *) 0xE000C030))

/* Universal Asynchronous Receiver Transmitter 1 (UART1) */
#define U1RBR           (*((volatile unsigned char *) 0xE0010000))
#define U1THR           (*((volatile unsigned char *) 0xE0010000))
#define U1IER           (*((volatile unsigned long *) 0xE0010004))
#define U1IIR           (*((volatile unsigned long *) 0xE0010008))
#define U1FCR           (*((volatile unsigned char *) 0xE0010008))
#define U1LCR           (*((volatile unsigned char *) 0xE001000C))
#define U1MCR           (*((volatile unsigned char *) 0xE0010010))
#define U1LSR           (*((volatile unsigned char *) 0xE0010014))
#define U1MSR           (*((volatile unsigned char *) 0xE0010018))
#define U1SCR           (*((volatile unsigned char *) 0xE001001C))
#define U1DLL           (*((volatile unsigned char *) 0xE0010000))
#define U1DLM           (*((volatile unsigned char *) 0xE0010004))
#define U1ACR           (*((volatile unsigned long *) 0xE0010020))
#define U1FDR           (*((volatile unsigned long *) 0xE0010028))
#define U1TER           (*((volatile unsigned char *) 0xE0010030))
/* I2C Interface 0 */
#define I2C0CONSET      (*((volatile unsigned char *) 0xE001C000))
#define I2C0STAT        (*((volatile unsigned char *) 0xE001C004))
#define I2C0DAT         (*((volatile unsigned char *) 0xE001C008))
#define I2C0ADR         (*((volatile unsigned char *) 0xE001C00C))
#define I2C0SCLH        (*((volatile unsigned short*) 0xE001C010))
#define I2C0SCLL        (*((volatile unsigned short*) 0xE001C014))
#define I2C0CONCLR      (*((volatile unsigned char *) 0xE001C018))

/* I2C Interface 1 */
#define I2C1CONSET      (*((volatile unsigned char *) 0xE005C000))
#define I2C1STAT        (*((volatile unsigned char *) 0xE005C004))
#define I2C1DAT         (*((volatile unsigned char *) 0xE005C008))
#define I2C1ADR         (*((volatile unsigned char *) 0xE005C00C))
#define I2C1SCLH        (*((volatile unsigned short*) 0xE005C010))
#define I2C1SCLL        (*((volatile unsigned short*) 0xE005C014))
#define I2C1CONCLR      (*((volatile unsigned char *) 0xE005C018))

/* SPI0 (Serial Peripheral Interface 0) */
#define S0SPCR          (*((volatile unsigned short*) 0xE0020000))
#define S0SPSR          (*((volatile unsigned char *) 0xE0020004))
#define S0SPDR          (*((volatile unsigned short*) 0xE0020008))
#define S0SPCCR         (*((volatile unsigned char *) 0xE002000C))
#define S0SPINT         (*((volatile unsigned char *) 0xE002001C))

/* SSP Controller (SPI1) */
#define SSPCR0          (*((volatile unsigned short*) 0xE0068000))
#define SSPCR1          (*((volatile unsigned char *) 0xE0068004))
#define SSPDR           (*((volatile unsigned short*) 0xE0068008))
#define SSPSR           (*((volatile unsigned char *) 0xE006800C))
#define SSPCPSR         (*((volatile unsigned char *) 0xE0068010))
#define SSPIMSC         (*((volatile unsigned char *) 0xE0068014))
#define SSPRIS          (*((volatile unsigned char *) 0xE0068018))
#define SSPMIS          (*((volatile unsigned char *) 0xE006801C))
#define SSPICR          (*((volatile unsigned char *) 0xE0068020))

/* Real Time Clock */
#define ILR             (*((volatile unsigned char *) 0xE0024000))
#define CTC             (*((volatile unsigned short*) 0xE0024004))
#define CCR             (*((volatile unsigned char *) 0xE0024008))
#define CIIR            (*((volatile unsigned char *) 0xE002400C))
#define AMR             (*((volatile unsigned char *) 0xE0024010))
#define CTIME0          (*((volatile unsigned long *) 0xE0024014))
#define CTIME1          (*((volatile unsigned long *) 0xE0024018))
#define CTIME2          (*((volatile unsigned long *) 0xE002401C))
#define SEC             (*((volatile unsigned char *) 0xE0024020))
#define MIN             (*((volatile unsigned char *) 0xE0024024))
#define HOUR            (*((volatile unsigned char *) 0xE0024028))
#define DOM             (*((volatile unsigned char *) 0xE002402C))
#define DOW             (*((volatile unsigned char *) 0xE0024030))
#define DOY             (*((volatile unsigned short*) 0xE0024034))
#define MONTH           (*((volatile unsigned char *) 0xE0024038))
#define YEAR            (*((volatile unsigned short*) 0xE002403C))
#define ALSEC           (*((volatile unsigned char *) 0xE0024060))
#define ALMIN           (*((volatile unsigned char *) 0xE0024064))
#define ALHOUR          (*((volatile unsigned char *) 0xE0024068))
#define ALDOM           (*((volatile unsigned char *) 0xE002406C))
#define ALDOW           (*((volatile unsigned char *) 0xE0024070))
#define ALDOY           (*((volatile unsigned short*) 0xE0024074))
#define ALMON           (*((volatile unsigned char *) 0xE0024078))
#define ALYEAR          (*((volatile unsigned short*) 0xE002407C))
#define PREINT          (*((volatile unsigned short*) 0xE0024080))
#define PREFRAC         (*((volatile unsigned short*) 0xE0024084))
/* A/D Converter 0 (AD0) */

#define AD0_BASE_ADDR   (*((volatile unsigned long *) 0xE0034000))
#define AD0CR           (*((volatile unsigned long *) 0xE0034000))
#define AD0GDR          (*((volatile unsigned long *) 0xE0034004))
#define AD0STAT         (*((volatile unsigned long *) 0xE0034030))
#define AD0INTEN        (*((volatile unsigned long *) 0xE003400C))
#define AD0DRArray      ((volatile unsigned long *)(  0xE0034010))       //An array of the AD0DRx registers
#define AD0DR0          (*((volatile unsigned long *) 0xE0034010))
#define AD0DR1          (*((volatile unsigned long *) 0xE0034014))
#define AD0DR2          (*((volatile unsigned long *) 0xE0034018))
#define AD0DR3          (*((volatile unsigned long *) 0xE003401C))
#define AD0DR4          (*((volatile unsigned long *) 0xE0034020))
#define AD0DR5          (*((volatile unsigned long *) 0xE0034024))
#define AD0DR6          (*((volatile unsigned long *) 0xE0034028))
#define AD0DR7          (*((volatile unsigned long *) 0xE003402C))

/* A/D Converter 1 (AD1) */
#define AD1_BASE_ADDR   (*((volatile unsigned long *) 0xE0060000))
#define AD1CR           (*((volatile unsigned long *) 0xE0060000))
#define AD1GDR          (*((volatile unsigned long *) 0xE0060004))
#define AD1STAT         (*((volatile unsigned long *) 0xE0060030))
#define AD1INTEN        (*((volatile unsigned long *) 0xE006000C))
#define AD1DRArray      ((volatile unsigned long *)(  0xE0060010))       //An array of the AD1DRx registers
#define AD1DR0          (*((volatile unsigned long *) 0xE0060010))
#define AD1DR1          (*((volatile unsigned long *) 0xE0060014))
#define AD1DR2          (*((volatile unsigned long *) 0xE0060018))
#define AD1DR3          (*((volatile unsigned long *) 0xE006001C))
#define AD1DR4          (*((volatile unsigned long *) 0xE0060020))
#define AD1DR5          (*((volatile unsigned long *) 0xE0060024))
#define AD1DR6          (*((volatile unsigned long *) 0xE0060028))
#define AD1DR7          (*((volatile unsigned long *) 0xE006002C))

/* A/D Converter Global */
#define ADGSR           (*((volatile unsigned long *) 0xE0034008))

/* D/A Converter */
#define DACR            (*((volatile unsigned long *) 0xE006C000))

/* Watchdog */
#define WDMOD           (*((volatile unsigned char *) 0xE0000000))
#define WDTC            (*((volatile unsigned long *) 0xE0000004))
#define WDFEED          (*((volatile unsigned char *) 0xE0000008))
#define WDTV            (*((volatile unsigned long *) 0xE000000C))

/* USB Controller */
#define USBIntSt        (*((volatile unsigned long *) 0xE01FC1C0))
#define USBDevIntSt     (*((volatile unsigned long *) 0xE0090000))
#define USBDevIntEn     (*((volatile unsigned long *) 0xE0090004))
#define USBDevIntClr    (*((volatile unsigned long *) 0xE0090008))
#define USBDevIntSet    (*((volatile unsigned long *) 0xE009000C))
#define USBDevIntPri    (*((volatile unsigned char *) 0xE009002C))
#define USBEpIntSt      (*((volatile unsigned long *) 0xE0090030))
#define USBEpIntEn      (*((volatile unsigned long *) 0xE0090034))
#define USBEpIntClr     (*((volatile unsigned long *) 0xE0090038))
#define USBEpIntSet     (*((volatile unsigned long *) 0xE009003C))
#define USBEpIntPri     (*((volatile unsigned long *) 0xE0090040))
#define USBReEp         (*((volatile unsigned long *) 0xE0090044))
#define USBEpInd        (*((volatile unsigned long *) 0xE0090048))
#define USBMaxPSize     (*((volatile unsigned long *) 0xE009004C))
#define USBRxData       (*((volatile unsigned long *) 0xE0090018))
#define USBRxPLen       (*((volatile unsigned long *) 0xE0090020))
#define USBTxData       (*((volatile unsigned long *) 0xE009001C))
#define USBTxPLen       (*((volatile unsigned long *) 0xE0090024))
#define USBTxData       (*((volatile unsigned long *) 0xE009001C))
#define USBTxPLen       (*((volatile unsigned long *) 0xE0090024))
#define USBCtrl         (*((volatile unsigned long *) 0xE0090028))
#define USBCmdCode      (*((volatile unsigned long *) 0xE0090010))
#define USBCmdData      (*((volatile unsigned long *) 0xE0090014))
#define USBDMARSt       (*((volatile unsigned long *) 0xE0090050))
#define USBDMARClr      (*((volatile unsigned long *) 0xE0090054))
#define USBDMARSet      (*((volatile unsigned long *) 0xE0090058))
#define USBUDCAH        (*((volatile unsigned long *) 0xE0090080))
#define USBEpDMASt      (*((volatile unsigned long *) 0xE0090084))
#define USBEpDMAEn      (*((volatile unsigned long *) 0xE0090088))
#define USBEpDMADis     (*((volatile unsigned long *) 0xE009008C))
#define USBDMAIntSt     (*((volatile unsigned long *) 0xE0090090))
#define USBDMAIntEn     (*((volatile unsigned long *) 0xE0090094))
#define USBEoTIntSt     (*((volatile unsigned long *) 0xE00900A0))
#define USBEoTIntClr    (*((volatile unsigned long *) 0xE00900A4))
#define USBEoTIntSet    (*((volatile unsigned long *) 0xE00900A8))
#define USBNDDRIntSt    (*((volatile unsigned long *) 0xE00900AC))
#define USBNDDRIntClr   (*((volatile unsigned long *) 0xE00900B0))
#define USBNDDRIntSet   (*((volatile unsigned long *) 0xE00900B4))
#define USBSysErrIntSt  (*((volatile unsigned long *) 0xE00900B8))
#define USBSysErrIntClr (*((volatile unsigned long *) 0xE00900BC))
#define USBSysErrIntSet (*((volatile unsigned long *) 0xE00900C0))






#define AD_CR_SEL0          (0x00000001)
#define AD_CR_SEL1          (0x00000002)
#define AD_CR_SEL2          (0x00000004)
#define AD_CR_SEL3          (0x00000008)
#define AD_CR_SEL4          (0x00000010)
#define AD_CR_SEL5          (0x00000020)
#define AD_CR_SEL6          (0x00000040)
#define AD_CR_SEL7          (0x00000080)
#define AD_CR_SELMASK       (0x000000ff)
#define AD_CR_CLKDIV        (0x0000ff00)
#define AD_CR_CLKDIVMASK    (0x0000ff00)
#define AD_CR_CLKDIVSHIFT   (8)
#define AD_CR_BURST         (0x00010000)
#define AD_CR_CLKS10        (0x00000000)
#define AD_CR_CLKS9         (0x00020000)
#define AD_CR_CLKS8         (0x00040000)
#define AD_CR_CLKS7         (0x00060000)
#define AD_CR_CLKS6         (0x00080000)
#define AD_CR_CLKS5         (0x000a0000)
#define AD_CR_CLKS4         (0x000c0000)
#define AD_CR_CLKS3         (0x000e0000)
#define AD_CR_PDN           (0x00200000)
#define AD_CR_START_NONE    (0x00000000)
#define AD_CR_START_NOW     (0x01000000)
#define AD_CR_START_P016    (0x02000000)
#define AD_CR_START_P022    (0x03000000)
#define AD_CR_START_MAT01   (0x04000000)
#define AD_CR_START_MAT03   (0x05000000)
#define AD_CR_START_MAT10   (0x06000000)
#define AD_CR_START_MAT11   (0x07000000)
#define AD_CR_START_MASK    (0x07000000)
#define AD_CR_EDGE          (0x08000000)
#define AD_CR_MASK          (0x0f2fffff)


#define AD_DR_RESULT        (0x0000ffc0)
#define AD_DR_RESULTMASK    (0x0000ffc0)
#define AD_DR_RESULTSHIFT   (6)
#define AD_DR_OVERRUN       (0x40000000)
#define AD_DR_DONE          (0x80000000)
#define AD_DR_MASK          (0xc000ffc0)


#define PCB_PINSEL0               (*((volatile unsigned long *) (0xe002c000)))
#define PCB_PINSEL1               (*((volatile unsigned long *) (0xe002c004)))
#define PCB_PINSEL2               (*((volatile unsigned long *) (0xe002c014)))

#define PCB_PINSEL0_ALL_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL1_ALL_GPIO      ((unsigned int) 0x00000000)

#define PCB_PINSEL0_P00_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P00_TXD0      ((unsigned int) 0x00000001)
#define PCB_PINSEL0_P00_PWM1      ((unsigned int) 0x00000002)
#define PCB_PINSEL0_P00_RSVD3     ((unsigned int) 0x00000003)
#define PCB_PINSEL0_P00_MASK      ((unsigned int) 0x00000003)
#define PCB_PINSEL0_P01_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P01_RXD0      ((unsigned int) 0x00000004)
#define PCB_PINSEL0_P01_PWM3      ((unsigned int) 0x00000008)
#define PCB_PINSEL0_P01_EINT0     ((unsigned int) 0x0000000c)
#define PCB_PINSEL0_P01_MASK      ((unsigned int) 0x0000000c)

#define PCB_PINSEL0_P02_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P02_SCL0      ((unsigned int) 0x00000010)
#define PCB_PINSEL0_P02_CAP00     ((unsigned int) 0x00000020)
#define PCB_PINSEL0_P02_RSVD3     ((unsigned int) 0x00000030)
#define PCB_PINSEL0_P02_MASK      ((unsigned int) 0x00000030)

#define PCB_PINSEL0_P03_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P03_SDA0      ((unsigned int) 0x00000040)
#define PCB_PINSEL0_P03_MAT00     ((unsigned int) 0x00000080)
#define PCB_PINSEL0_P03_EINT1     ((unsigned int) 0x000000c0)
#define PCB_PINSEL0_P03_MASK      ((unsigned int) 0x000000c0)

#define PCB_PINSEL0_P04_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P04_SCK0      ((unsigned int) 0x00000100)
#define PCB_PINSEL0_P04_CAP01     ((unsigned int) 0x00000200)
#define PCB_PINSEL0_P04_RSVD3     ((unsigned int) 0x00000300)
#define PCB_PINSEL0_P04_MASK      ((unsigned int) 0x00000300)

#define PCB_PINSEL0_P05_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P05_MISO0     ((unsigned int) 0x00000400)
#define PCB_PINSEL0_P05_MAT01     ((unsigned int) 0x00000800)
#define PCB_PINSEL0_P05_AD06      ((unsigned int) 0x00000c00)
#define PCB_PINSEL0_P05_MASK      ((unsigned int) 0x00000c00)

#define PCB_PINSEL0_P06_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P06_MOSI0     ((unsigned int) 0x00001000)
#define PCB_PINSEL0_P06_CAP02     ((unsigned int) 0x00002000)
#define PCB_PINSEL0_P06_AD10      ((unsigned int) 0x00003000)
#define PCB_PINSEL0_P06_MASK      ((unsigned int) 0x00003000)

#define PCB_PINSEL0_P07_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P07_SSEL0     ((unsigned int) 0x00004000)
#define PCB_PINSEL0_P07_PWM2      ((unsigned int) 0x00008000)
#define PCB_PINSEL0_P07_EINT2     ((unsigned int) 0x0000c000)
#define PCB_PINSEL0_P07_MASK      ((unsigned int) 0x0000c000)

#define PCB_PINSEL0_P08_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P08_TXD1      ((unsigned int) 0x00010000)
#define PCB_PINSEL0_P08_PWM4      ((unsigned int) 0x00020000)
#define PCB_PINSEL0_P08_AD11      ((unsigned int) 0x00030000)
#define PCB_PINSEL0_P08_MASK      ((unsigned int) 0x00030000)

#define PCB_PINSEL0_P09_GPIO      ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P09_RXD1      ((unsigned int) 0x00040000)
#define PCB_PINSEL0_P09_PWM6      ((unsigned int) 0x00080000)
#define PCB_PINSEL0_P09_EINT3     ((unsigned int) 0x000c0000)
#define PCB_PINSEL0_P09_MASK      ((unsigned int) 0x000c0000)
#define PCB_PINSEL0_P010_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P010_RTS1     ((unsigned int) 0x00100000)
#define PCB_PINSEL0_P010_CAP10    ((unsigned int) 0x00200000)
#define PCB_PINSEL0_P010_AD12     ((unsigned int) 0x00300000)
#define PCB_PINSEL0_P010_MASK     ((unsigned int) 0x00300000)

#define PCB_PINSEL0_P011_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P011_CTS1     ((unsigned int) 0x00400000)
#define PCB_PINSEL0_P011_CAP11    ((unsigned int) 0x00800000)
#define PCB_PINSEL0_P011_SCL1     ((unsigned int) 0x00c00000)
#define PCB_PINSEL0_P011_MASK     ((unsigned int) 0x00c00000)

#define PCB_PINSEL0_P012_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P012_DSR1     ((unsigned int) 0x01000000)
#define PCB_PINSEL0_P012_MAT10    ((unsigned int) 0x02000000)
#define PCB_PINSEL0_P012_AD13     ((unsigned int) 0x03000000)
#define PCB_PINSEL0_P012_MASK     ((unsigned int) 0x03000000)

#define PCB_PINSEL0_P013_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P013_DTR1     ((unsigned int) 0x04000000)
#define PCB_PINSEL0_P013_MAT11    ((unsigned int) 0x08000000)
#define PCB_PINSEL0_P013_AD14     ((unsigned int) 0x0c000000)
#define PCB_PINSEL0_P013_MASK     ((unsigned int) 0x0c000000)

#define PCB_PINSEL0_P014_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P014_DCD1     ((unsigned int) 0x10000000)
#define PCB_PINSEL0_P014_EINT1    ((unsigned int) 0x20000000)
#define PCB_PINSEL0_P014_SDA1     ((unsigned int) 0x30000000)
#define PCB_PINSEL0_P014_MASK     ((unsigned int) 0x30000000)

#define PCB_PINSEL0_P015_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL0_P015_RI1      ((unsigned int) 0x40000000)
#define PCB_PINSEL0_P015_EINT2    ((unsigned int) 0x80000000)
#define PCB_PINSEL0_P015_AD15     ((unsigned int) 0xc0000000)
#define PCB_PINSEL0_P015_MASK     ((unsigned int) 0xc0000000)

#define PCB_PINSEL1_P016_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P016_EINT0    ((unsigned int) 0x00000001)
#define PCB_PINSEL1_P016_MAT02    ((unsigned int) 0x00000002)
#define PCB_PINSEL1_P016_CAP02    ((unsigned int) 0x00000003)
#define PCB_PINSEL1_P016_MASK     ((unsigned int) 0x00000003)
#define PCB_PINSEL1_P017_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P017_CAP12    ((unsigned int) 0x00000004)
#define PCB_PINSEL1_P017_SCK1     ((unsigned int) 0x00000008)
#define PCB_PINSEL1_P017_MAT12    ((unsigned int) 0x0000000c)
#define PCB_PINSEL1_P017_MASK     ((unsigned int) 0x0000000c)

#define PCB_PINSEL1_P018_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P018_CAP13    ((unsigned int) 0x00000010)
#define PCB_PINSEL1_P018_MISO1    ((unsigned int) 0x00000020)
#define PCB_PINSEL1_P018_MAT13    ((unsigned int) 0x00000030)
#define PCB_PINSEL1_P018_MASK     ((unsigned int) 0x00000030)

#define PCB_PINSEL1_P019_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P019_MAT12    ((unsigned int) 0x00000040)
#define PCB_PINSEL1_P019_MOSI1    ((unsigned int) 0x00000080)
#define PCB_PINSEL1_P019_CAP12    ((unsigned int) 0x000000c0)
#define PCB_PINSEL1_P019_MASK     ((unsigned int) 0x000000c0)

#define PCB_PINSEL1_P020_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P020_MAT13    ((unsigned int) 0x00000100)
#define PCB_PINSEL1_P020_SSEL1    ((unsigned int) 0x00000200)
#define PCB_PINSEL1_P020_EINT3    ((unsigned int) 0x00000300)
#define PCB_PINSEL1_P020_MASK     ((unsigned int) 0x00000300)

#define PCB_PINSEL1_P021_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P021_PWM5     ((unsigned int) 0x00000400)
#define PCB_PINSEL1_P021_AD16     ((unsigned int) 0x00000800)
#define PCB_PINSEL1_P021_CAP13    ((unsigned int) 0x00000c00)
#define PCB_PINSEL1_P021_MASK     ((unsigned int) 0x00000c00)

#define PCB_PINSEL1_P022_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P022_AD17     ((unsigned int) 0x00001000)
#define PCB_PINSEL1_P022_CAP00    ((unsigned int) 0x00002000)
#define PCB_PINSEL1_P022_MAT00    ((unsigned int) 0x00003000)
#define PCB_PINSEL1_P022_MASK     ((unsigned int) 0x00003000)

#define PCB_PINSEL1_P023_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P023_VBUS     ((unsigned int) 0x00004000)
#define PCB_PINSEL1_P023_RSVD2    ((unsigned int) 0x00008000)
#define PCB_PINSEL1_P023_RSVD3    ((unsigned int) 0x0000c000)
#define PCB_PINSEL1_P023_MASK     ((unsigned int) 0x0000c000)

#define PCB_PINSEL1_P024_RSVD0    ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P024_RSVD1    ((unsigned int) 0x00010000)
#define PCB_PINSEL1_P024_RSVD2    ((unsigned int) 0x00020000)
#define PCB_PINSEL1_P024_RSVD3    ((unsigned int) 0x00030000)
#define PCB_PINSEL1_P024_MASK     ((unsigned int) 0x00030000)

#define PCB_PINSEL1_P025_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P025_AD04     ((unsigned int) 0x00040000)
#define PCB_PINSEL1_P025_AOUT     ((unsigned int) 0x00080000)
#define PCB_PINSEL1_P025_RSVD3    ((unsigned int) 0x000c0000)
#define PCB_PINSEL1_P025_MASK     ((unsigned int) 0x000c0000)

#define PCB_PINSEL1_P026_RSVD0    ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P026_RSVD1    ((unsigned int) 0x00100000)
#define PCB_PINSEL1_P026_RSVD2    ((unsigned int) 0x00200000)
#define PCB_PINSEL1_P026_RSVD3    ((unsigned int) 0x00300000)
#define PCB_PINSEL1_P026_MASK     ((unsigned int) 0x00300000)

#define PCB_PINSEL1_P027_RSVD0    ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P027_RSVD1    ((unsigned int) 0x00400000)
#define PCB_PINSEL1_P027_RSVD2    ((unsigned int) 0x00800000)
#define PCB_PINSEL1_P027_RSVD3    ((unsigned int) 0x00c00000)
#define PCB_PINSEL1_P027_MASK     ((unsigned int) 0x00c00000)

#define PCB_PINSEL1_P028_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P028_AD01     ((unsigned int) 0x01000000)
#define PCB_PINSEL1_P028_CAP02    ((unsigned int) 0x02000000)
#define PCB_PINSEL1_P028_MAT02    ((unsigned int) 0x03000000)
#define PCB_PINSEL1_P028_MASK     ((unsigned int) 0x03000000)

#define PCB_PINSEL1_P029_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P029_AD02     ((unsigned int) 0x04000000)
#define PCB_PINSEL1_P029_CAP03    ((unsigned int) 0x08000000)
#define PCB_PINSEL1_P029_MAT03    ((unsigned int) 0x0c000000)
#define PCB_PINSEL1_P029_MASK     ((unsigned int) 0x0c000000)

#define PCB_PINSEL1_P030_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P030_AD03     ((unsigned int) 0x10000000)
#define PCB_PINSEL1_P030_EINT3    ((unsigned int) 0x20000000)
#define PCB_PINSEL1_P030_CAP00    ((unsigned int) 0x30000000)
#define PCB_PINSEL1_P030_MASK     ((unsigned int) 0x30000000)

#define PCB_PINSEL1_P031_GPIO     ((unsigned int) 0x00000000)
#define PCB_PINSEL1_P031_UPLED    ((unsigned int) 0x40000000)
#define PCB_PINSEL1_P031_CONNECT  ((unsigned int) 0x80000000)
#define PCB_PINSEL1_P031_RSVD3    ((unsigned int) 0xc0000000)
#define PCB_PINSEL1_P031_MASK     ((unsigned int) 0xc0000000)

#define PCB_PINSEL2_P13626_GPIO   ((unsigned int) 0x00000000) 
#define PCB_PINSEL2_P13626_DEBUG  ((unsigned int) 0x00000004) 
#define PCB_PINSEL2_P13626_MASK   ((unsigned int) 0x00000004)

#define PCB_PINSEL2_P12516_GPIO   ((unsigned int) 0x00000000) 
#define PCB_PINSEL2_P12516_TRACE  ((unsigned int) 0x00000008) 
#define PCB_PINSEL2_P12516_MASK   ((unsigned int) 0x00000008)

#define SCB_PCONP           (*((volatile unsigned long *) (0xe01fc0c4)))
#define SCB_PCONP_PCAD0     (0x00001000)

#endif  // __LPC214x_H