/*-------------------------------------------------------------------------
  Register Declarations for SIEMENS/INFINEON SAB 80515 Processor

   Written By - Bela Torok
   Bela.Torokt@kssg.ch
   based on reg51.h by Sandeep Dutta sandeep.dutta@usa.net
   KEIL C compatible definitions are included

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA

   In other words, you are welcome to use, share and improve this program.
   You are forbidden to forbid anyone else to use, share and improve
   what you give them.   Help stamp out software-hoarding!
-------------------------------------------------------------------------*/

#ifndef SAB80515_H
#define SAB80515_H

/* BYTE addressable registers */
__sfr __at (0x1234) P0          ;
__sfr __at (0x1234) SP          ;
__sfr __at (0x1234) DPL         ;
__sfr __at (0x1234) DPH         ;
__sfr __at (0x1234) PCON        ;
__sfr __at (0x1234) TCON        ;
__sfr __at (0x1234) TMOD        ;
__sfr __at (0x1234) TL0         ;
__sfr __at (0x1234) TL1         ;
__sfr __at (0x1234) TH0         ;
__sfr __at (0x1234) TH1         ;
__sfr __at (0x1234) P1          ;
__sfr __at (0x1234) SCON        ;
__sfr __at (0x1234) SBUF        ;
__sfr __at (0x1234) P2          ;
__sfr __at (0x1234) IE          ;
__sfr __at (0x1234) IEN0        ; /* as called by Siemens */
__sfr __at (0x1234) IP0         ; /* interrupt priority register - SAB80515 specific */
__sfr __at (0x1234) P3          ;
__sfr __at (0x1234) IEN1        ; /* interrupt enable register - SAB80515 specific */
__sfr __at (0x1234) IP1         ; /* interrupt priority register as called by Siemens */
__sfr __at (0x1234) IRCON       ; /* interrupt control register - SAB80515 specific */
__sfr __at (0x1234) CCEN        ; /* compare/capture enable register */
__sfr __at (0x1234) CCL1        ; /* compare/capture register 1, low byte */
__sfr __at (0x1234) CCH1        ; /* compare/capture register 1, high byte */
__sfr __at (0x1234) CCL2        ; /* compare/capture register 2, low byte */
__sfr __at (0x1234) CCH2        ; /* compare/capture register 2, high byte */
__sfr __at (0x1234) CCL3        ; /* compare/capture register 3, low byte */
__sfr __at (0x1234) CCH3        ; /* compare/capture register 3, high byte */
__sfr __at (0x1234) T2CON       ;
__sfr __at (0x1234) CRCL        ; /* compare/reload/capture register, low byte */
__sfr __at (0x1234) CRCH        ; /* compare/reload/capture register, high byte */
__sfr __at (0x1234) TL2         ;
__sfr __at (0x1234) TH2         ;
__sfr __at (0x1234) PSW         ;
__sfr __at (0x1234) ADCON       ; /* A/D-converter control register */
__sfr __at (0x1234) ADDAT       ; /* A/D-converter data register */
__sfr __at (0x1234) DAPR        ; /* D/A-converter program register */
__sfr __at (0x1234) P6          ; /* Port 6 - SAB80515 specific */
__sfr __at (0x1234) ACC         ;
__sfr __at (0x1234) A           ;
__sfr __at (0x1234) P4          ; /* Port 4 - SAB80515 specific */
__sfr __at (0x1234) B           ;
__sfr __at (0x1234) P5          ; /* Port 5 - SAB80515 specific */


/* BIT addressable registers */
/* P0 */
__sbit __at (0x1234) P0_0       ;
__sbit __at (0x1234) P0_1       ;
__sbit __at (0x1234) P0_2       ;
__sbit __at (0x1234) P0_3       ;
__sbit __at (0x1234) P0_4       ;
__sbit __at (0x1234) P0_5       ;
__sbit __at (0x1234) P0_6       ;
__sbit __at (0x1234) P0_7       ;

