📄 security.rmh
字号:
// #887: ;// #888: ;**************************************************************************************// #889: ; Read the unique 64-bit serial number of the StrataFLASH FLASH memory// #890: ;**************************************************************************************// #891: ;// #892: ; To read the device information the Read device information command (90)// #893: ; must be written to the memory. The information is read back from address 000102// #894: ; to 000109 (note these are byte access addresses).// #895: ;// #896: ; The serial number is copied to 8 ascending scratch pad memory locations called// #897: ; 'serial_number0' through to 'serial_number7' for future use.// #898: ;// #899: ; After reading the device information the read array command is written to the// #900: ; device to put it back to normal read mode.// #901: ;// #902: ; Registers used s0,s1,s2,s7,s8,s9// #903: ;// @0f2 #904: [read_SF_serial_number]00900 // @0f2 #904: LOAD(s9,0) ;StrataFLASH address to read serial number = 00010200801 // @0f3 #905: LOAD(s8,1)00702 // @0f4 #906: LOAD(s7,2)00210 // @0f5 #907: LOAD(s2,serial_number0) ;pointer to scratch pad memory00190 // @0f6 #908: LOAD(s1,144) ;command to read device information3010b // @0f7 #909: CALL(SF_byte_write)// @0f8 #910: [read_SN_loop]30101 // @0f8 #910: CALL(SF_byte_read) ;read serial number value2f020 // @0f9 #911: STORE(s0,s2)14217 // @0fa #912: COMPARE(s2,serial_number7) ;check for 8 bytes copied350ff // @0fb #913: JUMP(Z,end_read_SN)18701 // @0fc #914: ADD(s7,1) ;increment StrataFLASH address18201 // @0fd #915: ADD(s2,1) ;increment memory pointer340f8 // @0fe #916: JUMP(read_SN_loop)// #917: ;// @0ff #918: [end_read_SN]30115 // @0ff #918: CALL(set_SF_read_array_mode) ;restore normal read array mode2a000 // @100 #919: RETURN// #920: ;// #921: ;// #922: ;// #923: ;**************************************************************************************// #924: ; Read a byte from StrataFlash Memory// #925: ;**************************************************************************************// #926: ;// #927: ; The 24-bit address should be supplied in register set [s9,s8,s7].// #928: ; Register s0 will return the byte data retrieved from the memory.// #929: ;// #930: ; To read a byte, the address needs to be set up on the address lines// #931: ; and the controls set as follows// #932: ; SF_read = 1 - disable Spartan data outputs and enable StrataFlash outputs (OE=0)// #933: ; SF_ce = 0 - enable StrataFLASH memory// #934: ; SF_we = 1 - Write enable off// #935: ;// #936: ; The access time of the memory is 75ns. This is equivalent to 3.75 clock cycles at// #937: ; 50MHz. Since each KCPSM3 instruction takes 2 clock cycles to execute, two instructions// #938: ; provides adequate delay for the memory to be accessed.// #939: ;// #940: ; Registers used s0,s1,s7,s8,s9// #941: ;// @101 #942: [SF_byte_read]2c983 // @101 #942: OUTPUT(s9,SF_addr_hi_port) ;set 24-bit address2c882 // @102 #943: OUTPUT(s8,SF_addr_mi_port)2c781 // @103 #944: OUTPUT(s7,SF_addr_lo_port)00105 // @104 #945: LOAD(s1,5) ;set controls2c140 // @105 #946: OUTPUT(s1,SF_control_port)00106 // @106 #947: LOAD(s1,6) ;>75ns delay00106 // @107 #948: LOAD(s1,6) ;but do something useful!04002 // @108 #949: INPUT(s0,SF_data_in_port) ;read data byte2c140 // @109 #950: OUTPUT(s1,SF_control_port) ;clear controls2a000 // @10a #951: RETURN// #952: ;// #953: ;// #954: ;**************************************************************************************// #955: ; Write data or command byte to StrataFlash Memory// #956: ;**************************************************************************************// #957: ;// #958: ; The 24-bit address should be supplied in register set [s9,s8,s7].// #959: ; Register s1 should contain the byte to be written to the memory.// #960: ;// #961: ; To write a byte, the address needs to be set up on the address lines// #962: ; and the controls set as follows// #963: ; SF_read = 0 - enable Spartan data outputs and disable StrataFlash outputs (OE=1)// #964: ; SF_ce = 0 - enable StrataFLASH memory// #965: ; SF_we = 0 - Write enable on// #966: ;// #967: ; The setup time of the memory is 60ns. This is equivalent to 3 clock cycles at// #968: ; 50MHz. Since each KCPSM3 instruction takes 2 clock cycles to execute, two instructions// #969: ; provides adequate delay for the memory.// #970: ;// #971: ; Registers used s1,s7,s8,s9// #972: ;// @10b #973: [SF_byte_write]2c983 // @10b #973: OUTPUT(s9,SF_addr_hi_port) ;set 24-bit address2c882 // @10c #974: OUTPUT(s8,SF_addr_mi_port)2c781 // @10d #975: OUTPUT(s7,SF_addr_lo_port)2c180 // @10e #976: OUTPUT(s1,SF_data_out_port) ;set data byte to be written00100 // @10f #977: LOAD(s1,0) ;set controls2c140 // @110 #978: OUTPUT(s1,SF_control_port)00106 // @111 #979: LOAD(s1,6) ;>60ns delay00106 // @112 #980: LOAD(s1,6) ;but do something useful!2c140 // @113 #981: OUTPUT(s1,SF_control_port) ;clear controls2a000 // @114 #982: RETURN// #983: ;// #984: ;// #985: ;**************************************************************************************// #986: ; Set 'Read Array' mode on StrataFLASH// #987: ;**************************************************************************************// #988: ;// #989: ; The read array mode is the default mode of the memory and allows the contents// #990: ; of the memory to be read based on the supplied address.// #991: ;// #992: ; Read array is the default mode of the device, but it must also be placed back// #993: ; into this mode after programming, erasing or reading the status register.// #994: ;// #995: ; The read array command (FF hex) is written to the Strata flash memory.// #996: ;// #997: ; Registers used s1,s7,s8,s9// #998: ;// @115 #999: [set_SF_read_array_mode]001ff // @115 #999: LOAD(s1,FF) ;command to read array3010b // @116 #1000: CALL(SF_byte_write)2a000 // @117 #1001: RETURN// #1002: ;// #1003: ;// #1004: ;**************************************************************************************// #1005: ; Wait for StrataFLASH to be ready// #1006: ;**************************************************************************************// #1007: ;// #1008: ; This routine will typically be used after instigating a program or erase// #1009: ; command. It continuously reads the StrataFLASH status register and tests the// #1010: ; information provided by bit7 which indicates if the memory is busy(0) or ready(1).// #1011: ; The routine waits for the ready condition before sending a read array command// #1012: ; which puts the memory back to normal read mode.// #1013: ;// #1014: ;// #1015: ; Registers used s0,s1,s7,s8,s9 (s7,s8,s9 not changed)// #1016: ;// #1017: ;// @118 #1018: [wait_SF_ready]30101 // @118 #1018: CALL(SF_byte_read) ;read status register into s012080 // @119 #1019: TEST(s0,128) ;test ready/busy flag35118 // @11a #1020: JUMP(Z,wait_SF_ready)30115 // @11b #1021: CALL(set_SF_read_array_mode) ;restore normal read array mode2a000 // @11c #1022: RETURN// #1023: ;// #1024: ;// #1025: ;// #1026: ;// #1027: ;**************************************************************************************// #1028: ; UART communication routines// #1029: ;**************************************************************************************// #1030: ;// #1031: ; Read one character from the UART// #1032: ;// #1033: ; Character read will be returned in a register called 'UART_data'.// #1034: ;// #1035: ; The routine first tests the receiver FIFO buffer to see if data is present.// #1036: ; If the FIFO is empty, the routine waits until there is a character to read.// #1037: ; As this could take any amount of time the wait loop could include a call to a// #1038: ; subroutine which performs a useful function.// #1039: ;// #1040: ;// #1041: ; Registers used s0 and UART_data// #1042: ;// @11d #1043: [read_from_UART]04000 // @11d #1043: INPUT(s0,status_port) ;test Rx_FIFO buffer12004 // @11e #1044: TEST(s0,rx_data_present) ;wait if empty35521 // @11f #1045: JUMP(NZ,read_character)3411d // @120 #1046: JUMP(read_from_UART)// @121 #1047: [read_character]04f01 // @121 #1047: INPUT(UART_data,UART_read_port) ;read from FIFO2a000 // @122 #1048: RETURN// #1049: ;// #1050: ;// #1051: ;// #1052: ; Transmit one character to the UART// #1053: ;// #1054: ; Character supplied in register called 'UART_data'.// #1055: ;// #1056: ; The routine first tests the transmit FIFO buffer to see if it is full.// #1057: ; If the FIFO is full, then the routine waits until it there is space.// #1058: ;// #1059: ; Registers used s0// #1060: ;// @123 #1061: [send_to_UART]04000 // @123 #1061: INPUT(s0,status_port) ;test Tx_FIFO buffer12002 // @124 #1062: TEST(s0,tx_full) ;wait if full35127 // @125 #1063: JUMP(Z,UART_write)34123 // @126 #1064: JUMP(send_to_UART)// @127 #1065: [UART_write]2cf08 // @127 #1065: OUTPUT(UART_data,UART_write_port)2a000 // @128 #1066: RETURN// #1067: ;// #1068: ;// #1069: ;// #1070: ;**************************************************************************************// #1071: ;Useful ASCII conversion and handling routines// #1072: ;**************************************************************************************// #1073: ;// #1074: ;// #1075: ;// #1076: ;Convert character to upper case// #1077: ;// #1078: ;The character supplied in register UART_data.// #1079: ;If the character is in the range 'a' to 'z', it is converted// #1080: ;to the equivalent upper case character in the range 'A' to 'Z'.// #1081: ;All other characters remain unchanged.// #1082: ;// #1083: ;Registers used s0.// #1084: ;// @129 #1085: [upper_case]14f61 // @129 #1085: COMPARE(UART_data,97) ;eliminate character codes below 'a' (61 hex)2b800 // @12a #1086: RETURN(C)14f7b // @12b #1087: COMPARE(UART_data,123) ;eliminate character codes above 'z' (7A hex)2bc00 // @12c #1088: RETURN(NC)0afdf // @12d #1089: AND(UART_data,DF) ;mask bit5 to convert to upper case2a000 // @12e #1090: RETURN// #1091: ;// #1092: ;// #1093: ;Convert hexadecimal value provided in register s0 into ASCII characters// #1094: ;// #1095: ;The value provided must can be any value in the range 00 to FF and will be converted into// #1096: ;two ASCII characters.// #1097: ; The upper nibble will be represented by an ASCII character returned in register s2.// #1098: ; The lower nibble will be represented by an ASCII character returned in register s1.// #1099: ;// #1100: ;The ASCII representations of '0' to '9' are 30 to 39 hexadecimal which is simply 30 hex// #1101: ;added to the actual decimal value. The ASCII representations of 'A' to 'F' are 41 to 46// #1102: ;hexadecimal requiring a further addition of 07 to the 30 already added.// #1103: ;// #1104: ;Registers used s0, s1 and s2.// #1105: ;// @12f #1106: [hex_byte_to_ASCII]01100 // @12f #1106: LOAD(s1,s0) ;remember value supplied2000e // @130 #1107: SR0(s0) ;isolate upper nibble2000e // @131 #1108: SR0(s0)2000e // @132 #1109: SR0(s0)2000e // @133 #1110: SR0(s0)3013b // @134 #1111: CALL(hex_to_ASCII) ;convert01200 // @135 #1112: LOAD(s2,s0) ;upper nibble value in s201010 // @136 #1113: LOAD(s0,s1) ;restore complete value0a00f // @137 #1114: AND(s0,15) ;isolate lower nibble3013b // @138 #1115: CALL(hex_to_ASCII) ;convert01100 // @139 #1116: LOAD(s1,s0) ;lower nibble value in s12a000 // @13a #1117: RETURN// #1118: ;// #1119: ;Convert hexadecimal value provided in register s0 into ASCII character// #1120: ;// #1121: ;Register used s0// #1122: ;// @13b #1123: [hex_to_ASCII]1c00a // @13b #1123: SUB(s0,10) ;test if value is in range 0 to 93593e // @13c #1124: JUMP(C,number_char)18007 // @13d #1125: ADD(s0,7) ;ASCII char A to F in range 41 to 46// @13e #1126: [number_char]1803a // @13e #1126: ADD(s0,58) ;ASCII char 0 to 9 in range 30 to 402a000 // @13f #1127: RETURN// #1128: ;// #1129: ;// #1130: ;Send the two character HEX value of the register contents 's0' to the UART// #1131: ;// #1132: ;Registers used s0, s1, s2// #1133: ;// @140 #1134: [send_hex_byte]3012f // @140 #1134: CALL(hex_byte_to_ASCII)01f20 // @141 #1135: LOAD(UART_data,s2)30123 // @142 #1136: CALL(send_to_UART)01f10 // @143 #1137: LOAD(UART_data,s1)30123 // @144 #1138: CALL(send_to_UART)2a000 // @145 #1139: RETURN// #1140: ;// #1141: ;// #1142: ;Send the six character HEX value of the register contents [s9,s8,s7] to the UART// #1143: ;// #1144: ;Registers used s0, s1, s2// #1145: ;// @146 #1146: [send_hex_3bytes]01090 // @146 #1146: LOAD(s0,s9)30140 // @147 #1147: CALL(send_hex_byte)01080 // @148 #1148: LOAD(s0,s8)30140 // @149 #1149: CALL(send_hex_byte)01070 // @14a #1150: LOAD(s0,s7)30140 // @14b #1151: CALL(send_hex_byte)2a000 // @14c #1152: RETURN// #1153: ;// #1154: ;// #1155: ;Display the two character HEX value of the register contents 's0' on the LCD display// #1156: ;// #1157: ;Registers used s0,s1,s2,s3,s4,s5// #1158: ;// @14d #1159: [disp_hex_byte]3012f // @14d #1159: CALL(hex_byte_to_ASCII)01310 // @14e #1160: LOAD(s3,s1) ;remember least significant digit01520 // @14f #1161: LOAD(s5,s2)302fe // @150 #1162: CALL(LCD_write_data) ;display most significant digit01530 // @151 #1163: LOAD(s5,s3)302f
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -