/*********MACROS*******/

#define   WriteReg(Address, Value) ((*((volatile unsigned char __xdata *) Address)) = Value)
#define   ReadReg(Address)         (*((volatile unsigned char __xdata *) Address))

/*********UART0*********/
#define UART0_BA                   0x2800

#define UART0_CFG0                UART0_BA + 0x0
#define UART0_CFG1                UART0_BA + 0x1
#define UART0_BDR0                UART0_BA + 0x4
#define UART0_BDR1                UART0_BA + 0x5
#define UART0_TXFIFOLVL0          UART0_BA + 0x8
#define UART0_TXFIFOLVL1          UART0_BA + 0x9
#define UART0_RXFIFOLVL0          UART0_BA + 0xc
#define UART0_RXFIFOLVL1          UART0_BA + 0xd
#define UART0_NBMSK               UART0_BA + 0x10
#define UART0_NBADDR0             UART0_BA + 0x14
#define UART0_NBADDR1             UART0_BA + 0x15
#define UART0_MSK0                UART0_BA + 0x18
#define UART0_MSK1                UART0_BA + 0x19
#define UART0_CTRL                UART0_BA + 0x1c
#define UART0_TX                  UART0_BA + 0x20
#define UART0_RX0                 UART0_BA + 0x24
#define UART0_RX1                 UART0_BA + 0x25
#define UART0_ST0                 UART0_BA + 0x28
#define UART0_ST1                 UART0_BA + 0x29

/*********UART1*********/
#define UART1_BA                   0x2900

#define UART1_CFG0                UART1_BA + 0x0
#define UART1_CFG1                UART1_BA + 0x1
#define UART1_BDR0                UART1_BA + 0x4
#define UART1_BDR1                UART1_BA + 0x5
#define UART1_TXFIFOLVL0          UART1_BA + 0x8
#define UART1_TXFIFOLVL1          UART1_BA + 0x9
#define UART1_RXFIFOLVL0          UART1_BA + 0xc
#define UART1_RXFIFOLVL1          UART1_BA + 0xd
#define UART1_NBMSK               UART1_BA + 0x10
#define UART1_NBADDR0             UART1_BA + 0x14
#define UART1_NBADDR1             UART1_BA + 0x15
#define UART1_MSK0                UART1_BA + 0x18
#define UART1_MSK1                UART1_BA + 0x19
#define UART1_CTRL                UART1_BA + 0x1c
#define UART1_TX                  UART1_BA + 0x20
#define UART1_RX0                 UART1_BA + 0x24
#define UART1_RX1                 UART1_BA + 0x25
#define UART1_ST0                 UART1_BA + 0x28
#define UART1_ST1                 UART1_BA + 0x29

/*********I2C*********/
//--- CTRL
#define   RST_RX_PNTRS           1<<7
#define   NRST_RX_PNTRS          0
#define   RST_TX_RDP             1<<6
#define   NRST_TX_RDP            0
#define   RST_TX_PNTRS           1<<5
#define   NRST_TX_PNTRS          0
#define   ADDR_10_BITS           1<<4
#define   ADDR_7_BITS            0
#define   SEND_ACK               1<<3
#define   NSEND_ACK              0
#define   SEND_STOP              1<<2
#define   NSEND_STOP             0
#define   SEND_START             1<<1
#define   NSEND_START            0
#define   EN_I2C                 1
#define   DIS_I2C                0

//--- CFG
#define   EN_CYCLE_BUF           1
#define   DIS_CYCLE_BUF          0

//--- PRSC
#define   FAST_MODE              1<<7
#define   STANDART_MODE          0
#define   DUTY_16_9              1<<6
#define   DUTY_2_1               0

//--- ST
#define   NBUSY                  1
#define   FIFO_RX_REACH_LVL      1<<7
#define   MST_MODE               1<<6
#define   BUS_CLEAR              1<<5
#define   SLV_WR_FIX             1<<4
#define   SLV_RD_FIX             1<<3
#define   FIFO_TX_EMPTY          1<<2
#define   FIFO_TX_FULL           1<<1
#define   FIFO_RX_NEMPTY         1
#define   FIFO_RX_OV             1<<7
#define   FIFO_RX_FULL           1<<6
#define   ARB_LOST               1<<5
#define   BUS_ERROR              1<<4
#define   NACK_FIX               1<<3
#define   END_BYTE               1<<2
#define   STOP_FIX               1<<1
#define   START_FIX              1

#define I2C_BA                   0x2a00

