Difference Analysis Generated by HtmlDiff on 10/26/2004 1:34 PM  

Base file: C:\CY4632_RDK_1_21\Firmware\Source Code\RDK Bridge\E2.asm

Modified file: C:\CY4632_RDK_1_3\Firmware\Source Code\RDK Bridge\E2.asm

;****************************************************************************
;
;   file:           E2.asm
;   Description:    This file contains Spi functions for the Serial EEPROM
;   External Functions:
;                   E2_WriteByte
;                   E2_ReadByte
;                   E2_get_bind_parms
;                   E2_put_bind_parms
;                   E2_get_device_id
;                   E2_put_device_id
;
;   Target:         Cypress CY7C63723/CY7C63743 Encore Chips
;   $Header:
;   Version:        1.3.0000
;
;****************************************************************************
; Copyright (2003), Cypress Semiconductor Corporation
; This software is owned by Cypress Semiconductor Corporation (Cypress) and  is
; protected by United States copyright laws and international treaty provisions.
; Cypress hereby grants to Licensee a personal, non-exclusive, non-transferable
; license to copy, use, modify, create derivative works of, and compile the
; Cypress Source Code and derivative works for the sole purpose of creating
; custom software in support of Licensee product ("Licensee Product") to be used
; only in conjunction with a Cypress integrated circuit. Any reproduction,
; modification, translation, compilation, or representation of this software
; except as specified above is prohibited without the express written permission
; of Cypress.
; Disclaimer: Cypress makes no warranty of any kind, express or implied, with
; regard to this material, including, but not limited to, the implied warranties
; of merchantability and fitness for a particular purpose. Cypress reserves the
; right to make changes without further notice to the materials described herein.
; Cypress does not assume any liability arising out of the application or use of
; any product or circuit described herein. Cypress’ products described herein are
; not authorized for use as components in life-support devices.
; This software is protected by and subject to worldwide patent coverage,
; including U.S. and foreign patents. Use may be limited by and subject to the
; Cypress Software License Agreement.
;
;****************************************************************************

;-------------------------------------------------------
; Serial EEPROM Defines
;-------------------------------------------------------

; E2 Spi default = SPIMaster, 2Mb/s, CPHA=1
SPI_CONTROL_E2_RESET:       equ (MODE0|CPHA)

E2_BIND_LOC:                equ 00
E2_ID_1_LOC:                equ 10h
E2_ID_2_LOC:                equ 14h

; Normal LS Spi default
SPI_CONTROL_RESET:          equ (MODE0 | CPHA)

; P0.2: E2 Chip Select bit
BIT_SPI_E2_CS:              equ 04h
; E2 Signature byte at E2 address 0 indicates E2 has valid data
E2_SIGNATURE_BYTE:          equ 92h     ; 92 means valid 2-way data, 91 is valid 1-way data

AT250X0_WREN_OPCODE:        equ 06h
AT250X0_WRDI_OPCODE:        equ 04h
AT250X0_RDSR_OPCODE:        equ 05h
AT250X0_WRSR_OPCODE:        equ 01h

; Note: AT25010 does not use 9th bit of address
AT250X0_RD_OPCODE:          equ 03h
AT250X0_WR_OPCODE:          equ 02h


AT250X0_STAT_BUSY:          equ 01h
AT250X0_STAT_WREN:          equ 02h

;-------------------------------------------------------
; E2_Activate_CS_Select
;-------------------------------------------------------
E2_Activate_CS_Select:

    MOV   A,BIT_SPI_E2_CS           ;port0Shadow |= BIT_SPI_E2_CS;
    OR    [port0Shadow],A
    MOV   A,[port0Shadow]           ;port0 = port0Shadow;
    IOWR  port0
    RET

;-------------------------------------------------------
; E2_DeActivate_CS_Select
;-------------------------------------------------------
E2_DeActivate_CS_Select:

    MOV   A,~BIT_SPI_E2_CS          ;port0Shadow &= ~BIT_SPI_E2_CS;
    AND   [port0Shadow],A
    MOV   A,[port0Shadow]           ;port0 = port0Shadow;
    IOWR  port0
    RET

;-------------------------------------------------------
; E2_PendSPIByte
;
; This function is called after writing to the spi_data register.
; This waits for Encore Master AND  E2 Slave to complete Spi byte exchange.
; Output byte from E2 Slave remains in spi_data register afterwards.
;-------------------------------------------------------
E2_PendSPIByte:

    IORD  spi_control               ;while(!(spi_control & TCMP_C));
    AND   A,80h
    JZ    E2_PendSPIByte
    MOV   A,SPI_CONTROL_E2_RESET    ;spi_control = SPI_CONTROL_E2_RESET;
    IOWR  spi_control
    RET

;-------------------------------------------------------
; E2_ReadByte_status
;-------------------------------------------------------
E2_ReadByte_status :

    CALL  E2_DeActivate_CS_Select

    ; Write AT250X0_RDSR_OPCODE to E2 SPI
    MOV   A,AT250X0_RDSR_OPCODE     ;spi_data = AT250X0_RDSR_OPCODE;
    IOWR  spi_data
    CALL  E2_PendSPIByte

    ; Pump an FF to read result
    MOV   A,FFh                     ;spi_data = 0xFF;
    IOWR  spi_data
    CALL  E2_PendSPIByte

    JMP   E2_Activate_CS_Select


;-------------------------------------------------------
; E2_WaitForRDY
; Pend on prior write operation
;-------------------------------------------------------
E2_WaitForRDY:
                                    ;do{
    CALL  E2_ReadByte_status
    IORD  spi_data                  ;}while(spi_data & AT250X0_STAT_BUSY);
    AND   A,AT250X0_STAT_BUSY
    JNZ   E2_WaitForRDY
    RET

;-------------------------------------------------------
; E2_ReadByte
;
; Input:
; X Reg = Address of an E2 byte to be read
;
; Processing:
; AT25010 data byte is read over SPI bus
;
; Output:
; spi_data reg = data byte for calling app
;
; Usage:
; Calling app should assign spi_data to destination after return
; Example:
; for(i=0; i<MAX_E2_BYTES; i++)
; {
;   X = i;                      ; Input var E2 address
;   E2_ReadByte();
;   E2ByteInBuff[i] = spi_data ; Output E2 Data Byte
; }
;-------------------------------------------------------
E2_ReadByte :
    ; set CPHA for E2
    MOV   A,SPI_CONTROL_E2_RESET    ;spi_control = SPI_CONTROL_E2_RESET;
    IOWR  spi_control

    CALL  E2_DeActivate_CS_Select

    ; Send Read command
    MOV   A,AT250X0_RD_OPCODE       ;spi_data = AT250X0_RD_OPCODE;
    IOWR  spi_data
    CALL  E2_PendSPIByte

    ; Send read address
    SWAP  A,X                       ;spi_data = X;
    IOWR  spi_data
    SWAP  A,X
    CALL  E2_PendSPIByte

    ; Pump an FF to read data
    MOV   A,FFh                     ;spi_data = 0xFF;
    IOWR  spi_data
    CALL  E2_PendSPIByte

    ; Note: Data byte from E2 is now in spi_data

    CALL  E2_Activate_CS_Select

    ; leave CPHA the way LS Spi likes it
    MOV   A,SPI_CONTROL_RESET       ;spi_control = SPI_CONTROL_RESET;
    IOWR  spi_control

    IORD spi_data
    RET

;-------------------------------------------------------
; E2_WriteByte
;
; Input:
; X Reg = Write address of an E2 byte
; A Reg = Data Byte value to write
;
; Processing:
; AT25010 data byte write over SPI bus
;
; Output: None
;
; Example:
; for(i=0; i<MAX_E2_BYTES; i++)
; {
;   X = i;                    ; Input var E2 address
;   A = E2ByteOutBuff[i];     ; Input var write byte
;   E2_WriteByte();
; }
; Note: X Reg should be saved on entry if X is used (not currently necessary)
;-------------------------------------------------------
E2_WriteByte :

    ; Save input parameters
    PUSH  A

    ; Set CPHA for E2
    MOV   A,SPI_CONTROL_E2_RESET    ;spi_control = SPI_CONTROL_E2_RESET;
    IOWR  spi_control

    CALL  E2_WaitForRDY

    ; Set Write Enable bit
    CALL  E2_DeActivate_CS_Select
    MOV   A,AT250X0_WREN_OPCODE     ;spi_data = AT250X0_WREN_OPCODE;
    IOWR  spi_data
    CALL  E2_PendSPIByte
    CALL  E2_Activate_CS_Select

    CALL  E2_ReadByte_status 
    IORD  spi_data

    CALL  E2_DeActivate_CS_Select

    ; Send Write command
    MOV   A,AT250X0_WR_OPCODE       ;spi_data = AT250X0_WR_OPCODE;
    IOWR  spi_data
    CALL  E2_PendSPIByte

    ; Send write address
    SWAP  A,X                       ;spi_data = X;
    IOWR  spi_data
    SWAP  A,X
    CALL  E2_PendSPIByte

    ; Send data byte
    POP   A
    IOWR  spi_data                  ;spi_data = A;
    CALL  E2_PendSPIByte

    CALL  E2_Activate_CS_Select

    ; Complete before exiting
    CALL  E2_WaitForRDY

    CALL  E2_DeActivate_CS_Select
    ; Set Write Disable
    MOV   A,AT250X0_WRDI_OPCODE     ;spi_data = AT250X0_WRDI_OPCODE;
    IOWR  spi_data
    CALL  E2_PendSPIByte
    CALL  E2_Activate_CS_Select

    ; leave CPHA the way LS Spi likes it
    MOV   A,SPI_CONTROL_RESET       ;spi_control = SPI_CONTROL_RESET;
    IOWR  spi_control
    RET

