📄 control.psm
字号:
welcome_start: CALL send_welcome ;start up message and version number
;
;
;
; The main program guides the user to follow the command state machine of the
; DS2432 device by only offering those choices that are valid at each stage.
; This program only offers a limited choice and it is left as an exercise to
; the user to modify or expand this choice as required.
;
;**************************************************************************************
; Reset Main menu and command selection
;**************************************************************************************
;
; Initially the only action available is a master reset and test for a presence
; pulse response from the DS2432.
;
reset_menu: CALL send_reset_menu ;Menu and command selection
CALL send_CR
;
reset_prompt: CALL menu_prompt ;prompt for user input
COMPARE s0, character_H ;test for commands and execute as required
JUMP Z, reset_menu
COMPARE s0, character_1
JUMP Z, master_reset_regular
CALL no_valid_input
JUMP reset_prompt ;Try again!
;
; The master reset should result in a presence pulse.
; This will be reported and control passed to the appropriate
; menu in the sequence.
;
master_reset_regular: CALL send_CR
CALL DS_init_regular_mode
JUMP NC, reset_passed ;test for presence pulse
CALL send_Fail
JUMP reset_menu ;fail stays in reset menu
reset_passed: CALL send_Pass ;pass progresses to ROM menu
JUMP ROM_menu
;
; After a valid master reset, the only commands available are the ROM
; commands of which only Read ROM and Skip ROM are currently supported.
; Another master reset can be issued is so desired.
;
ROM_menu: CALL send_ROM_menu ;Menu and command selection
CALL send_CR
;
ROM_prompt: CALL menu_prompt ;prompt for user input
COMPARE s0, character_H ;test for commands and execute as required
JUMP Z, ROM_menu
COMPARE s0, character_1
JUMP Z, master_reset_regular ;repeat reset as before
COMPARE s0, character_2
JUMP Z, read_ROM_command
COMPARE s0, character_3
JUMP Z, skip_ROM_command
CALL no_valid_input
JUMP ROM_prompt ;Try again!
;
;
;
; After a valid ROM command the DS2432 specific memory commands and SHA-1
; functions become accessible. Each of these end with the DS2432 returned
; back to the waiting for ROM command state completing the menu sequence.
;
DS2432_menu: CALL send_DS2432_menu ;Menu and command selection
CALL send_CR
;
DS2432_prompt: CALL menu_prompt ;prompt for user input
COMPARE s0, character_H ;test for commands and execute as required
JUMP Z, DS2432_menu
COMPARE s0, character_1
JUMP Z, master_reset_regular ;repeat reset as before
COMPARE s0, character_2
JUMP Z, read_memory_command
COMPARE s0, character_3
JUMP Z, write_scratchpad_command
COMPARE s0, character_4
JUMP Z, read_scratchpad_command
COMPARE s0, character_5
JUMP Z, write_byte_command
COMPARE s0, character_6
JUMP Z, read_byte_command
CALL no_valid_input
JUMP DS2432_prompt ;Try again!
;
;
;
;
;
;**************************************************************************************
; Prompt and selection tasks used in menus.
;**************************************************************************************
;
; Prompts for input with > character and waits for key stroke which is
; returned in upper case in register s0
;
menu_prompt: CALL send_CR
CALL send_CR
LOAD UART_data, character_greater_than ;prompt for input
CALL send_to_UART
CALL read_upper_case
RETURN
;
no_valid_input: 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
RETURN
;
;
;**************************************************************************************
; DS2432 Read ROM Command.
;**************************************************************************************
;
; The read ROM command (33 hex) allows the 8-bit family code, 48-bit unique serial
; number and 8-bit CRC to be read from the DS2432 device.
;
; This routine reads the values and places them in KCPSM3 scratch pad memory
; locations for future reference. These locations should be defined with constants
; as follows and MUST be in consecutive ascending locations.
;
; family_code
; Location to store family code which should be 33 hex
; serial_number0 to serial_number5
; 6 bytes to hold 48-bit serial number (LS-byte first).
; read_ROM_CRC
; 8-bit CRC value for the above data.
;
;
; The routine also displays the values read and performs a verification of the
; 8-bit CRC displaying a 'pass' or 'fail' message as appropriate.
;
read_ROM_command: LOAD s3, 33 ;Read ROM Command
CALL write_byte_slow ;transmit command
LOAD s5, family_code ;memory pointer
read_ROM_loop: CALL read_byte_slow ;read response into s3
STORE s3, (s5) ;store value
COMPARE s5, read_ROM_CRC ;8-bytes to read
JUMP Z, display_ROM
ADD s5, 01
JUMP read_ROM_loop
display_ROM: CALL send_CR
CALL send_code ;'code=' to display family code
FETCH s0, family_code
CALL send_hex_byte
CALL send_CR
CALL send_serial ;'serial=' to display family code
LOAD s5, serial_number5 ;memory pointer starting MS-byte first
disp_serial_loop: FETCH s0, (s5)
CALL send_hex_byte
COMPARE s5, serial_number0
JUMP Z, end_serial
SUB s5, 01
JUMP disp_serial_loop
end_serial: CALL send_CR
CALL send_CRC ;'CRC=' to display CRC value
FETCH s0, read_ROM_CRC
CALL send_hex_byte
CALL send_CR
CALL compute_CRC8 ;compute CRC value in s0
FETCH s1, read_ROM_CRC ;compare with received value
COMPARE s0, s1
JUMP NZ, crc8_fail
CALL send_Pass
JUMP DS2432_menu ;now in memory and SHA-1 functions level
crc8_fail: CALL send_Fail
JUMP ROM_menu ;can not proceed to next level
;
;
;
;**************************************************************************************
; DS2432 Skip ROM Command.
;**************************************************************************************
;
; The skip ROM command (CC hex) is a short cut to the memory commands and SHA-1
; functions which means that the 64 bit ROM contents do not have to be read.
;
;
skip_ROM_command: LOAD s3, CC ;Skip ROM Command
CALL write_byte_slow ;transmit command
CALL send_OK
JUMP DS2432_menu
;
;
;
;**************************************************************************************
; DS2432 Read Memory Command.
;**************************************************************************************
;
; The read memory command (F0 hex) allows the entire memory contents to be read
; except for the secret. This routine displays the address followed by 8 bytes
; of data on each line until the address 0097 is reached.
;
; The initial 'F0' command must be followed by the 16-bit start address transmitted
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -