spi_prog.rmh
来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,531 行 · 第 1/5 页
RMH
1,531 行
// #367: ;is because an SPI device outputs data MSB first compared with a Xilinx// #368: ;serial PROM which outputs LSB first. Therefore this routine will swap// #369: ;the bits of each byte provided by the MCS file before programming.// #370: ;// #371: ;This routine will continue until an end of file record is detected.// #372: ;For each line of MCS received, the current address will be output so that// #373: ;progress can be monitored.// #374: ;// #375: ;Register sA is used to remember if a page is currently open (01) or closed (00)// #376: ;for writing on the SPI memory.// #377: ;// @06f #378: [program_MCS]00a00 // @06f #378: LOAD(sA,0) ;page is closed// @070 #379: [next_prog_line]300a9 // @070 #379: CALL(read_MCS_line) ;read line300b9 // @071 #380: CALL(MCS_address) ;find start address and record type14b01 // @072 #381: COMPARE(sB,1) ;test for end record350a5 // @073 #382: JUMP(Z,end_program_MCS)301fd // @074 #383: CALL(send_hex_3bytes) ;send address for other lines3021d // @075 #384: CALL(send_CR)14b04 // @076 #385: COMPARE(sB,4) ;test for extended address record350a1 // @077 #386: JUMP(Z,MCS_address_boundary)// #387: ;// #388: ;Assume data record type 00 now and program SPI page// #389: ;1ce01 // @078 #390: SUB(sE,1) ;location of checksum just after last stored data byte00d2b // @079 #391: LOAD(sD,line_start) ;Point to first data byte18d04 // @07a #392: ADD(sD,4)14a00 // @07b #393: COMPARE(sA,0) ;check if page is closed35088 // @07c #394: JUMP(Z,program_byte) ;jump if page needs to be opened06201 // @07d #395: FETCH(s2,page_address_h) ;check new address is sequential15290 // @07e #396: COMPARE(s2,s9)35486 // @07f #397: JUMP(NZ,addr_out_of_sequence)06202 // @080 #398: FETCH(s2,page_address_m) ;check new address is sequential15280 // @081 #399: COMPARE(s2,s8)35486 // @082 #400: JUMP(NZ,addr_out_of_sequence)06203 // @083 #401: FETCH(s2,page_address_l) ;check new address is sequential15270 // @084 #402: COMPARE(s2,s7)35088 // @085 #403: JUMP(Z,program_byte) ;continue with open page// @086 #404: [addr_out_of_sequence]3018f // @086 #404: CALL(close_prog_page_spi) ;close page because address out of sequence00a00 // @087 #405: LOAD(sA,0) ;page is now closed// @088 #406: [program_byte]14a00 // @088 #406: COMPARE(sA,0) ;check if page is closed3548c // @089 #407: JUMP(NZ,page_is_open) ;jump is page already open30181 // @08a #408: CALL(open_prog_page_spi) ;open page with address [s9,s8,s7]00a01 // @08b #409: LOAD(sA,1) ;page is open// @08c #410: [page_is_open]071d0 // @08c #410: FETCH(s1,sD) ;fetch data byte00008 // @08d #411: LOAD(s0,8) ;reverse order of bits// @08e #412: [swap_bits]2010e // @08e #412: SR0(s1)20200 // @08f #413: SLA(s2)1c001 // @090 #414: SUB(s0,1)3548e // @091 #415: JUMP(NZ,swap_bits) ;swapped bits now in s230112 // @092 #416: CALL(SPI_FLASH_tx_rx) ;program byte into SPI memory18701 // @093 #417: ADD(s7,1) ;increment address to keep track1a800 // @094 #418: ADDCY(s8,0)1a900 // @095 #419: ADDCY(s9,0)14700 // @096 #420: COMPARE(s7,0) ;test if crossing page boundary FF to 003549a // @097 #421: JUMP(NZ,byte_programmed)3018f // @098 #422: CALL(close_prog_page_spi)00a00 // @099 #423: LOAD(sA,0) ;page is now closed// @09a #424: [byte_programmed]18d01 // @09a #424: ADD(sD,1) ;move to next byte15de0 // @09b #425: COMPARE(sD,sE) ;check for last on line35488 // @09c #426: JUMP(NZ,program_byte) ;fetch next byte to program2e901 // @09d #427: STORE(s9,page_address_h) ;remember next address in sequence2e802 // @09e #428: STORE(s8,page_address_m)2e703 // @09f #429: STORE(s7,page_address_l)34070 // @0a0 #430: JUMP(next_prog_line) ;read next line for programming// @0a1 #431: [MCS_address_boundary]14a00 // @0a1 #431: COMPARE(sA,0) ;check if page needs to be closed35070 // @0a2 #432: JUMP(Z,next_prog_line)3018f // @0a3 #433: CALL(close_prog_page_spi)3406f // @0a4 #434: JUMP(program_MCS)// @0a5 #435: [end_program_MCS]14a00 // @0a5 #435: COMPARE(sA,0) ;check if page needs to be closed2b000 // @0a6 #436: RETURN(Z)3018f // @0a7 #437: CALL(close_prog_page_spi)2a000 // @0a8 #438: RETURN// #439: ;// #440: ;**************************************************************************************// #441: ;Read one line of an MCS file into scratch pad memory// #442: ;**************************************************************************************// #443: ;// #444: ;Reads one line of MCS file format into scratch pad memory starting at location 'line_start'.// #445: ;// #446: ;The routine detects the line start character ':' ignoring any preceding characters. This// #447: ;will remove any additional CR or LF characters.// #448: ;// #449: ;It then reads each subsequent pair of ASCII characters, converts them to true hex in the// #450: ;range 00 to FF and stores them in scratch pad memory.// #451: ;// #452: ;The end of the line is determined by either a CR or LF character.// #453: ;// #454: ;The value last returned in register 'sE' will be the pointer to the location in// #455: ;scratch pad memory following the last byte for the line read.// #456: ;// @0a9 #457: [read_MCS_line]00e2b // @0a9 #457: LOAD(sE,line_start) ;initialise SPM memory pointer// @0aa #458: [wait_MCS_line_Start]301af // @0aa #458: CALL(read_from_UART) ;read character14f3a // @0ab #459: COMPARE(UART_data,character_colon) ;test for start character354aa // @0ac #460: JUMP(NZ,wait_MCS_line_Start)// @0ad #461: [read_MCS_byte]301af // @0ad #461: CALL(read_from_UART) ;read character14f0d // @0ae #462: COMPARE(UART_data,character_CR) ;test for end of line2b000 // @0af #463: RETURN(Z)14f0a // @0b0 #464: COMPARE(UART_data,character_LF) ;test for end of line2b000 // @0b1 #465: RETURN(Z)013f0 // @0b2 #466: LOAD(s3,UART_data) ;upper nibble character301af // @0b3 #467: CALL(read_from_UART) ;read character012f0 // @0b4 #468: LOAD(s2,UART_data) ;lower nibble character30204 // @0b5 #469: CALL(ASCII_byte_to_hex) ;convert to true hex value2f0e0 // @0b6 #470: STORE(s0,sE) ;write to SPM18e01 // @0b7 #471: ADD(sE,1) ;increment pointer340ad // @0b8 #472: JUMP(read_MCS_byte)// #473: ;// #474: ;// #475: ;**************************************************************************************// #476: ;Determine the current address for the line of an MCS file in scratch pad memory// #477: ;**************************************************************************************// #478: ;// #479: ;Checks the existing line data stored in scratch pad memory starting at location// #480: ;'line_start' and determines the current address.// #481: ;// #482: ;The address is in the register set [s9,s8,s7] before and after this routine is// #483: ;executed because not all address bits are defined by a given line of MCS and// #484: ;the undefined bits remain constant.// #485: ;// #486: ;A record type of 04 will update [s9].// #487: ;A record type of 00 will update [s8,s7].// #488: ;// #489: ;On return, the register sB will contain the record type and// #490: ;register sC will indicate the number of data bytes stored.// #491: ;// @0b9 #492: [MCS_address]00d2b // @0b9 #492: LOAD(sD,line_start) ;initialise SPM memory pointer07cd0 // @0ba #493: FETCH(sC,sD) ;read number of bytes on line18d03 // @0bb #494: ADD(sD,3) ;move to record type07bd0 // @0bc #495: FETCH(sB,sD) ;read record type14b00 // @0bd #496: COMPARE(sB,0) ;test for data record350c4 // @0be #497: JUMP(Z,new_low_address)14b04 // @0bf #498: COMPARE(sB,4) ;test for data record2b400 // @0c0 #499: RETURN(NZ)18d02 // @0c1 #500: ADD(sD,2) ;read upper 8-bits079d0 // @0c2 #501: FETCH(s9,sD)2a000 // @0c3 #502: RETURN// @0c4 #503: [new_low_address]1cd01 // @0c4 #503: SUB(sD,1) ;read lower 8-bits077d0 // @0c5 #504: FETCH(s7,sD)1cd01 // @0c6 #505: SUB(sD,1) ;read middle 8-bits078d0 // @0c7 #506: FETCH(s8,sD)2a000 // @0c8 #507: RETURN// #508: ;// #509: ;**************************************************************************************// #510: ;Read a page from SPI FLASH memory and display// #511: ;**************************************************************************************// #512: ;// #513: ;The start address should be provided in register set [s9,s8,s7].// #514: ;The display will be next 256 bytes displayed as 16 lines of 16 bytes// #515: ;with each line commencing with the address of the first byte.// #516: ;// #517: ;// @0c9 #518: [send_spi_page]00610 // @0c9 #518: LOAD(s6,16) ;16 lines to display// @0ca #519: [send_spi_line]3021d // @0ca #519: CALL(send_CR)301fd // @0cb #520: CALL(send_hex_3bytes) ;display address30220 // @0cc #521: CALL(send_space)00510 // @0cd #522: LOAD(s5,16) ;16 lines to display// @0ce #523: [send_spi_byte]30220 // @0ce #523: CALL(send_space)3014e // @0cf #524: CALL(read_spi_byte) ;read byte into s218701 // @0d0 #525: ADD(s7,1) ;increment SPI FLASH address1a800 // @0d1 #526: ADDCY(s8,0)1a900 // @0d2 #527: ADDCY(s9,0)01020 // @0d3 #528: LOAD(s0,s2) ;display byte301f7 // @0d4 #529: CALL(send_hex_byte)1c501 // @0d5 #530: SUB(s5,1) ;count bytes per line354ce // @0d6 #531: JUMP(NZ,send_spi_byte)1c601 // @0d7 #532: SUB(s6,1) ;count lines354ca // @0d8 #533: JUMP(NZ,send_spi_line)3021d // @0d9 #534: CALL(send_CR)2a000 // @0da #535: RETURN// #536: ;// #537: ;**************************************************************************************// #538: ;Test of SPI FLASH memory operations// #539: ;**************************************************************************************// #540: ;// #541: ;Sector 18 (120000 to 12FFFF) is used.// #542: ;A page (123400 to 1234FF) is programmed with a test pattern 00 to FF.// #543: ;The pattern is verified and then the sector erased and a blank check performed.// #544: ;// #545: ;Note that the page used is already blank (all locations contain FF hex)// #546: ;as with any device supplied (initial delivery state).// #547: ;// #548: ;Program page with test pattern// #549: ;// @0db #550: [memory_test]00912 // @0db #550: LOAD(s9,18) ;select page address 12340000834 // @0dc #551: LOAD(s8,52)00700 // @0dd #552: LOAD(s7,0)30181 // @0de #553: CALL(open_prog_page_spi) ; program test pattern 00 to FF// @0df #554: [pattern_loop]01270 // @0df #554: LOAD(s2,s7)30112 // @0e0 #555: CALL(SPI_FLASH_tx_rx)18701 // @0e1 #556: ADD(s7,1)35cdf // @0e2 #557: JUMP(NC,pattern_loop)3018f // @0e3 #558: CALL(close_prog_page_spi) ; program test pattern 00 to FF// #559: ;// #560: ;Verify test pattern by reading back page// #561: ;00f70 // @0e4 #562: LOAD(UART_data,character_p) ;p for pass00912 // @0e5 #563: LOAD(s9,18) ;select page address 12340000834 // @0e6 #564: LOAD(s8,52)00700 // @0e7 #565: LOAD(s7,0)// @0e8 #566: [verify_test_page]3014e // @0e8 #566: CALL(read_spi_byte) ;read byte into s215270 // @0e9 #567: COMPARE(s2,s7) ;check test pattern data value354ee // @0ea #568: JUMP(NZ,memory_verify_fail)18701 // @0eb #569: ADD(s7,1) ;next location354e8 // @0ec #570: JUMP(NZ,verify_test_page) ;loop until roll over page340ef // @0ed #571: JUMP(memory_verify_result)// @0ee #572: [memory_verify_fail]00f66 // @0ee #572: LOAD(UART_data,character_f) ;f for fail// @0ef #573: [memory_verify_result]301c1 // @0ef #573: CALL(send_to_UART)2a000 // @0f0 #574: RETURN// #575: ;// #576: ;Erase sector with test pattern and verify blank// #577: ;// @0f1 #578: [erase_test_sector]00912 // @0f1 #578: LOAD(s9,18) ;sector 18 start address 12000000800 // @0f2 #579: LOAD(s8,0)00700 // @0f3 #580: LOAD(s7,0)3015f // @0f4 #581: CALL(erase_spi_sector)00f70 // @0f5 #582: LOAD(UART_data,character_p) ;p for pass00912 // @0f6 #583: LOAD(s9,18) ;select page address 12340000834 // @0f7 #584: LOAD(s8,52)00700 // @0f8 #585: LOAD(s7,0)// @0f9 #586: [verify_blank_page]3014e // @0f9 #586: CALL(read_spi_byte) ;read byte into s2142ff // @0fa #587: COMPARE(s2,FF) ;check blank 'FF'354ff // @0fb #588: JUMP(NZ,memory_blank_fail)18701 // @0fc #589: ADD(s7,1) ;next location354f9 // @0fd #590: JUMP(NZ,verify_blank_page) ;loop until roll over page34100 // @0fe #591: JUMP(memory_blank_result)// @0ff #592: [memory_blank_fail]00f66 // @0ff #592: LOAD(UART_data,character_f) ;f for fail// @100 #593: [memory_blank_result]301c1 // @100 #593: CALL(send_to_UART)2a000 // @101 #594: RETURN// #595: ;// #596: ;// #597: ;// #598: ;**************************************************************************************// #599: ;Test of SPI FLASH memory communications// #600: ;**************************************************************************************// #601: ;Link must be installed in J11 to link ROM-CS to CSO_B// #602: ;// #603: ;Read the identification ID from SPI FLASH memory (ST type M25P16)// #604: ;and compare with expected response.// #605: ; s9 = Manufacturer Identification = 20 hex// #606: ; s8 = Memory Type = 20 hex// #607: ; s7 = Memory Capacity = 15 hex// #608: ;// @102 #609: [memory_comms_test]3013e // @102 #609: CALL(read_spi_flash_ID)00f70 // @103 #610: LOAD(UART_data,character_p) ;p for pass14920 // @104 #611: COMPARE(s9,32)3550b // @105 #612: JUMP(NZ,SPI_FLASH_ID_fail)14820 // @106 #613: COMPARE(s8,32)3550b // @107 #614: JUMP(NZ,SPI_FLASH_ID_fail)14715 // @108 #615: COMPARE(s7,21)3550b // @109 #616: JUMP(NZ,SPI_FLASH_ID_fail)3410c // @10a #617: JUMP(SPI_FLASH_ID_result)// @10b #618: [SPI_FLASH_ID_fail]00f66 // @10b #618: LOAD(UART_data,character_f) ;f for fail// @10c #619: [SPI_FLASH_ID_result]301c1 // @10c #619: CALL(send_to_UART)2a000 // @10d #620: RETURN// #621: ;// #622: ;// #623: ;// #624: ;// #625: ;// #626: ;// #627: ;**************************************************************************************// #628: ;SPI FLASH memory routines// #629: ;**************************************************************************************// #630: ;// #631: ;These routines will work with two output ports and one input port which should be// #632: ;defined as follows using CONSTANT directives.// #633: ; (replace 'pp' with appropriate port address in each case)// #634: ;In the list of CONSTANT directives, only the ones marked with a * are really required// #635: ;in an SPI FLASH memory system. The other directives are to control (disable) or// #636: ;communicate with the other SPI components on the same SPI bus of the Spartan-3E Starter Kit.// #637: ;// #638: ;// #639: ;// #640: ;CONSTANT SPI_control_port, pp ;SPI clock and chip selects *// #641: ;CONSTANT SPI_sck, 01 ; SCK - bit0 *// #642: ;CONSTANT SPI_rom_cs, 02 ; serial rom select - bit1 *// #643: ;CONSTANT SPI_spare_control, 04 ; spare - bit2// #644: ;CONSTANT SPI_amp_cs, 08 ; amplifier select - bit3
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?