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

📄 spi_prog.psm

📁 利用Picoblaze实现对SPI flash的控制
💻 PSM
📖 第 1 页 / 共 5 页
字号:
                        CALL send_CR
                        LOAD UART_data, character_greater_than ;prompt for input
                        CALL send_to_UART
                        CALL read_upper_case
                        COMPARE s0, character_E                ;command test
                        JUMP Z, erase_command
                        COMPARE s0, character_S                ;command test
                        JUMP Z, sector_erase_command
                        COMPARE s0, character_P                ;command test
                        JUMP Z, program_command
                        COMPARE s0, character_R                ;command test
                        JUMP Z, read_command
                        COMPARE s0, character_I                ;command test
                        JUMP Z, ID_command
                        COMPARE s0, character_H                ;command test
                        JUMP Z, welcome_start
                        CALL send_CR                           ;no valid command input
                        LOAD UART_data, character_question     ;display ???
                        CALL send_to_UART
                        CALL send_to_UART
                        CALL send_to_UART
                        JUMP prompt                            ;Try again!
                        ;
                        ;
       read_upper_case: CALL read_from_UART                    ;read command character from UART
                        CALL send_to_UART                      ;echo character
                        LOAD s0, UART_data                     ;convert to upper case
                        CALL upper_case
                        RETURN
                        ;
                        ;**************************************************************************************
                        ;ID Command - Read and display the ID for the SPI FLASH memory
                        ;**************************************************************************************
                        ;
                        ;Normal response should be
                        ;   s9 = Manufacturer Identification = 20 hex
                        ;   s8 = Memory Type = 20 hex
                        ;   s7 = Memory Capacity = 15 hex
                        ;
            ID_command: CALL send_CR
                        CALL read_spi_flash_ID
                        CALL send_ID
                        LOAD UART_data, character_equals
                        CALL send_to_UART
                        CALL send_space
                        LOAD s0, s9
                        CALL send_hex_byte
                        CALL send_space
                        LOAD s0, s8
                        CALL send_hex_byte
                        CALL send_space
                        LOAD s0, s7
                        CALL send_hex_byte
                        CALL send_space
                        CALL send_CR
                        JUMP prompt
                        ;
                        ;**************************************************************************************
                        ;Erase Command - Perform bulk erase of the SPI FLASH memory and display messages
                        ;**************************************************************************************
                        ;
         erase_command: CALL send_CR
                        CALL send_Confirm                      ;confirm command with a 'Y' which must be upper case
                        CALL read_from_UART                    ;read command character from UART
                        CALL send_to_UART                      ;echo input
                        COMPARE UART_data, character_Y
                        JUMP NZ, abort_erase
                        CALL send_CR
                        CALL send_Erase_in_progress
                        CALL bulk_erase_spi
                        CALL send_OK
                        JUMP prompt
                        ;
           abort_erase: CALL send_Abort
                        JUMP prompt
                        ;
                        ;
                        ;**************************************************************************************
                        ;Sector Erase Command - Performs erase of lowest 5 sectors SPI FLASH memory which
                        ;covers the address range 000000 to 04FFFF in which the configuration for an XC3S500E
                        ;would be able to fit.
                        ;**************************************************************************************
                        ;
  sector_erase_command: CALL send_CR
                        CALL send_Confirm                      ;confirm command with a 'Y' which must be upper case
                        CALL read_from_UART                    ;read command character from UART
                        CALL send_to_UART                      ;echo input
                        COMPARE UART_data, character_Y
                        JUMP NZ, abort_erase
                        CALL send_CR
                        CALL send_Erase_in_progress
                        LOAD s9, 00                            ;any address inside sector 0
                        CALL erase_spi_sector
                        LOAD s9, 01                            ;any address inside sector 1
                        CALL erase_spi_sector
                        LOAD s9, 02                            ;any address inside sector 2
                        CALL erase_spi_sector
                        LOAD s9, 03                            ;any address inside sector 3
                        CALL erase_spi_sector
                        LOAD s9, 04                            ;any address inside sector 4
                        CALL erase_spi_sector
                        CALL send_OK
                        JUMP prompt
                        ;
                        ;
                        ;**************************************************************************************
                        ;Program Command - Program SPI FLASH memory with MCS file
                        ;**************************************************************************************
                        ;
       program_command: CALL send_CR
                        CALL send_Waiting_MCS_file
                        CALL program_MCS
                        CALL send_OK
                        JUMP prompt
                        ;
                        ;
                        ;**************************************************************************************
                        ;Read Command - Read one page of memory at specified address
                        ;**************************************************************************************
                        ;
          read_command: CALL send_page_address                 ;obtain 24-bit address
                        CALL obtain_8bits
                        JUMP C, read_command                   ;bad input address
                        COMPARE s0, 20                         ;test for address greater than 1FFFFF
                        JUMP NC, read_command                  ;value too big
                        LOAD s9, s0
                        CALL obtain_8bits
                        JUMP C, read_command                   ;bad input address
                        LOAD s8, s0
                        CALL obtain_8bits
                        JUMP C, read_command                   ;bad input address
                        LOAD s7, s0
                        CALL send_CR
                        CALL send_spi_page
                        CALL send_OK
                        JUMP prompt
          obtain_8bits: CALL read_upper_case                   ;obtain one byte from UART
                        LOAD s3, s0
                        CALL read_upper_case
                        LOAD s2, s0
                        CALL ASCII_byte_to_hex
                        RETURN
                        ;
                        ;
                        ;
                        ;**************************************************************************************
                        ;Program SPI FLASH with MCS file
                        ;**************************************************************************************
                        ;
                        ;Reads the MCS file from the UART and programs the SPI FLASH device at the locations.
                        ;specified by the file contents.
                        ;
                        ;One important factor of programming the SPI FLASH for use as configuration
                        ;memory is that the bits within each byte must be in reverse order. This
                        ;is because an SPI device outputs data MSB first compared with a Xilinx
                        ;serial PROM which outputs LSB first. Therefore this routine will swap
                        ;the bits of each byte provided by the MCS file before programming.
                        ;
                        ;This routine will continue until an end of file record is detected.
                        ;For each line of MCS received, the current address will be output so that
                        ;progress can be monitored.
                        ;
                        ;Register sA is used to remember if a page is currently open (01) or closed (00)
                        ;for writing on the SPI memory.
                        ;
           program_MCS: LOAD sA, 00                            ;page is closed
        next_prog_line: CALL read_MCS_line                     ;read line
                        CALL MCS_address                       ;find start address and record type
                        COMPARE sB, 01                         ;test for end record
                        JUMP Z, end_program_MCS
                        CALL send_hex_3bytes                   ;send address for other lines
                        CALL send_CR
                        COMPARE sB, 04                         ;test for extended address record
                        JUMP Z, MCS_address_boundary
                        ;
                        ;Assume data record type 00 now and program SPI page
                        ;
                        SUB sE, 01                             ;location of checksum just after last stored data byte
                        LOAD sD, line_start                    ;Point to first data byte
                        ADD sD, 04
                        COMPARE sA, 00                         ;check if page is closed
                        JUMP Z, program_byte                   ;jump if page needs to be opened
                        FETCH s2, page_address_h               ;check new address is sequential
                        COMPARE s2, s9
                        JUMP NZ, addr_out_of_sequence
                        FETCH s2, page_address_m               ;check new address is sequential
                        COMPARE s2, s8
                        JUMP NZ, addr_out_of_sequence
                        FETCH s2, page_address_l               ;check new address is sequential
                        COMPARE s2, s7
                        JUMP Z, program_byte                   ;continue with open page
  addr_out_of_sequence: CALL close_prog_page_spi               ;close page because address out of sequence
                        LOAD sA, 00                            ;page is now closed
          program_byte: COMPARE sA, 00                         ;check if page is closed
                        JUMP NZ, page_is_open                  ;jump is page already open
                        CALL open_prog_page_spi                ;open page with address [s9,s8,s7]
                        LOAD sA, 01                            ;page is open
          page_is_open: FETCH s1, (sD)                         ;fetch data byte
                        LOAD s0, 08                            ;reverse order of bits
             swap_bits: SR0 s1
                        SLA s2
                        SUB s0, 01
                        JUMP NZ, swap_bits                     ;swapped bits now in s2
                        CALL SPI_FLASH_tx_rx                   ;program byte into SPI memory
                        ADD s7, 01                             ;increment address to keep track
                        ADDCY s8, 00
                        ADDCY s9, 00
                        COMPARE s7, 00                         ;test if crossing page boundary FF to 00
                        JUMP NZ, byte_programmed
                        CALL close_prog_page_spi
                        LOAD sA, 00                            ;page is now closed
       byte_programmed: ADD sD, 01                             ;move to next byte

⌨️ 快捷键说明

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