;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Copyright (c) 2001-2002 TIMEX Corporation.
; 
; This document is the property of, and contains information
; proprietary to TIMEX Corporation.   It is to  be  returned
; upon request.  Reproduction by any means,  disclosure,  or
; use of its contents for other than the  expressed  purpose
; for which it is loaned, without  the  written  consent  of
; TIMEX Corporation, is strictly prohibited.
;
; File Name:            hweeprom.h
;
; Purpose:              Definitions for the EEPROM module
;
; Dependencies:         hw.h
;
; File Change History:  
;                       02/19/2002 RVD - Created file for the M851 
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  EEPROM communication pins redefinition
;  MCU=Master device - EEPROM=Slave device
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; I2C Interface definitions.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Control Byte Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Bit Definitions
;
; C C C C A A A R/
; 3 2 1 0 2 1 0 W
;
; 1 0 1 0 0 0 0 0 b      
; | | | | | | | |
; | | | | | | |  ------->   Read Or Write operation. 1 = Read; 0 = Write    
; | | | | | |  --------\
; | | | | |  ----------->   Chip Address. A2,A1,A0. This is set to 000, the default  
; | | | |  ------------/     address the chip when the A0-A2 pins are unconnected.
; | | |  --------------\
; | |  ----------------->   Control code. C3,C2,C1,C0. This is set to 1010 for
; |  ------------------->    24XX256 memory devices
;  --------------------/

HW_EE_I2C_CONTROL_CODE          EQU     10100000b       ; Control code for this family of part.     

HW_EE_ADDRESS                   EQU     00000000b       ; Internal default I2C address of the EEPROM.

HW_EE_WRITE_BIT                 EQU     11111110b       ; LSB is R/W control. 0 = Write
HW_EE_READ_BIT                  EQU     00000001b       ;                     1 = Read

; Write command 0A0h
HW_EE_CTRLBYTE_WR               EQU     (HW_EE_I2C_CONTROL_CODE|HW_EE_ADDRESS&HW_EE_WRITE_BIT)    
; Read command  0A1h
HW_EE_CTRLBYTE_RD               EQU     (HW_EE_I2C_CONTROL_CODE|HW_EE_ADDRESS|HW_EE_READ_BIT)     

HW_EEPROM_SDA                   EQU     InOutPortP00    ; Serial Data port.
bHW_EEPROM_SDA                  EQU     bP00            ; Serial Data pin. This is an 
                                                        ; input or output, depending on whether the 
                                                        ; Micro is transmitting or receiving.
HW_EEPROM_SDA_IO_CONTROL        EQU     P00Control      ; Serial Data Direction Control Port.
bHW_EEPROM_SDA_IO_CONTROL       EQU     bIOC00          ; Serial Data Direction Control Pin.
                                                        ;  1 = SDA is an output.
                                                        ;  0 = SDA is an input.
HW_EEPROM_SDA_PULL_UP_CONTROL   EQU     OutPortR0       ; SDA Pullup Control port.
bHW_EEPROM_SDA_PULL_UP_CONTROL  EQU     bR07            ; SDA Pullup Control pin.
                                                        ; A pull up resistor is necessary on the
                                                        ; SDA line. When the EEPROM is NOT powered
                                                        ; up, this line must be inactive (ie, pulled LOW).

HW_EEPROM_SCK                   EQU     OutPortR1       ; Serial Clock Port . 
bHW_EEPROM_SCK                  EQU     bR12            ; Serial Clock Pin.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   CONSTANTS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EEWRITECOMMAND                  EQU     HW_EE_CTRLBYTE_WR       ;control write command
EEREADCOMMAND                   EQU     HW_EE_CTRLBYTE_RD       ;control read command
CARRYBITCLEARED                 EQU     11111101b       ;carry bit of the SC flag is zero
CARRYBITSET                     EQU     00000010b       ;carry bit of the SC flag is 1


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; SPI Interface definitions.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


HWEEPROM_MISO                   EQU     InOutPortP00    ; Master In Slave Out port
bHWEEPROM_MISO                  EQU     bP00            ; this port is configured as an input
                                                        ; It is connected to SO EEPROM port
HWEEPROM_MISO_IO_CONTROL        EQU     P00Control   
bHWEEPROM_MISO_IO_CONTROL       EQU     bIOC00          ; in order to initiate the I/O port as 
                                                        ;  an input
                                                        ; Write 0 to insure that it is an input

HWEEPROM_MOSI                   EQU     OutPortR1       ; Master Out Slave In
bHWEEPROM_MOSI                  EQU     bR12            ; connected to SI EEPROM port

HWEEPROM_CS                     EQU     OutPortR1       ; Slave Chip Select
bHWEEPROM_CS                    EQU     bR13            ;  connected to !CS EEPROM port
                                                        
                                                        ; Note that !WP(wrtie protect) and
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Generic Interface definitions.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; EEPROM Power. 
; EEPROM requires up to 3mA of current when writing.
; Quiescent (standby) is up to 1uA. 

; This port uses 1 pin to provide power to the EEPROM by controling a transistor circuit.
HWEEPROM_POWER_UP               EQU     OutPortR1       ; EEPROM power control port. 
                                                    
bHWEEPROM_NOT_POWER_UP          EQU     bR10            ; EEPROM power control pin. 1 = EEPROM powered off.
                                                        ;                           0 = EEPROM powered on.
; This port uses 8 pins ganged together to provide power to the EEPROM.
HWEEPROM_POWER_UP_2             EQU     OutPortR2       ; EEPROM power control port. 
                                                        
bHWEEPROM_POWER_UP_2            EQU     (bR20|bR21|bR22|bR23|bR24|bR25|bR26|bR27) ; EEPROM power control pins. 

HWBITSPERBYTE                   EQU     8               ; Number of bits per byte, used for 
                                                        ; loop counter when reading/writing 
                                                        ; a byte to/from the EEPROM.

HWEEPROM_PAGESIZE_32            EQU     20H             ; Page size of EEPROM. 32 Byte.
                                                        ; Maximum amount of data that an be 
                                                        ; written to the EEPROM on one write cycle.

HWEEPROM_PAGEMASK_32            EQU     1FH             ; Mask used to force data addresses to conform
                                                        ; to page size of EEPROM for efficient 
                                                        ; writing.

HWEEPROM_PAGESIZE_64            EQU     40H             ; Page size of EEPROM. 32 Byte.
                                                        ; Maximum amount of data that an be 
                                                        ; written to the EEPROM on one write cycle.

HWEEPROM_PAGEMASK_64            EQU     3FH             ; Mask used to force data addresses to conform
                                                        ; to page size of EEPROM for efficient 
                                                        ; writing.

; Unused in current implementation.
HWEEPROM_PAGESIZE_128           EQU     80H             ; Page size of EEPROM. 64 Byte.
                                                        ; Maximum amount of data that an be 
                                                        ; written to the EEPROM on one write cycle.

HWEEPROM_PAGEMASK_128           EQU     7FH             ; Mask used to force data addresses to conform
                                                        ; to page size of EEPROM for efficient 
                                                        ; writing.
; EEPROM Default Size definition
HW_32K_BYTES_LO                 EQU     00
HW_32K_BYTES_HI                 EQU     80H