;-------------------------------------------------------
; E2_get_bind_parms
;
; Input:
; NVParms = Channel, PN Code, etc.
;
; Processing:
; NVParms are retrieved from the Serial EEPROM
;
; Output:
; A reg == 0 ==> Valid NVParms
;
;-------------------------------------------------------
E2_get_bind_parms:

    MOV   X,E2_BIND_LOC             ; IParm E2 address
    CALL  E2_ReadByte
    ;IORD  spi_data                  ; if(spi_data == E2_SIGNATURE_BYTE) 
    CMP   A,E2_SIGNATURE_BYTE
    JNZ   .InValidNVParms   
        
    INC   X
    CALL  E2_ReadByte
    ;IORD  spi_data                  ; channel = spi_data;
    MOV   [channel],A
    INC   X
    CALL  E2_ReadByte
    ;IORD  spi_data                  ; codepos_a = spi_data;
    MOV   [pn_code],A
    MOV   A,00h                     ; Return A = 0;
    RET
    
.InValidNVParms:
    MOV   A,01h                     ; Return A = 1;
    RET

;-------------------------------------------------------
; E2_put_bind_parms
;
; Processing:
; NVParms are stored on the Serial EEPROM
; An E2 Signature byte is written at E2 address 0
;
;-------------------------------------------------------
E2_put_bind_parms:

    MOV   X,E2_BIND_LOC                     ; IParm E2 address
    MOV   A,E2_SIGNATURE_BYTE       ; A = E2_SIGNATURE_BYTE;
    CALL  E2_WriteByte
    INC   X
    MOV   A,[channel]               ; A = channel;
    CALL  E2_WriteByte
    INC   X
    MOV   A,[pn_code]               ; A = codepos_a;
    CALL  E2_WriteByte
    
    RET

;-------------------------------------------------------
;
;   E2_get_device_id
;
;   Reads manufacturing ID from NVRAM
;   AND  stores it in the reg_data buffer.
;   A determines the storage location
;-------------------------------------------------------
E2_get_device_id:
    AND  A, ffh
    JNZ  E2_get_id_2_init
    
    ; set the location
E2_get_id_1_init:
    MOV  X, E2_ID_1_LOC
    JMP  E2_get_id
    
E2_get_id_2_init:
    MOV  X, E2_ID_2_LOC

    ; read the Manufacturing ID
E2_get_id:
    CALL  E2_ReadByte
    ;IORD  spi_data              
    MOV   [reg_data],A
    INC   X
    CALL  E2_ReadByte
    ;IORD  spi_data              
    MOV   [reg_data+1],A
    INC   X
    CALL  E2_ReadByte
    ;IORD  spi_data              
    MOV   [reg_data+2],A
    INC   X
    CALL  E2_ReadByte
    ;IORD  spi_data              
    MOV   [reg_data+3],A

    RET


;-------------------------------------------------------
;
;   E2_put_device_id
;
;   Stores the manufacturing ID in NVRAM
;   A determines the storage location
;-------------------------------------------------------
E2_put_device_id:
    AND  A, ffh
    JNZ  E2_put_id_2_init
        
    ; set the location
E2_put_id_1_init:
    MOV  X, E2_ID_1_LOC
    JMP  E2_put_id
    
E2_put_id_2_init:
    MOV  X, E2_ID_2_LOC

    ; store the Manufacturing ID
E2_put_id:
    MOV  A, [rx_buffer+10]
    CALL  E2_WriteByte
    INC   X
    MOV  A, [rx_buffer+11]
    CALL  E2_WriteByte
    INC   X
    MOV  A, [rx_buffer+12]
    CALL  E2_WriteByte
    INC   X
    MOV  A, [rx_buffer+13]
    CALL  E2_WriteByte

    RET


;-------------------------------------------------------
;   endfile:       E2.asm
;-------------------------------------------------------