/* TCON */
__sbit __at (0x1234) IT0        ;
__sbit __at (0x1234) IE0        ;
__sbit __at (0x1234) IT1        ;
__sbit __at (0x1234) IE1        ;
__sbit __at (0x1234) TR0        ;
__sbit __at (0x1234) TF0        ;
__sbit __at (0x1234) TR1        ;
__sbit __at (0x1234) TF1        ;

/* P1 */
__sbit __at (0x1234) P1_0       ;
__sbit __at (0x1234) P1_1       ;
__sbit __at (0x1234) P1_2       ;
__sbit __at (0x1234) P1_3       ;
__sbit __at (0x1234) P1_4       ;
__sbit __at (0x1234) P1_5       ;
__sbit __at (0x1234) P1_6       ;
__sbit __at (0x1234) P1_7       ;

__sbit __at (0x1234) INT3_CC0   ; /* P1 alternate functions - SAB80515 specific */
__sbit __at (0x1234) INT4_CC1   ;
__sbit __at (0x1234) INT5_CC2   ;
__sbit __at (0x1234) INT6_CC3   ;
__sbit __at (0x1234) INT2       ;
__sbit __at (0x1234) T2EX       ;
__sbit __at (0x1234) CLKOUT     ;
__sbit __at (0x1234) T2         ;

/* SCON */
__sbit __at (0x1234) RI         ;
__sbit __at (0x1234) TI         ;
__sbit __at (0x1234) RB8        ;
__sbit __at (0x1234) TB8        ;
__sbit __at (0x1234) REN        ;
__sbit __at (0x1234) SM2        ;
__sbit __at (0x1234) SM1        ;
__sbit __at (0x1234) SM0        ;

/* P2 */
__sbit __at (0x1234) P2_0       ;
__sbit __at (0x1234) P2_1       ;
__sbit __at (0x1234) P2_2       ;
__sbit __at (0x1234) P2_3       ;
__sbit __at (0x1234) P2_4       ;
__sbit __at (0x1234) P2_5       ;
__sbit __at (0x1234) P2_6       ;
__sbit __at (0x1234) P2_7       ;

/* IEN0 */
__sbit __at (0x1234) EX0        ;
__sbit __at (0x1234) ET0        ;
__sbit __at (0x1234) EX1        ;
__sbit __at (0x1234) ET1        ;
__sbit __at (0x1234) ES         ;
__sbit __at (0x1234) ET2        ;
__sbit __at (0x1234) WDT        ; /* watchdog timer reset - SAB80515 specific */
__sbit __at (0x1234) EA         ;

__sbit __at (0x1234) EAL        ; /* EA as called by Siemens */

/* P3 */
__sbit __at (0x1234) P3_0       ;
__sbit __at (0x1234) P3_1       ;
__sbit __at (0x1234) P3_2       ;
__sbit __at (0x1234) P3_3       ;
__sbit __at (0x1234) P3_4       ;
__sbit __at (0x1234) P3_5       ;
__sbit __at (0x1234) P3_6       ;
__sbit __at (0x1234) P3_7       ;

__sbit __at (0x1234) RXD        ;
__sbit __at (0x1234) TXD        ;
__sbit __at (0x1234) INT0       ;
__sbit __at (0x1234) INT1       ;
__sbit __at (0x1234) T0         ;
__sbit __at (0x1234) T1         ;
__sbit __at (0x1234) WR         ;
__sbit __at (0x1234) RD         ;

/* IEN1 */
__sbit __at (0x1234) EADC       ; /* A/D converter interrupt enable */
__sbit __at (0x1234) EX2        ;
__sbit __at (0x1234) EX3        ;
__sbit __at (0x1234) EX4        ;
__sbit __at (0x1234) EX5        ;
__sbit __at (0x1234) EX6        ;
__sbit __at (0x1234) SWDT       ; /* watchdog timer start/reset */
__sbit __at (0x1234) EXEN2      ; /* timer2 external reload interrupt enable */

