spi_prog.rmh

来自「和picoblaze完全兼容的mcu ip core」· RMH 代码 · 共 1,531 行 · 第 1/5 页

RMH
1,531
字号
// #72: ;// #73: ;Example: For a 50MHz clock the constant value is (10-6)/4 = 11  (0B Hex).// #74: ;For clock rates below 10MHz the value of 1 must be used and the operation will// #75: ;become lower than intended.// #76: ;// #77: CONSTANT(delay_1us_constant,11)// #78: ;// #79: ;// #80: ;Useful constants// #81: ;// #82: ;// #83: ;ASCII table// #84: ;// #85: CONSTANT(character_a,97)// #86: CONSTANT(character_b,98)// #87: CONSTANT(character_c,99)// #88: CONSTANT(character_d,100)// #89: CONSTANT(character_e,101)// #90: CONSTANT(character_f,102)// #91: CONSTANT(character_g,103)// #92: CONSTANT(character_h,104)// #93: CONSTANT(character_i,105)// #94: CONSTANT(character_j,106)// #95: CONSTANT(character_k,107)// #96: CONSTANT(character_l,108)// #97: CONSTANT(character_m,109)// #98: CONSTANT(character_n,110)// #99: CONSTANT(character_o,111)// #100: CONSTANT(character_p,112)// #101: CONSTANT(character_q,113)// #102: CONSTANT(character_r,114)// #103: CONSTANT(character_s,115)// #104: CONSTANT(character_t,116)// #105: CONSTANT(character_u,117)// #106: CONSTANT(character_v,118)// #107: CONSTANT(character_w,119)// #108: CONSTANT(character_x,120)// #109: CONSTANT(character_y,121)// #110: CONSTANT(character_z,122)// #111: CONSTANT(character_A,65)// #112: CONSTANT(character_B,66)// #113: CONSTANT(character_C,67)// #114: CONSTANT(character_D,68)// #115: CONSTANT(character_E,69)// #116: CONSTANT(character_F,70)// #117: CONSTANT(character_G,71)// #118: CONSTANT(character_H,72)// #119: CONSTANT(character_I,73)// #120: CONSTANT(character_J,74)// #121: CONSTANT(character_K,75)// #122: CONSTANT(character_L,76)// #123: CONSTANT(character_M,77)// #124: CONSTANT(character_N,78)// #125: CONSTANT(character_O,79)// #126: CONSTANT(character_P,80)// #127: CONSTANT(character_Q,81)// #128: CONSTANT(character_R,82)// #129: CONSTANT(character_S,83)// #130: CONSTANT(character_T,84)// #131: CONSTANT(character_U,85)// #132: CONSTANT(character_V,86)// #133: CONSTANT(character_W,87)// #134: CONSTANT(character_X,88)// #135: CONSTANT(character_Y,89)// #136: CONSTANT(character_Z,90)// #137: CONSTANT(character_0,48)// #138: CONSTANT(character_1,49)// #139: CONSTANT(character_2,50)// #140: CONSTANT(character_3,51)// #141: CONSTANT(character_4,52)// #142: CONSTANT(character_5,53)// #143: CONSTANT(character_6,54)// #144: CONSTANT(character_7,55)// #145: CONSTANT(character_8,56)// #146: CONSTANT(character_9,57)// #147: CONSTANT(character_colon,58)// #148: CONSTANT(character_fullstop,46)// #149: CONSTANT(character_semi_colon,59)// #150: CONSTANT(character_minus,45)// #151: CONSTANT(character_plus,43)// #152: CONSTANT(character_comma,44)// #153: CONSTANT(character_less_than,60) ;'<'// #154: CONSTANT(character_greater_than,62) ;'>'// #155: CONSTANT(character_open,40) ;'('// #156: CONSTANT(character_close,41) ;')'// #157: CONSTANT(character_divide,47) ;'/'// #158: CONSTANT(character_equals,61)// #159: CONSTANT(character_space,32)// #160: CONSTANT(character_CR,13) ;carriage return// #161: CONSTANT(character_LF,10) ;line feed// #162: CONSTANT(character_question,63) ;'?'// #163: CONSTANT(character_dollar,36)// #164: CONSTANT(character_exclaim,33) ;'!'// #165: CONSTANT(character_BS,8) ;Back Space command character// #166: CONSTANT(character_XON,17) ;Flow control ON// #167: CONSTANT(character_XOFF,19) ;Flow control OFF// #168: ;// #169: ;// #170: ;Scratch Pad Memory Locations// #171: ;// #172: ;// #173: CONSTANT(ISR_preserve_s0,0) ;preserve register during ISR// #174: ;// #175: CONSTANT(page_address_h,1) ;Remember page address for SPI boundary checking.// #176: CONSTANT(page_address_m,2) ;high, middle and low bytes// #177: CONSTANT(page_address_l,3)// #178: ;// #179: CONSTANT(SPI_control_status,4) ;SPI status signals// #180: ;// #181: ;// #182: ;// #183: ;Store up to one line of an MCS file as bytes// #184: ;A typical data line consists of:-// #185: ;:     Start character which is not stored// #186: ;10    Number of data bytes included (16 in this case)// #187: ;aaaa  Lower 16-bits of the storage address// #188: ;00    Record type (data in this case)// #189: ;dddd...   Data bytes (typically 16 which is the maximum)// #190: ;cc    Checksum// #191: ;CR/LF Line will end in carriage return and/or line feed which is not stored.// #192: ;// #193: ;So a total of 21 could be stored before processing.// #194: ;// #195: CONSTANT(line_start,43) ;21 bytes until end of memory// #196: ;// #197: ;// #198: ;Initialise the system and welcome message// #199: ;// #200: ;// @000 #201: [cold_start]3010e // @000 #201: CALL(SPI_init) ;initialise SPI bus ports301aa // @001 #202: CALL(delay_1s) ;delay because UART is fast and JTAG startup sequence can be slow3c001 // @002 #203: ENABLE(INTERRUPT) ;Interrupt is used for XON/XOFF flow control// @003 #204: [welcome_start]3021d // @003 #204: CALL(send_CR)30223 // @004 #205: CALL(send_welcome) ;start up message and version number// #206: ;// #207: ;Main menu and command selection// #208: ;// #209: ;// #210: ;// @005 #211: [warm_start]302bd // @005 #211: CALL(send_Menu) ;Menu and command selection// @006 #212: [prompt]3021d // @006 #212: CALL(send_CR)3021d // @007 #213: CALL(send_CR)00f3e // @008 #214: LOAD(UART_data,character_greater_than) ;prompt for input301c1 // @009 #215: CALL(send_to_UART)3001d // @00a #216: CALL(read_upper_case)14045 // @00b #217: COMPARE(s0,character_E) ;command test35033 // @00c #218: JUMP(Z,erase_command)14053 // @00d #219: COMPARE(s0,character_S) ;command test35040 // @00e #220: JUMP(Z,sector_erase_command)14050 // @00f #221: COMPARE(s0,character_P) ;command test35054 // @010 #222: JUMP(Z,program_command)14052 // @011 #223: COMPARE(s0,character_R) ;command test35059 // @012 #224: JUMP(Z,read_command)14049 // @013 #225: COMPARE(s0,character_I) ;command test35022 // @014 #226: JUMP(Z,ID_command)14048 // @015 #227: COMPARE(s0,character_H) ;command test35003 // @016 #228: JUMP(Z,welcome_start)3021d // @017 #229: CALL(send_CR) ;no valid command input00f3f // @018 #230: LOAD(UART_data,character_question) ;display ???301c1 // @019 #231: CALL(send_to_UART)301c1 // @01a #232: CALL(send_to_UART)301c1 // @01b #233: CALL(send_to_UART)34006 // @01c #234: JUMP(prompt) ;Try again!// #235: ;// #236: ;// @01d #237: [read_upper_case]301af // @01d #237: CALL(read_from_UART) ;read command character from UART301c1 // @01e #238: CALL(send_to_UART) ;echo character010f0 // @01f #239: LOAD(s0,UART_data) ;convert to upper case301ce // @020 #240: CALL(upper_case)2a000 // @021 #241: RETURN// #242: ;// #243: ;**************************************************************************************// #244: ;ID Command - Read and display the ID for the SPI FLASH memory// #245: ;**************************************************************************************// #246: ;// #247: ;Normal response should be// #248: ;   s9 = Manufacturer Identification = 20 hex// #249: ;   s8 = Memory Type = 20 hex// #250: ;   s7 = Memory Capacity = 15 hex// #251: ;// @022 #252: [ID_command]3021d // @022 #252: CALL(send_CR)3013e // @023 #253: CALL(read_spi_flash_ID)30328 // @024 #254: CALL(send_ID)00f3d // @025 #255: LOAD(UART_data,character_equals)301c1 // @026 #256: CALL(send_to_UART)30220 // @027 #257: CALL(send_space)01090 // @028 #258: LOAD(s0,s9)301f7 // @029 #259: CALL(send_hex_byte)30220 // @02a #260: CALL(send_space)01080 // @02b #261: LOAD(s0,s8)301f7 // @02c #262: CALL(send_hex_byte)30220 // @02d #263: CALL(send_space)01070 // @02e #264: LOAD(s0,s7)301f7 // @02f #265: CALL(send_hex_byte)30220 // @030 #266: CALL(send_space)3021d // @031 #267: CALL(send_CR)34006 // @032 #268: JUMP(prompt)// #269: ;// #270: ;**************************************************************************************// #271: ;Erase Command - Perform bulk erase of the SPI FLASH memory and display messages// #272: ;**************************************************************************************// #273: ;// @033 #274: [erase_command]3021d // @033 #274: CALL(send_CR)3032d // @034 #275: CALL(send_Confirm) ;confirm command with a 'Y' which must be upper case301af // @035 #276: CALL(read_from_UART) ;read command character from UART301c1 // @036 #277: CALL(send_to_UART) ;echo input14f59 // @037 #278: COMPARE(UART_data,character_Y)3543e // @038 #279: JUMP(NZ,abort_erase)3021d // @039 #280: CALL(send_CR)30293 // @03a #281: CALL(send_Erase_in_progress)30173 // @03b #282: CALL(bulk_erase_spi)302b6 // @03c #283: CALL(send_OK)34006 // @03d #284: JUMP(prompt)// #285: ;// @03e #286: [abort_erase]3034a // @03e #286: CALL(send_Abort)34006 // @03f #287: JUMP(prompt)// #288: ;// #289: ;// #290: ;**************************************************************************************// #291: ;Sector Erase Command - Performs erase of lowest 5 sectors SPI FLASH memory which// #292: ;covers the address range 000000 to 04FFFF in which the configuration for an XC3S500E// #293: ;would be able to fit.// #294: ;**************************************************************************************// #295: ;// @040 #296: [sector_erase_command]3021d // @040 #296: CALL(send_CR)3032d // @041 #297: CALL(send_Confirm) ;confirm command with a 'Y' which must be upper case301af // @042 #298: CALL(read_from_UART) ;read command character from UART301c1 // @043 #299: CALL(send_to_UART) ;echo input14f59 // @044 #300: COMPARE(UART_data,character_Y)3543e // @045 #301: JUMP(NZ,abort_erase)3021d // @046 #302: CALL(send_CR)30293 // @047 #303: CALL(send_Erase_in_progress)00900 // @048 #304: LOAD(s9,0) ;any address inside sector 03015f // @049 #305: CALL(erase_spi_sector)00901 // @04a #306: LOAD(s9,1) ;any address inside sector 13015f // @04b #307: CALL(erase_spi_sector)00902 // @04c #308: LOAD(s9,2) ;any address inside sector 23015f // @04d #309: CALL(erase_spi_sector)00903 // @04e #310: LOAD(s9,3) ;any address inside sector 33015f // @04f #311: CALL(erase_spi_sector)00904 // @050 #312: LOAD(s9,4) ;any address inside sector 43015f // @051 #313: CALL(erase_spi_sector)302b6 // @052 #314: CALL(send_OK)34006 // @053 #315: JUMP(prompt)// #316: ;// #317: ;// #318: ;**************************************************************************************// #319: ;Program Command - Program SPI FLASH memory with MCS file// #320: ;**************************************************************************************// #321: ;// @054 #322: [program_command]3021d // @054 #322: CALL(send_CR)3026c // @055 #323: CALL(send_Waiting_MCS_file)3006f // @056 #324: CALL(program_MCS)302b6 // @057 #325: CALL(send_OK)34006 // @058 #326: JUMP(prompt)// #327: ;// #328: ;// #329: ;**************************************************************************************// #330: ;Read Command - Read one page of memory at specified address// #331: ;**************************************************************************************// #332: ;// @059 #333: [read_command]30357 // @059 #333: CALL(send_page_address) ;obtain 24-bit address30069 // @05a #334: CALL(obtain_8bits)35859 // @05b #335: JUMP(C,read_command) ;bad input address14020 // @05c #336: COMPARE(s0,32) ;test for address greater than 1FFFFF35c59 // @05d #337: JUMP(NC,read_command) ;value too big01900 // @05e #338: LOAD(s9,s0)30069 // @05f #339: CALL(obtain_8bits)35859 // @060 #340: JUMP(C,read_command) ;bad input address01800 // @061 #341: LOAD(s8,s0)30069 // @062 #342: CALL(obtain_8bits)35859 // @063 #343: JUMP(C,read_command) ;bad input address01700 // @064 #344: LOAD(s7,s0)3021d // @065 #345: CALL(send_CR)300c9 // @066 #346: CALL(send_spi_page)302b6 // @067 #347: CALL(send_OK)34006 // @068 #348: JUMP(prompt)// @069 #349: [obtain_8bits]3001d // @069 #349: CALL(read_upper_case) ;obtain one byte from UART01300 // @06a #350: LOAD(s3,s0)3001d // @06b #351: CALL(read_upper_case)01200 // @06c #352: LOAD(s2,s0)30204 // @06d #353: CALL(ASCII_byte_to_hex)2a000 // @06e #354: RETURN// #355: ;// #356: ;// #357: ;// #358: ;**************************************************************************************// #359: ;Program SPI FLASH with MCS file// #360: ;**************************************************************************************// #361: ;// #362: ;Reads the MCS file from the UART and programs the SPI FLASH device at the locations.// #363: ;specified by the file contents.// #364: ;// #365: ;One important factor of programming the SPI FLASH for use as configuration// #366: ;memory is that the bits within each byte must be in reverse order. This

⌨️ 快捷键说明

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