progctrl.rmh

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

RMH
1,519 行
字号
// #668: ;// #669: ;**************************************************************************************// #670: ; Read a byte from StrataFlash Memory// #671: ;**************************************************************************************// #672: ;// #673: ; The 24-bit address should be supplied in register set [s9,s8,s7].// #674: ; Register s0 will return the byte data retrieved from the memory.// #675: ;// #676: ; To read a byte, the address needs to be set up on the address lines// #677: ; and the controls set as follows// #678: ;    SF_read = 1 - disable Spartan data outputs and enable StrataFlash outputs (OE=0)// #679: ;      SF_ce = 0 - enable StrataFLASH memory// #680: ;      SF_we = 1 - Write enable off// #681: ;// #682: ; The access time of the memory is 75ns. This is equivalent to 3.75 clock cycles at// #683: ; 50MHz. Since each KCPSM3 instruction takes 2 clock cycles to execute, two instructions// #684: ; provides adequate delay for the memory to be accessed.// #685: ;// #686: ; Registers used s0,s1,s7,s8,s9// #687: ;// @0e0 #688: [SF_byte_read]2c980 // @0e0 #688: OUTPUT(s9,SF_addr_hi_port) ;set 24-bit address2c840 // @0e1 #689: OUTPUT(s8,SF_addr_mi_port)2c720 // @0e2 #690: OUTPUT(s7,SF_addr_lo_port)00105 // @0e3 #691: LOAD(s1,5) ;set controls2c108 // @0e4 #692: OUTPUT(s1,SF_control_port)00106 // @0e5 #693: LOAD(s1,6) ;>75ns delay00106 // @0e6 #694: LOAD(s1,6) ;but do something useful!04002 // @0e7 #695: INPUT(s0,SF_data_in_port) ;read data byte2c108 // @0e8 #696: OUTPUT(s1,SF_control_port) ;clear controls2a000 // @0e9 #697: RETURN// #698: ;// #699: ;// #700: ;**************************************************************************************// #701: ; Write data or command byte to StrataFlash Memory// #702: ;**************************************************************************************// #703: ;// #704: ; The 24-bit address should be supplied in register set [s9,s8,s7].// #705: ; Register s1 should contain the byte to be written to the memory.// #706: ;// #707: ; To write a byte, the address needs to be set up on the address lines// #708: ; and the controls set as follows// #709: ;    SF_read = 0 - enable Spartan data outputs and disable StrataFlash outputs (OE=1)// #710: ;      SF_ce = 0 - enable StrataFLASH memory// #711: ;      SF_we = 0 - Write enable on// #712: ;// #713: ; The setup time of the memory is 60ns. This is equivalent to 3 clock cycles at// #714: ; 50MHz. Since each KCPSM3 instruction takes 2 clock cycles to execute, two instructions// #715: ; provides adequate delay for the memory.// #716: ;// #717: ; Registers used s1,s7,s8,s9// #718: ;// @0ea #719: [SF_byte_write]2c980 // @0ea #719: OUTPUT(s9,SF_addr_hi_port) ;set 24-bit address2c840 // @0eb #720: OUTPUT(s8,SF_addr_mi_port)2c720 // @0ec #721: OUTPUT(s7,SF_addr_lo_port)2c110 // @0ed #722: OUTPUT(s1,SF_data_out_port) ;set data byte to be written00100 // @0ee #723: LOAD(s1,0) ;set controls2c108 // @0ef #724: OUTPUT(s1,SF_control_port)00106 // @0f0 #725: LOAD(s1,6) ;>60ns delay00106 // @0f1 #726: LOAD(s1,6) ;but do something useful!2c108 // @0f2 #727: OUTPUT(s1,SF_control_port) ;clear controls2a000 // @0f3 #728: RETURN// #729: ;// #730: ;// #731: ;**************************************************************************************// #732: ; Set 'Read Array' mode on StrataFLASH// #733: ;**************************************************************************************// #734: ;// #735: ; The read array mode is the default mode of the memory and allows the contents// #736: ; of the memory to be read based on the supplied address.// #737: ;// #738: ; Read array is the default mode of the device, but it must also be placed back// #739: ; into this mode after programming, erasing or reading the status register.// #740: ;// #741: ; The read array command (FF hex) is written to the Strata flash memory.// #742: ;// #743: ; Registers used s1,s7,s8,s9// #744: ;// @0f4 #745: [set_SF_read_array_mode]001ff // @0f4 #745: LOAD(s1,FF) ;command to read array300ea // @0f5 #746: CALL(SF_byte_write)2a000 // @0f6 #747: RETURN// #748: ;// #749: ;// #750: ;**************************************************************************************// #751: ; Wait for StrataFLASH to be ready// #752: ;**************************************************************************************// #753: ;// #754: ; This routine will typically be used after instigating a program or erase// #755: ; command. It continuously reads the StrataFLASH status register and tests the// #756: ; information provided by bit7 which indicates if the memory is busy(0) or ready(1).// #757: ; The routine waits for the ready condition before sending a read array command// #758: ; which puts the memory back to normal read mode.// #759: ;// #760: ; During the polling process, a counter formed by register pair [sE,sD] records// #761: ; approximately how long the memory is busy. This can be used to evaluate programming// #762: ; and erase times if required. The timing loop is 15 instructions which is equivalent// #763: ; to 30 clock cycles (600ns at 50MHz)// #764: ;// #765: ; Registers used s0,s1,s7,s8,s9,sD,sE   (s7,s8,s9 not changed)// #766: ;// #767: ;// @0f7 #768: [wait_SF_ready]00e00 // @0f7 #768: LOAD(sE,0) ;clear 16-bit counter timer00d00 // @0f8 #769: LOAD(sD,0)// @0f9 #770: [wait_SF_loop]18d01 // @0f9 #770: ADD(sD,1) ;increment counter timer1ae00 // @0fa #771: ADDCY(sE,0)300e0 // @0fb #772: CALL(SF_byte_read) ;read status register into s012080 // @0fc #773: TEST(s0,128) ;test ready/busy flag350f9 // @0fd #774: JUMP(Z,wait_SF_loop)300f4 // @0fe #775: CALL(set_SF_read_array_mode) ;restore normal read array mode2a000 // @0ff #776: RETURN// #777: ;// #778: ;// #779: ;**************************************************************************************// #780: ; Send 16-bit value in register pair [sE,sD] to UART// #781: ;**************************************************************************************// #782: ;// #783: ; In this program the register pair [sE,sD] indicates the programming time of the// #784: ; StrataFLASH memory in 600ns increments. This routine can be used to display that// #785: ; value if required.// #786: ;// @100 #787: [send_counter_timer]30193 // @100 #787: CALL(send_CR)010e0 // @101 #788: LOAD(s0,sE)30167 // @102 #789: CALL(send_hex_byte)010d0 // @103 #790: LOAD(s0,sD)30167 // @104 #791: CALL(send_hex_byte)30193 // @105 #792: CALL(send_CR)2a000 // @106 #793: RETURN// #794: ;// #795: ;// #796: ;**************************************************************************************// #797: ;Software delay routines// #798: ;**************************************************************************************// #799: ;// #800: ;Delay of 1us.// #801: ;// #802: ;Constant value defines reflects the clock applied to KCPSM3. Every instruction// #803: ;executes in 2 clock cycles making the calculation highly predictable. The '6' in// #804: ;the following equation even allows for 'CALL delay_1us' instruction in the initiating code.// #805: ;// #806: ; delay_1us_constant =  (clock_rate - 6)/4       Where 'clock_rate' is in MHz// #807: ;// #808: ;Registers used s0// #809: ;// @107 #810: [delay_1us]0000b // @107 #810: LOAD(s0,delay_1us_constant)// @108 #811: [wait_1us]1c001 // @108 #811: SUB(s0,1)35508 // @109 #812: JUMP(NZ,wait_1us)2a000 // @10a #813: RETURN// #814: ;// #815: ;Delay of 40us.// #816: ;// #817: ;Registers used s0, s1// #818: ;// @10b #819: [delay_40us]00128 // @10b #819: LOAD(s1,40) ;40 x 1us = 40us// @10c #820: [wait_40us]30107 // @10c #820: CALL(delay_1us)1c101 // @10d #821: SUB(s1,1)3550c // @10e #822: JUMP(NZ,wait_40us)2a000 // @10f #823: RETURN// #824: ;// #825: ;// #826: ;Delay of 1ms.// #827: ;// #828: ;Registers used s0, s1, s2// #829: ;// @110 #830: [delay_1ms]00219 // @110 #830: LOAD(s2,25) ;25 x 40us = 1ms// @111 #831: [wait_1ms]3010b // @111 #831: CALL(delay_40us)1c201 // @112 #832: SUB(s2,1)35511 // @113 #833: JUMP(NZ,wait_1ms)2a000 // @114 #834: RETURN// #835: ;// #836: ;Delay of 20ms.// #837: ;// #838: ;Delay of 20ms used during initialisation.// #839: ;// #840: ;Registers used s0, s1, s2, s3// #841: ;// @115 #842: [delay_20ms]00314 // @115 #842: LOAD(s3,20) ;20 x 1ms = 20ms// @116 #843: [wait_20ms]30110 // @116 #843: CALL(delay_1ms)1c301 // @117 #844: SUB(s3,1)35516 // @118 #845: JUMP(NZ,wait_20ms)2a000 // @119 #846: RETURN// #847: ;// #848: ;Delay of approximately 1 second.// #849: ;// #850: ;Registers used s0, s1, s2, s3, s4// #851: ;// @11a #852: [delay_1s]00414 // @11a #852: LOAD(s4,20) ;50 x 20ms = 1000ms// @11b #853: [wait_1s]30115 // @11b #853: CALL(delay_20ms)1c401 // @11c #854: SUB(s4,1)3551b // @11d #855: JUMP(NZ,wait_1s)2a000 // @11e #856: RETURN// #857: ;// #858: ;// #859: ;**************************************************************************************// #860: ;UART communication routines// #861: ;**************************************************************************************// #862: ;// #863: ;Read one character from the UART// #864: ;// #865: ;Character read will be returned in a register called 'UART_data'.// #866: ;// #867: ;The routine first tests the receiver FIFO buffer to see if data is present.// #868: ;If the FIFO is empty, the routine waits until there is a character to read.// #869: ;As this could take any amount of time the wait loop could include a call to a// #870: ;subroutine which performs a useful function.// #871: ;// #872: ;If the received character is an XOFF, then the routine will then wait// #873: ;for an XON to be received. This means that the rest of the program is held// #874: ;in suspense and therefore it can not transmit. Once an XON is received, it will// #875: ;again wait for a normal character before returning.// #876: ;// #877: ;NOTE: Characters between the XOFF and XON will be ignored in this version of the// #878: ;program!!!// #879: ;// #880: ;Interrupt is disabled during this routine to prevent a false situation. If the// #881: ;receiver half-full flag went High it should result in an interrupt transmitting// #882: ;an XOFF character. However, if this routine were able to read the receiver buffer// #883: ;at just about the same as the hardware detects the half-full flag, then it could// #884: ;think that an XON needs to be transmitted.// #885: ;// #886: ;// #887: ;Registers used s0 and UART_data// #888: ;// @11f #889: [read_from_UART]3c000 // @11f #889: DISABLE(INTERRUPT)// @120 #890: [wait_Rx_character]04000 // @120 #890: INPUT(s0,status_port) ;test Rx_FIFO buffer12008 // @121 #891: TEST(s0,rx_data_present)35524 // @122 #892: JUMP(NZ,read_character)34120 // @123 #893: JUMP(wait_Rx_character)// @124 #894: [read_character]04f01 // @124 #894: INPUT(UART_data,UART_read_port) ;read from FIFO14f13 // @125 #895: COMPARE(UART_data,character_XOFF) ;test for XOFF35129 // @126 #896: JUMP(Z,wait_XON)3c001 // @127 #897: ENABLE(INTERRUPT) ;normal finish2a000 // @128 #898: RETURN// @129 #899: [wait_XON]04000 // @129 #899: INPUT(s0,status_port) ;test Rx_FIFO buffer12008 // @12a #900: TEST(s0,rx_data_present)3552d // @12b #901: JUMP(NZ,read_XON)34129 // @12c #902: JUMP(wait_XON)// @12d #903: [read_XON]04f01 // @12d #903: INPUT(UART_data,UART_read_port) ;read from FIFO14f11 // @12e #904: COMPARE(UART_data,character_XON) ;test for XON35120 // @12f #905: JUMP(Z,wait_Rx_character) ;now wait for normal character34129 // @130 #906: JUMP(wait_XON) ;continue to wait for XON// #907: ;// #908: ;// #909: ;// #910: ;Transmit one character to the UART// #911: ;// #912: ;Character supplied in register called 'UART_data'.// #913: ;// #914: ;The routine first tests the transmit FIFO buffer is empty.// #915: ;If the FIFO currently has any data, the routine waits until it is empty.// #916: ;Ultimately this means that only one character is sent at a time which// #917: ;could be important if the PC at the other end of the link transmits// #918: ;an XOFF and needs the flow of data to terminate as soon as possible.// #919: ;// #920: ;Registers used s0// #921: ;// @131 #922: [send_to_UART]04000 // @131 #922: INPUT(s0,status_port) ;test Tx_FIFO buffer12001 // @132 #923: TEST(s0,tx_data_present)35135 // @133 #924: JUMP(Z,UART_write)34131 // @134 #925: JUMP(send_to_UART)// @135 #926: [UART_write]2cf04 // @135 #926: OUTPUT(UART_data,UART_write_port)2a000 // @136 #927: RETURN// #928: ;// #929: ;// #930: ;**************************************************************************************// #931: ;Useful ASCII conversion and handling routines// #932: ;**************************************************************************************// #933: ;// #934: ;Convert value provided in register s0 into ASCII characters// #935: ;// #936: ;The value provided must in the range 0 to 99 and will be converted into// #937: ;two ASCII characters.// #938: ;     The number of 'tens' will be represented by an ASCII character returned in register s1.// #939: ;     The number of 'units' will be represented by an ASCII character returned in register s0.// #940: ;// #941: ;The ASCII representations of '0' to '9' are 30 to 39 hexadecimal which is simply 30 hex added to// #942: ;the actual decimal value.// #943: ;// #944: ;Registers used s0 and s1.// #945: ;// @137 #946: [decimal_to_ASCII]00130 // @137 #946: LOAD(s1,48) ;load 'tens' counter with ASCII for '0'// @138 #947: [test_for_ten]

⌨️ 快捷键说明

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