/* IRCON */
__sbit __at (0x1234) IADC       ; /* A/D converter irq flag */
__sbit __at (0x1234) IEX2       ; /* external interrupt edge detect flag */
__sbit __at (0x1234) IEX3       ;
__sbit __at (0x1234) IEX4       ;
__sbit __at (0x1234) IEX5       ;
__sbit __at (0x1234) IEX6       ;
__sbit __at (0x1234) TF2        ; /* timer 2 owerflow flag  */
__sbit __at (0x1234) EXF2       ; /* timer2 reload flag */

/* T2CON */
__sbit __at (0x1234) T2CON_0    ;
__sbit __at (0x1234) T2CON_1    ;
__sbit __at (0x1234) T2CON_2    ;
__sbit __at (0x1234) T2CON_3    ;
__sbit __at (0x1234) T2CON_4    ;
__sbit __at (0x1234) T2CON_5    ;
__sbit __at (0x1234) T2CON_6    ;
__sbit __at (0x1234) T2CON_7    ;

__sbit __at (0x1234) T2I0       ;
__sbit __at (0x1234) T2I1       ;
__sbit __at (0x1234) T2CM       ;
__sbit __at (0x1234) T2R0       ;
__sbit __at (0x1234) T2R1       ;
__sbit __at (0x1234) I2FR       ;
__sbit __at (0x1234) I3FR       ;
__sbit __at (0x1234) T2PS       ;


/* PSW */
__sbit __at (0x1234) P          ;
__sbit __at (0x1234) FL         ;
__sbit __at (0x1234) OV         ;
__sbit __at (0x1234) RS0        ;
__sbit __at (0x1234) RS1        ;
__sbit __at (0x1234) F0         ;
__sbit __at (0x1234) AC         ;
__sbit __at (0x1234) CY         ;

__sbit __at (0x1234) F1         ;

/* ADCON */
__sbit __at (0x1234) MX0        ;
__sbit __at (0x1234) MX1        ;
__sbit __at (0x1234) MX2        ;
__sbit __at (0x1234) ADM        ;
__sbit __at (0x1234) BSY        ;

__sbit __at (0x1234) CLK        ;
__sbit __at (0x1234) BD         ;

/* A */
__sbit __at (0x1234) AREG_F0    ;
__sbit __at (0x1234) AREG_F1    ;
__sbit __at (0x1234) AREG_F2    ;
__sbit __at (0x1234) AREG_F3    ;
__sbit __at (0x1234) AREG_F4    ;
__sbit __at (0x1234) AREG_F5    ;
__sbit __at (0x1234) AREG_F6    ;
__sbit __at (0x1234) AREG_F7    ;

/* P4 */
__sbit __at (0x1234) P4_0       ;
__sbit __at (0x1234) P4_1       ;
__sbit __at (0x1234) P4_2       ;
__sbit __at (0x1234) P4_3       ;
__sbit __at (0x1234) P4_4       ;
__sbit __at (0x1234) P4_5       ;
__sbit __at (0x1234) P4_6       ;
__sbit __at (0x1234) P4_7       ;

/* B */
__sbit __at (0x1234) BREG_F0    ;
__sbit __at (0x1234) BREG_F1    ;
__sbit __at (0x1234) BREG_F2    ;
__sbit __at (0x1234) BREG_F3    ;
__sbit __at (0x1234) BREG_F4    ;
__sbit __at (0x1234) BREG_F5    ;
__sbit __at (0x1234) BREG_F6    ;
__sbit __at (0x1234) BREG_F7    ;

/* P5 */
__sbit __at (0x1234) P5_0       ;
__sbit __at (0x1234) P5_1       ;
__sbit __at (0x1234) P5_2       ;
__sbit __at (0x1234) P5_3       ;
__sbit __at (0x1234) P5_4       ;
__sbit __at (0x1234) P5_5       ;
__sbit __at (0x1234) P5_6       ;
__sbit __at (0x1234) P5_7       ;

/* BIT definitions for bits that are not directly accessible */
/* PCON bits */
#define IDL             0x01
#define PD              0x02
#define GF0             0x04
#define GF1             0x08
#define SMOD            0x80

#define IDL_            0x01
#define PD_             0x02
#define GF0_            0x04
#define GF1_            0x08
#define SMOD_           0x80

/* TMOD bits */
#define M0_0            0x01
#define M1_0            0x02
#define C_T0            0x04
#define GATE0           0x08
#define M0_1            0x10
#define M1_1            0x20
#define C_T1            0x40
#define GATE1           0x80

#define M0_0_           0x01
#define M1_0_           0x02
#define C_T0_           0x04
#define GATE0_          0x08
#define M0_1_           0x10
#define M1_1_           0x20
#define C_T1_           0x40
#define GATE1_          0x80

#define T0_M0           0x01
#define T0_M1           0x02
#define T0_CT           0x04
#define T0_GATE         0x08
#define T1_M0           0x10
#define T1_M1           0x20
#define T1_CT           0x40
#define T1_GATE         0x80

#define T0_M0_          0x01
#define T0_M1_          0x02
#define T0_CT_          0x04
#define T0_GATE_        0x08
#define T1_M0_          0x10
#define T1_M1_          0x20
#define T1_CT_          0x40
#define T1_GATE_        0x80

#define T0_MASK         0x0F
#define T1_MASK         0xF0

#define T0_MASK_        0x0F
#define T1_MASK_        0xF0

/* T2MOD bits */
#define DCEN            0x01
#define T2OE            0x02

#define DCEN_           0x01
#define T2OE_           0x02

/* WMCON bits */
#define WMCON_WDTEN     0x01
#define WMCON_WDTRST    0x02
#define WMCON_DPS       0x04
#define WMCON_EEMEN     0x08
#define WMCON_EEMWE     0x10
#define WMCON_PS0       0x20
#define WMCON_PS1       0x40
#define WMCON_PS2       0x80

/* SPCR-SPI bits */
#define SPCR_SPR0       0x01
#define SPCR_SPR1       0x02
#define SPCR_CPHA       0x04
#define SPCR_CPOL       0x08
#define SPCR_MSTR       0x10
#define SPCR_DORD       0x20
#define SPCR_SPE        0x40
#define SPCR_SPIE       0x80

/* SPSR-SPI bits */
#define SPSR_WCOL       0x40
#define SPSR_SPIF       0x80

/* SPDR-SPI bits */
#define SPDR_SPD0       0x10
#define SPDR_SPD1       0x20
#define SPDR_SPD2       0x40
#define SPDR_SPD3       0x80
#define SPDR_SPD4       0x10
#define SPDR_SPD5       0x20
#define SPDR_SPD6       0x40
#define SPDR_SPD7       0x80

/* Interrupt numbers: address = (number * 8) + 3 */
#define IE0_VECTOR      0       /* 0x03 external interrupt 0 */
#define TF0_VECTOR      1       /* 0x0b timer 0 */
#define IE1_VECTOR      2       /* 0x13 external interrupt 1 */
#define TF1_VECTOR      3       /* 0x1b timer 1 */
#define SI0_VECTOR      4       /* 0x23 serial port 0 */
#define TF2_VECTOR      5       /* 0x2B timer 2 */
#define EX2_VECTOR      5       /* 0x2B external interrupt 2 */

#define IADC_VECTOR     8       /* 0x43 A/D converter interrupt */
#define IEX2_VECTOR     9       /* 0x4B external interrupt 2 */
#define IEX3_VECTOR    10       /* 0x53 external interrupt 3 */
#define IEX4_VECTOR    11       /* 0x5B external interrupt 4 */
#define IEX5_VECTOR    12       /* 0x63 external interrupt 5 */
#define IEX6_VECTOR    13       /* 0x6B external interrupt 6 */

#endif