#define I2C_CFG                 I2C_BA + 0x0
#define I2C_CTRL                I2C_BA + 0x4
#define I2C_ST0                 I2C_BA + 0x8
#define I2C_ST1                 I2C_BA + 0x9
#define I2C_ST2                 I2C_BA + 0xa
#define I2C_ADDR0               I2C_BA + 0xC
#define I2C_ADDR1               I2C_BA + 0xD
#define I2C_PRSC0               I2C_BA + 0x10
#define I2C_PRSC1               I2C_BA + 0x11
#define I2C_PRSC2               I2C_BA + 0x12
#define I2C_PRSC3               I2C_BA + 0x13
#define I2C_MSK0                I2C_BA + 0x14
#define I2C_MSK1                I2C_BA + 0x15
#define I2C_MSK2                I2C_BA + 0x16
#define I2C_TXFIFO              I2C_BA + 0x18
#define I2C_RXFIFO              I2C_BA + 0x1C
#define I2C_TXWORDS             I2C_BA + 0x20
#define I2C_RXTHRESHOLD         I2C_BA + 0x24

/********1WIRE********/
#define ONE_WIRE_BA              0x2b00

#define OWI_CFG                  ONE_WIRE_BA + 0x0
#define OWI_BUF                  ONE_WIRE_BA + 0x4
#define OWI_ST                   ONE_WIRE_BA + 0x8
#define OWI_MSK                  ONE_WIRE_BA + 0x0C
#define OWI_PRCR                 ONE_WIRE_BA + 0x10
#define OWI_CTRL                 ONE_WIRE_BA + 0x14


#define OWI_CFG_1WR							 (1 << 0)
#define OWI_CFG_SRA							 (1 << 1)
#define OWI_CFG_FOW							 (1 << 2)
#define OWI_CFG_OW_IN						 (1 << 3)


#define OWI_ST_PD								 (1 << 0)
#define OWI_ST_PDR							 (1 << 1)
#define OWI_ST_TBE							 (1 << 2)
#define OWI_ST_TEMT							 (1 << 3)
#define OWI_ST_RBF							 (1 << 4)
#define OWI_ST_RSRF							 (1 << 5)
#define OWI_ST_OW_SHORT					 (1 << 6)
#define OWI_ST_OW_LOW						 (1 << 7)


#define OWI_MSK_EPD 						 (1 << 0)
#define OWI_MSK_IAS 						 (1 << 1)
#define OWI_MSK_ETBE 						 (1 << 2)
#define OWI_MSK_ETEMT 					 (1 << 3)
#define OWI_MSK_ERBF 						 (1 << 4)
#define OWI_MSK_ERSF						 (1 << 5)
#define OWI_MSK_EOWSH						 (1 << 6)
#define OWI_MSK_EOWL						 (1 << 7)


#define OWI_PRCR_PRE_1					 (0x00 << 0)
#define OWI_PRCR_PRE_3					 (0x01 << 0)
#define OWI_PRCR_PRE_5					 (0x02 << 0)
#define OWI_PRCR_PRE_7					 (0x03 << 0)
#define OWI_PRCR_DIV_1					 (0x00 << 2)
#define OWI_PRCR_DIV_2					 (0x01 << 2)
#define OWI_PRCR_DIV_4					 (0x02 << 2)
#define OWI_PRCR_DIV_8					 (0x03 << 2)
#define OWI_PRCR_DIV_16					 (0x04 << 2)
#define OWI_PRCR_DIV_32					 (0x05 << 2)
#define OWI_PRCR_DIV_64					 (0x06 << 2)
#define OWI_PRCR_DIV_128				 (0x07 << 2)
#define OWI_PRCR_CLK_EN					 (1 << 7)


#define OWI_CTRL_LLM						 (1 << 0)
#define OWI_CTRL_PPM						 (1 << 1)
#define OWI_CTRL_EN_FOW					 (1 << 2)
#define OWI_CTRL_STPEN					 (1 << 3)
#define OWI_CTRL_STP_SPLY				 (1 << 4)
#define OWI_CTRL_DIT_CTL				 (1 << 5)
#define OWI_CTRL_DIT_OD					 (1 << 6)

/*********ADC*********/
#define ADC_BA                    0x2F00

#define ADC_CTRL                  ADC_BA + 0x0
#define ADC_CFG                   ADC_BA + 0x4
#define ADC_MSK                   ADC_BA + 0x8
#define ADC_ST                    ADC_BA + 0xC
#define ADC_RESL                  ADC_BA + 0x10
#define ADC_RESH                  ADC_BA + 0x11

/*********DAC*********/
#define DAC_BA                    0x3000

#define DAC_CTRL                  DAC_BA + 0x0
#define DAC_CFG                   DAC_BA + 0x4
#define DAC_VALUE0                DAC_BA + 0x8
#define DAC_VALUE1                DAC_BA + 0x9

/*********SPI0*********/
#define SPI0_BA                   0x2600

#define SPI0_CTRL                 SPI0_BA + 0x0
#define SPI0_CFG0                 SPI0_BA + 0x4
#define SPI0_CFG1                 SPI0_BA + 0x5
#define SPI0_CFG2                 SPI0_BA + 0x6
#define SPI0_CFG3                 SPI0_BA + 0x7
#define SPI0_MSK                  SPI0_BA + 0x8
#define SPI0_ST                   SPI0_BA + 0xC
#define SPI0_TX0                  SPI0_BA + 0x10
#define SPI0_TX1              	  SPI0_BA + 0x11
#define SPI0_RX0                  SPI0_BA + 0x10
#define SPI0_RX1                  SPI0_BA + 0x11

/*********SPI1*********/
#define SPI1_BA                   0x2700

#define SPI1_CTRL                 SPI1_BA + 0x0
#define SPI1_CFG0                 SPI1_BA + 0x4
#define SPI1_CFG1                 SPI1_BA + 0x5
#define SPI1_CFG2                 SPI1_BA + 0x6
#define SPI1_CFG3                 SPI1_BA + 0x7
#define SPI1_MSK                  SPI1_BA + 0x8
#define SPI1_ST                   SPI1_BA + 0xc
#define SPI1_TX0                  SPI1_BA + 0x10
#define SPI1_TX1              	  SPI1_BA + 0x11
#define SPI1_RX0                  SPI1_BA + 0x10
#define SPI1_RX1                  SPI1_BA + 0x11

/*********WDT*********/
#define WDT_BA                   0x2200

#define WDT_LOAD0                WDT_BA + 0x0
#define WDT_LOAD1                WDT_BA + 0x1
#define WDT_LOAD2                WDT_BA + 0x2
#define WDT_LOAD3                WDT_BA + 0x3
#define WDT_VAL0                 WDT_BA + 0x4
#define WDT_VAL1                 WDT_BA + 0x5
#define WDT_VAL2                 WDT_BA + 0x6
#define WDT_VAL3                 WDT_BA + 0x7
#define WDT_CTRL                 WDT_BA + 0x8
#define WDT_CLR                  WDT_BA + 0xc
#define WDT_INTRAW               WDT_BA + 0x10
#define WDT_INT                  WDT_BA + 0x14
#define WDT_LOCK                 WDT_BA + 0x18
#define WDT_TCR                  WDT_BA + 0x1c
#define WDT_TOP                  WDT_BA + 0x20

/*********PMM*********/
#define PMM_BA                   0x2000

#define PMM_CTRL                 PMM_BA + 0x0
#define PMM_ST                   PMM_BA + 0x1

/*********CMM*********/
#define CMM_BA                   0x2100

#define CMM_CTRL                CMM_BA + 0x0
#define CMM_DIV                 CMM_BA + 0x1
#define CMM_MSK                 CMM_BA + 0x2
#define CMM_ST                  CMM_BA + 0x3

/*********GPIOA********/
#define GPIOA_BA                 0x2300

#define GPIOA_DIR_SET            GPIOA_BA + 0x0
#define GPIOA_DIR_CLR            GPIOA_BA + 0x1
#define GPIOA_ALTF0              GPIOA_BA + 0x4
#define GPIOA_ALTF1              GPIOA_BA + 0x5
#define GPIOA_INTEN_SET		 GPIOA_BA + 0x6
#define GPIOA_INTEN_CLR		 GPIOA_BA + 0x7
#define GPIOA_INTTYPE_SET	 GPIOA_BA + 0x8
#define GPIOA_INTTYPE_CLR	 GPIOA_BA + 0x9
#define GPIOA_INTPOL_SET	 GPIOA_BA + 0xA
#define GPIOA_INTPOL_CLR	 GPIOA_BA + 0xB
#define GPIOA_INT	 	 GPIOA_BA + 0xC

/*********GPIOB********/
#define GPIOB_BA                 0x2400

#define GPIOB_DIR_SET            GPIOB_BA + 0x0
#define GPIOB_DIR_CLR            GPIOB_BA + 0x1
#define GPIOB_ALTF0              GPIOB_BA + 0x4
#define GPIOB_ALTF1              GPIOB_BA + 0x5
#define GPIOB_INTEN_SET		 GPIOB_BA + 0x6
#define GPIOB_INTEN_CLR		 GPIOB_BA + 0x7
#define GPIOB_INTTYPE_SET	 GPIOB_BA + 0x8
#define GPIOB_INTTYPE_CLR	 GPIOB_BA + 0x9
#define GPIOB_INTPOL_SET	 GPIOB_BA + 0xA
#define GPIOB_INTPOL_CLR	 GPIOB_BA + 0xB
#define GPIOB_INT	 	 GPIOB_BA + 0xC

/*********GPIOC********/
#define GPIOC_BA                 0x2500

#define GPIOC_DIR_SET            GPIOC_BA + 0x0
#define GPIOC_DIR_CLR            GPIOC_BA + 0x1
#define GPIOC_ALTF0              GPIOC_BA + 0x4
#define GPIOC_ALTF1              GPIOC_BA + 0x5
#define GPIOC_INTEN_SET		 GPIOC_BA + 0x6
#define GPIOC_INTEN_CLR		 GPIOC_BA + 0x7
#define GPIOC_INTTYPE_SET	 GPIOC_BA + 0x8
#define GPIOC_INTTYPE_CLR	 GPIOC_BA + 0x9
#define GPIOC_INTPOL_SET	 GPIOC_BA + 0xA
#define GPIOC_INTPOL_CLR	 GPIOC_BA + 0xB
#define GPIOC_INT	 	 GPIOC_BA + 0xC

/*********TIMER0*********/
#define TMR0_BA                0x2d00

#define TMR0_CTRL              TMR0_BA + 0x0
#define TMR0_CFG               TMR0_BA + 0x1
#define TMR0_PRDH              TMR0_BA + 0x2
#define TMR0_PRDM              TMR0_BA + 0x3
#define TMR0_PRDL              TMR0_BA + 0x4
#define TMR0_VALH              TMR0_BA + 0x5
#define TMR0_VALM              TMR0_BA + 0x6
#define TMR0_VALL              TMR0_BA + 0x7
#define TMR0_MSK               TMR0_BA + 0x8
#define TMR0_ST                TMR0_BA + 0x9

#define TMR1_CTRL              TMR0_BA + 0x20
#define TMR1_CFG               TMR0_BA + 0x21
#define TMR1_PRDH              TMR0_BA + 0x22
#define TMR1_PRDM              TMR0_BA + 0x23
#define TMR1_PRDL              TMR0_BA + 0x24
#define TMR1_VALH              TMR0_BA + 0x25
#define TMR1_VALM              TMR0_BA + 0x26
#define TMR1_VALL              TMR0_BA + 0x27
#define TMR1_MSK               TMR0_BA + 0x28
#define TMR1_ST                TMR0_BA + 0x29

#define TMR2_CTRL              TMR0_BA + 0x40
#define TMR2_CFG               TMR0_BA + 0x41
#define TMR2_PRDH              TMR0_BA + 0x42
#define TMR2_PRDM              TMR0_BA + 0x43
#define TMR2_PRDL              TMR0_BA + 0x44
#define TMR2_VALH              TMR0_BA + 0x45
#define TMR2_VALM              TMR0_BA + 0x46
#define TMR2_VALL              TMR0_BA + 0x47
#define TMR2_MSK               TMR0_BA + 0x48
#define TMR2_ST                TMR0_BA + 0x49


/*********IC*********/
#define INT_FIX_BA               0x3100

#define INT_FIX_CLR0             INT_FIX_BA + 0x0
#define INT_FIX_CLR1             INT_FIX_BA + 0x1
#define INT_FIX_CLR2             INT_FIX_BA + 0x2
#define INT_FIX_CLR3             INT_FIX_BA + 0x3

/*********FSM_WORK*********/
#define FSM_BA                 0x2c00

#define FSM_CTRL               FSM_BA + 0x0
#define FSM_PRD2               FSM_BA + 0x1
#define FSM_PRD1               FSM_BA + 0x2
#define FSM_PRD0               FSM_BA + 0x3

/*********DBG*********/
/*#define DBG_BA                   0x3200

#define DBG_CTRL                 DBG_BA + 0x0
#define DBG_ST                   DBG_BA + 0x4
#define DBG_ISR_L                DBG_BA + 0x8
#define DBG_ISR_H                DBG_BA + 0x9
#define DBG_BP1_L                DBG_BA + 0xc
#define DBG_BP1_H                DBG_BA + 0xd
#define DBG_BP2_L                DBG_BA + 0x10
#define DBG_BP2_H                DBG_BA + 0x11
#define DBG_BP3_L                DBG_BA + 0x14
#define DBG_BP3_H                DBG_BA + 0x15
#define DBG_BP4_L                DBG_BA + 0x18
#define DBG_BP4_H                DBG_BA + 0x19
#define DBG_LST_L                DBG_BA + 0x1c
#define DBG_LST_H                DBG_BA + 0x1d*/

/*********ANALOG_CFG*********/
#define ANALOG_CFG_BA            0x3300

#define ANALOG_O_BUF             ANALOG_CFG_BA + 0x0
#define ANALOG_O_PLL             ANALOG_CFG_BA + 0x1
#define ANALOG_O_RC              ANALOG_CFG_BA + 0x2
#define ANALOG_O_REF             ANALOG_CFG_BA + 0x3
#define ANALOG_O_DIV             ANALOG_CFG_BA + 0x4
#define ANALOG_O_IROM            ANALOG_CFG_BA + 0x5
#define ANALOG_O_RC_R            ANALOG_CFG_BA + 0x6
