⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 i2cflash.asm

📁 cypress cy3721做的外部无线结点。感知温度后将温度值反给中心结点。
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: I2CFLASH.asm
;;  @Version@
;;  Generated by PSoC Designer ver 4.2  b1013 : 02 September, 2004
;;
;;  DESCRIPTION: I2CFLASH Low level driver
;;  
;;-----------------------------------------------------------------------------
;;  Copyright (c) Cypress MicroSystems 2003. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************
include "EzI2Cs.inc"
include "m8c.inc"
include "memory.inc"
include "i2cflash.inc"
include "SystemConst.inc"
include "flashblock.inc"

EzI2Cs_FLASH_ENABLE:     equ  TotalBlocksUsed           ; If Set Flash interface enabled
EzI2Cs_LARGE_FLASH:      equ  ((FlashSize & 0x8000)>>15); Set if Flash larger than 16K
EzI2Cs_FirstBlock:       equ  FirstConstBlock           ; First Flash blocke used
EzI2Cs_BlocksUsed:       equ  TotalBlocksUsed           ; Flash blocks used

EzI2Cs_blockId_2bytes:   equ  (FLASH_WRITE_STRUCT_SIZE - 7) ; Size of blockID (0/1 -> 1/2 bytes size)
EzI2Cs_ReadCount_2bytes: equ  (FLASH_READ_STRUCT_SIZE - EzI2Cs_blockId_2bytes - 4) ; Size of ReadCount (0/1 -> 1/2 bytes size)

// The following is only allowd if Flash programming
// is enabled.
IF (EzI2Cs_FLASH_ENABLE)

export    EzI2Cs_Execute_CMD


ENDIF




AREA InterruptRAM (RAM, REL, CON)

;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------



;-----------------------------------------------
;  EQUATES and TABLES
;-----------------------------------------------


STATE_WR_ROM_ADDR:  equ  0x08      ; Wait for Secondary address on write
STATE_RD_ROM:       equ  0x0A      ; Read ROM Data

STATE_WR_ROM:       equ  0x0C      ; Write ROM (Not supported at this time)

STATE_MASK:         equ  0x0E
STATE_MASK2:        equ  0x0F      ; State Mask

FLASH_MODE_FLAG:    equ  0x40      ; Set if in Flash mode.

I2C_FLASH_PAGE_OFFSET:   equ  0x00       // Zero except for 29xxx



;@PSoC_UserCode_INIT@ (Do not change this line.)
;---------------------------------------------------
; Insert your custom declarations below this banner
;---------------------------------------------------

;------------------------
;  Constant Definitions
;------------------------


;------------------------
; Variable Allocation
;------------------------


;---------------------------------------------------
; Insert your custom declarations above this banner
;---------------------------------------------------
;@PSoC_UserCode_END@ (Do not change this line.)




AREA UserModules (ROM, REL, CON)


IF (EzI2Cs_FLASH_ENABLE)

;-----------------------------------------------------------------------------
;  FUNCTION NAME: EzI2Cs_Execute_CMD
;
;  DESCRIPTION:
;     Execute flash command
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS: none
;
;  RETURNS:   0 => Invalid command or completed incorrectly
;             1 => Valid command and completed properly
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;  
;  Page and Block offset must be pre-defined
;  I2C_FLASH_PAGE_OFFSET          // Zero except for 29xxx
;  I2C_FLASH_BLOCK_OFFSET
;
;  * The caller of this function should look at the return value and ACK or NAK
;    the master accordingly.
;

 EzI2Cs_Execute_CMD:
_EzI2Cs_Execute_CMD:

IF (Enable_Flash_Interface)                                          ; Enable Flash interface code

    inc  [EzI2Cs_bROM_RWcntr]                                        ; Increment command counter.
    mov  A,[EzI2Cs_bROM_RWcntr]                                      ; Calculate command index.
    sub  A,[EzI2Cs_bROM_RWoffset] 
    cmp  A,0x01                                                      ; Check for command index of 1 (The command)
    jnz  .CHK_PARAM
    mov  A,reg[EzI2Cs_DR_REG]                                        ; Get "Command" value and save it.
    mov  [EzI2Cs_bFLASH_CMD ],A                                      ; Save in command register
    jmp  .ACK_CMD

.CHK_PARAM:
    cmp  A,0x02                                                      ; Check for command index of 2 (The Param)
    jnz  .NAK_CMD                                                ; Since index is not 1 or 2, invalid, NAK data
    mov  A,reg[EzI2Cs_DR_REG]                                        ; Get "Parameter" value and save it.
    mov  [EzI2Cs_bFLASH_Param ],A                                    ; Save in Parameter register

   // Check what mode we are operating in, normal or flash mode.
   // If in normal mode, jump down to .CK_NORMAL_MODE so to skip
   // checking for flash mode commands which are invalid in normal
   // mode.
   tst  [EzI2Cs_bState],FLASH_MODE_FLAG                              ; Check if in FLASH MODE
   jz   .CK_NORMAL_MODE

   // Get command
   // Verify command by checking write pointer, command, and parameter

   // Commands


   ;=================================================================
   ;   Read Block       
   ;=================================================================

.CK_ReadBlock_CMD:
   cmp  [EzI2Cs_bFLASH_CMD],I2C_FLASH_READ_BLOCK_CMD
   jnz  .CK_WriteBlock_CMD

   // Check for block range 0 to n  (Max n-1)
   mov  A,(EzI2Cs_BlocksUsed - 1)                                    ; Load block count -1
   sub  A,[EzI2Cs_bFLASH_Param]
   jc   .NAK_CMD                                                     ; Block index out of range

   mov  X,SP                                                         ; Get copy of current Stack location
   add  [EzI2Cs_bFLASH_Param],<EzI2Cs_FirstBlock                     ; Get offset of first block


;IF (EzI2Cs_LARGE_FLASH)
IF (EzI2Cs_blockId_2bytes)
   mov  A,>EzI2Cs_FirstBlock                                         ; Get MSB of FirstBlock
   adc  A,0x00                                                       ; Add with carry to complete MSB
   push A                                                            ; Store MSB of BlockID
ENDIF


   mov  A,[EzI2Cs_bFLASH_Param]                                      ; Move LSB of blockID to A           
   push A                                                            ; Save block ID

IF (SYSTEM_LARGE_MEMORY_MODEL)
   mov  A,[EzI2Cs_pRAM_Buf_Addr_MSB]                                 ; Save RAM buffer pointer MSB
ELSE
   mov  A,0x00
ENDIF

   push A
   mov  A,[EzI2Cs_pRAM_Buf_Addr_LSB]                                 ; Save RAM buffer pointer LSB
   push A

;IF (EzI2Cs_LARGE_FLASH)
IF (EzI2Cs_ReadCount_2bytes)
   mov  A,0  // 64 bytes, entire block
   push A
ENDIF

   mov  A,64  // 64 bytes, entire block
   push A

   // Setup parameters for call
   // LSB to structure is already in X
IF (SYSTEM_LARGE_MEMORY_MODEL)
   mov  A,reg[STK_PP]
ELSE
   mov  A,0x00     // Save MSB
ENDIF

   lcall FlashReadBlock
;IF (EzI2Cs_LARGE_FLASH)
;   add   SP,-6     // Fixup the stack
;ELSE
;   add   SP,-4     // Fixup the stack
;ENDIF
   add   SP,-FLASH_READ_STRUCT_SIZE 
   jmp  .ACK_CMD                                                     ; Command executed without errors.


   ;=================================================================
   ;   Write Block       
   ;=================================================================
.CK_WriteBlock_CMD:
   cmp  [EzI2Cs_bFLASH_CMD],I2C_FLASH_WRITE_BLOCK_CMD
   jnz  .CK_Reset_CMD
   // Check for block range 0 to n  (Max n-1)
   mov  A,(EzI2Cs_BlocksUsed - 1)                                    ; Load block count -1
   sub  A,[EzI2Cs_bFLASH_Param]
   jc   .NAK_CMD                                                     ; Block index out of range

   mov  X,SP                                                         ; Get copy of current Stack location
   add  [EzI2Cs_bFLASH_Param],<EzI2Cs_FirstBlock                     ; Get offset of first block

;IF (EzI2Cs_LARGE_FLASH)
IF (EzI2Cs_blockId_2bytes)
   mov  A,>EzI2Cs_FirstBlock                                         ; Get MSB of FirstBlock
   adc  A,0x00                                                       ; Add with carry to complete MSB
   push A                                                            ; Store MSB of BlockID
ENDIF

   mov  A,[EzI2Cs_bFLASH_Param]                                      ; Move LSB of blockID to A           
   push A                                                            ; Save block ID
   
IF (SYSTEM_LARGE_MEMORY_MODEL)
   mov  A,[EzI2Cs_pRAM_Buf_Addr_MSB]                                 ; Save RAM buffer pointer MSB
ELSE
   mov  A,0x00
ENDIF
   push A
   mov  A,[EzI2Cs_pRAM_Buf_Addr_LSB]                                 ; Save RAM buffer pointer LSB
   push A
   mov  A,I2C_FLASH_DEFAULT_TEMP                                     ; Use default temperature
   push A

   mov  A,0x55   // Three byte temp storage
   push A
   push A

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -