comparison src/comm.asm @ 354:043890f06bce

some cleanups
author heinrichsweikamp
date Wed, 29 Jul 2015 20:39:35 +0200
parents 2fd258596af0
children fcf3ae0fee6a
comparison
equal deleted inserted replaced
353:573f2251cf49 354:043890f06bce
141 bra comm_mode2 ; Cycle 141 bra comm_mode2 ; Cycle
142 bra comm_download_mode ; Startbyte for download mode found 142 bra comm_download_mode ; Startbyte for download mode found
143 143
144 comm_mode2b: 144 comm_mode2b:
145 ; Startbyte found 145 ; Startbyte found
146 call rs232_wait_tx ; Wait for UART 146 rcall comm_rs232_wait_tx ; Wait for UART
147 movlw 0x4B 147 movlw 0x4B
148 movwf TXREG1 ; Send Answer 148 movwf TXREG1 ; Send Answer
149 ; Now, check comm command 149 ; Now, check comm command
150 150
151 rcall comm_write_get_byte ; first byte 151 rcall comm_write_get_byte ; first byte
152 call rs232_wait_tx ; Wait for UART 152 rcall comm_rs232_wait_tx ; Wait for UART
153 movff RCREG1,TXREG1 ; Echo 153 movff RCREG1,TXREG1 ; Echo
154 movlw UPPER comm_service_key 154 movlw UPPER comm_service_key
155 cpfseq RCREG1 155 cpfseq RCREG1
156 bra comm_mode1 ; Wrong -> Restart 156 bra comm_mode1 ; Wrong -> Restart
157 rcall comm_write_get_byte ; second byte 157 rcall comm_write_get_byte ; second byte
158 call rs232_wait_tx ; Wait for UART 158 rcall comm_rs232_wait_tx ; Wait for UART
159 movff RCREG1,TXREG1 ; Echo 159 movff RCREG1,TXREG1 ; Echo
160 movlw HIGH (comm_service_key & 0xFFFF) 160 movlw HIGH (comm_service_key & 0xFFFF)
161 cpfseq RCREG1 161 cpfseq RCREG1
162 bra comm_mode1 ; Wrong -> Restart 162 bra comm_mode1 ; Wrong -> Restart
163 rcall comm_write_get_byte ; third byte 163 rcall comm_write_get_byte ; third byte
164 call rs232_wait_tx ; Wait for UART 164 rcall comm_rs232_wait_tx ; Wait for UART
165 movff RCREG1,TXREG1 ; Echo 165 movff RCREG1,TXREG1 ; Echo
166 movlw LOW comm_service_key 166 movlw LOW comm_service_key
167 cpfseq RCREG1 167 cpfseq RCREG1
168 bra comm_mode1 ; Wrong -> Restart 168 bra comm_mode1 ; Wrong -> Restart
169 169
184 184
185 comm_service_exit: 185 comm_service_exit:
186 WIN_SMALL comm_status3_column, comm_status3_row 186 WIN_SMALL comm_status3_column, comm_status3_row
187 STRCPY_TEXT_PRINT tUsbExit ; Exited 187 STRCPY_TEXT_PRINT tUsbExit ; Exited
188 comm_service_exit_common: 188 comm_service_exit_common:
189 call rs232_wait_tx ; Wait for UART 189 rcall comm_rs232_wait_tx ; Wait for UART
190 movlw 0xFF ; Reply FF 190 movlw 0xFF ; Reply FF
191 movwf TXREG1 ; Send Answer 191 movwf TXREG1 ; Send Answer
192 192
193 ; Wait 1 second 193 ; Wait 1 second
194 bcf onesecupdate 194 bcf onesecupdate
217 ; send firmware to bootloader 217 ; send firmware to bootloader
218 ; 218 ;
219 comm_send_firmware: 219 comm_send_firmware:
220 movlw 0x50 ; send echo 220 movlw 0x50 ; send echo
221 movwf TXREG1 221 movwf TXREG1
222 call rs232_wait_tx ; Wait for UART 222 rcall comm_rs232_wait_tx ; Wait for UART
223 223
224 ; Read 5 bytes into buffer. 224 ; Read 5 bytes into buffer.
225 lfsr FSR2,buffer 225 lfsr FSR2,buffer
226 movlw .5 ; counter 226 movlw .5 ; counter
227 movwf lo 227 movwf lo
243 movf hi,W 243 movf hi,W
244 bnz comm_send_firmware_failed 244 bnz comm_send_firmware_failed
245 245
246 movlw 0x4C ; send OK 246 movlw 0x4C ; send OK
247 movwf TXREG1 247 movwf TXREG1
248 call rs232_wait_tx ; Wait for UART 248 rcall comm_rs232_wait_tx ; Wait for UART
249 249
250 ; Passed: goto second stage verification. 250 ; Passed: goto second stage verification.
251 ; NOTE: Bootloader is Bank0. With buffer at address 0x200. 251 ; NOTE: Bootloader is Bank0. With buffer at address 0x200.
252 call vault_decodata_into_eeprom ; Store last deco data (And Time/Date) into EEPROM 252 call vault_decodata_into_eeprom ; Store last deco data (And Time/Date) into EEPROM
253 goto 0x1FDF0 ; And pray... 253 goto 0x1FDF0 ; And pray...
288 ; erases range in 4kB steps 288 ; erases range in 4kB steps
289 289
290 comm_erase_range4kb: 290 comm_erase_range4kb:
291 movlw 0x42 ; send echo 291 movlw 0x42 ; send echo
292 movwf TXREG1 292 movwf TXREG1
293 call rs232_wait_tx ; Wait for UART 293 rcall comm_rs232_wait_tx ; Wait for UART
294 294
295 bcf INTCON,GIE ; All interrups off! 295 bcf INTCON,GIE ; All interrups off!
296 296
297 rcall comm_get_flash_address ; Get three bytes address or return 297 rcall comm_get_flash_address ; Get three bytes address or return
298 btfsc rs232_recieve_overflow ; Got Data? 298 btfsc rs232_recieve_overflow ; Got Data?
331 ;----------------------------------------------------------------------------- 331 ;-----------------------------------------------------------------------------
332 332
333 comm_write_range: ; Get 3 bytes start address 333 comm_write_range: ; Get 3 bytes start address
334 movlw 0x30 ; send echo 334 movlw 0x30 ; send echo
335 movwf TXREG1 335 movwf TXREG1
336 call rs232_wait_tx ; Wait for UART 336 rcall comm_rs232_wait_tx ; Wait for UART
337 337
338 bcf INTCON,GIE ; All interrups off! 338 bcf INTCON,GIE ; All interrups off!
339 339
340 rcall comm_get_flash_address ; Get three bytes address or return 340 rcall comm_get_flash_address ; Get three bytes address or return
341 btfsc rs232_recieve_overflow ; Got Data? 341 btfsc rs232_recieve_overflow ; Got Data?
353 ;----------------------------------------------------------------------------- 353 ;-----------------------------------------------------------------------------
354 354
355 comm_send_range: ; Get 3 bytes start address and 3 bytes amount 355 comm_send_range: ; Get 3 bytes start address and 3 bytes amount
356 movlw 0x20 ; send echo 356 movlw 0x20 ; send echo
357 movwf TXREG1 357 movwf TXREG1
358 call rs232_wait_tx ; Wait for UART 358 rcall comm_rs232_wait_tx ; Wait for UART
359 359
360 bcf INTCON,GIE ; All interrups off! 360 bcf INTCON,GIE ; All interrups off!
361 361
362 rcall comm_get_flash_address ; Get three bytes address or return 362 rcall comm_get_flash_address ; Get three bytes address or return
363 btfsc rs232_recieve_overflow ; Got Data? 363 btfsc rs232_recieve_overflow ; Got Data?
394 bra comm_send_range24 ; counter 24bit 394 bra comm_send_range24 ; counter 24bit
395 comm_send_range24_loop: 395 comm_send_range24_loop:
396 call ext_flash_read_block ; Read one byte 396 call ext_flash_read_block ; Read one byte
397 movwf TXREG1 ; Start new transmit 397 movwf TXREG1 ; Start new transmit
398 comm_send_range24: 398 comm_send_range24:
399 call rs232_wait_tx ; Wait for UART 399 rcall comm_rs232_wait_tx ; Wait for UART
400 decfsz lo,F 400 decfsz lo,F
401 bra comm_send_range24_loop 401 bra comm_send_range24_loop
402 decf hi,F 402 decf hi,F
403 movlw 0xFF 403 movlw 0xFF
404 cpfseq hi 404 cpfseq hi
433 comm_download_mode: 433 comm_download_mode:
434 ; Enable comm download mode 434 ; Enable comm download mode
435 WIN_SMALL comm_status2_column, comm_status2_row 435 WIN_SMALL comm_status2_column, comm_status2_row
436 STRCPY_TEXT_PRINT tUsbDownloadMode; Download mode enabled 436 STRCPY_TEXT_PRINT tUsbDownloadMode; Download mode enabled
437 bsf INTCON,GIE ; All interrups on 437 bsf INTCON,GIE ; All interrups on
438 call rs232_wait_tx ; Wait for UART 438 rcall comm_rs232_wait_tx ; Wait for UART
439 movlw 0xBB ; Command Echo 439 movlw 0xBB ; Command Echo
440 movwf TXREG1 ; Send Answer 440 movwf TXREG1 ; Send Answer
441 comm_download_mode0: 441 comm_download_mode0:
442 bsf INTCON,GIE ; All interrups on 442 bsf INTCON,GIE ; All interrups on
443 call rs232_wait_tx ; Wait for UART 443 rcall comm_rs232_wait_tx ; Wait for UART
444 movlw 0x4C ; 4C in service mode 444 movlw 0x4C ; 4C in service mode
445 btfss comm_service_enabled 445 btfss comm_service_enabled
446 movlw 0x4D ; 4D in download mode 446 movlw 0x4D ; 4D in download mode
447 movwf TXREG1 ; Send Answer 447 movwf TXREG1 ; Send Answer
448 movlw timeout_service_mode 448 movlw timeout_service_mode
593 bra comm_download_mode0 ; Done. Loop with timeout reset 593 bra comm_download_mode0 ; Done. Loop with timeout reset
594 594
595 comm_send_compact_headers4: 595 comm_send_compact_headers4:
596 movlw .13 596 movlw .13
597 movwf lo ; Counter 597 movwf lo ; Counter
598 call rs232_wait_tx ; Wait for UART 598 rcall comm_rs232_wait_tx ; Wait for UART
599 call ext_flash_read_block_start ; 1st byte 599 call ext_flash_read_block_start ; 1st byte
600 movwf TXREG1 600 movwf TXREG1
601 bra comm_send_compact_headers3 ; counter 24bit 601 bra comm_send_compact_headers3 ; counter 24bit
602 comm_send_compact_headers_loop: 602 comm_send_compact_headers_loop:
603 call ext_flash_read_block ; Read one byte 603 call ext_flash_read_block ; Read one byte
604 movwf TXREG1 ; Start new transmit 604 movwf TXREG1 ; Start new transmit
605 comm_send_compact_headers3: 605 comm_send_compact_headers3:
606 call rs232_wait_tx ; Wait for UART 606 rcall comm_rs232_wait_tx ; Wait for UART
607 decfsz lo,F 607 decfsz lo,F
608 bra comm_send_compact_headers_loop 608 bra comm_send_compact_headers_loop
609 call ext_flash_read_block_stop 609 call ext_flash_read_block_stop
610 610
611 movlw 0xFF ; Spare 611 movlw 0xFF ; Spare
612 movwf TXREG1 612 movwf TXREG1
613 call rs232_wait_tx ; Wait for UART 613 rcall comm_rs232_wait_tx ; Wait for UART
614 movlw 0xFF ; Spare 614 movlw 0xFF ; Spare
615 movwf TXREG1 615 movwf TXREG1
616 call rs232_wait_tx ; Wait for UART 616 rcall comm_rs232_wait_tx ; Wait for UART
617 movlw 0xFF ; Spare 617 movlw 0xFF ; Spare
618 movwf TXREG1 618 movwf TXREG1
619 call rs232_wait_tx ; Wait for UART 619 rcall comm_rs232_wait_tx ; Wait for UART
620 620
621 bra comm_send_compact_headers2 ; continue 621 bra comm_send_compact_headers2 ; continue
622 622
623 623
624 ;----------------------------------------------------------------------------- 624 ;-----------------------------------------------------------------------------
651 bra comm_send_headers4 ; No, continue 651 bra comm_send_headers4 ; No, continue
652 bra comm_download_mode0 ; Done. Loop with timeout reset 652 bra comm_download_mode0 ; Done. Loop with timeout reset
653 653
654 comm_send_headers4: 654 comm_send_headers4:
655 clrf lo ; Counter 655 clrf lo ; Counter
656 call rs232_wait_tx ; Wait for UART 656 rcall comm_rs232_wait_tx ; Wait for UART
657 call ext_flash_read_block_start ; 1st byte 657 call ext_flash_read_block_start ; 1st byte
658 movwf TXREG1 658 movwf TXREG1
659 bra comm_send_headers3 ; counter 24bit 659 bra comm_send_headers3 ; counter 24bit
660 comm_send_headers_loop: 660 comm_send_headers_loop:
661 call ext_flash_read_block ; Read one byte 661 call ext_flash_read_block ; Read one byte
662 movwf TXREG1 ; Start new transmit 662 movwf TXREG1 ; Start new transmit
663 comm_send_headers3: 663 comm_send_headers3:
664 call rs232_wait_tx ; Wait for UART 664 rcall comm_rs232_wait_tx ; Wait for UART
665 decfsz lo,F 665 decfsz lo,F
666 bra comm_send_headers_loop 666 bra comm_send_headers_loop
667 call ext_flash_read_block_stop 667 call ext_flash_read_block_stop
668 bra comm_send_headers2 ; continue 668 bra comm_send_headers2 ; continue
669 669
678 ;----------------------------------------------------------------------------- 678 ;-----------------------------------------------------------------------------
679 679
680 comm_write_get_byte: 680 comm_write_get_byte:
681 goto rs232_get_byte ; returns... 681 goto rs232_get_byte ; returns...
682 682
683 comm_rs232_wait_tx:
684 goto rs232_wait_tx ; returns...
683 685
684 comm_set_time: 686 comm_set_time:
685 movlw "b" ; send echo 687 movlw "b" ; send echo
686 movwf TXREG1 688 movwf TXREG1
687 689
688 call rs232_wait_tx ; wait for UART 690 rcall comm_rs232_wait_tx ; wait for UART
689 rcall comm_write_get_byte 691 rcall comm_write_get_byte
690 btfsc rs232_recieve_overflow ; Got byte? 692 btfsc rs232_recieve_overflow ; Got byte?
691 bra comm_download_mode0 ; No, abort 693 bra comm_download_mode0 ; No, abort
692 movff RCREG1, hours 694 movff RCREG1, hours
693 movlw d'24' 695 movlw d'24'
734 ; 736 ;
735 737
736 comm_set_custom_text: 738 comm_set_custom_text:
737 movlw "c" ; send echo 739 movlw "c" ; send echo
738 movwf TXREG1 740 movwf TXREG1
739 call rs232_wait_tx ; wait for UART 741 rcall comm_rs232_wait_tx ; wait for UART
740 lfsr FSR2,opt_name 742 lfsr FSR2,opt_name
741 movlw opt_name_length 743 movlw opt_name_length
742 movwf lo ; counter 744 movwf lo ; counter
743 comm_set_ctext_loop: 745 comm_set_ctext_loop:
744 rcall comm_write_get_byte 746 rcall comm_write_get_byte
762 ; 764 ;
763 765
764 comm_identify: 766 comm_identify:
765 movlw "i" ; send echo 767 movlw "i" ; send echo
766 movwf TXREG1 768 movwf TXREG1
767 call rs232_wait_tx ; wait for UART 769 rcall comm_rs232_wait_tx ; wait for UART
768 770
769 ;---- Read serial from internal EEPROM address 0000 771 ;---- Read serial from internal EEPROM address 0000
770 clrf EEADRH 772 clrf EEADRH
771 clrf EEADR ; Get Serial number LOW 773 clrf EEADR ; Get Serial number LOW
772 call read_eeprom ; read byte 774 call read_eeprom ; read byte
775 call read_eeprom ; read byte 777 call read_eeprom ; read byte
776 movff EEDATA,hi 778 movff EEDATA,hi
777 779
778 ;---- Emit serial number 780 ;---- Emit serial number
779 movff lo,TXREG1 781 movff lo,TXREG1
780 call rs232_wait_tx 782 rcall comm_rs232_wait_tx
781 movff hi,TXREG1 783 movff hi,TXREG1
782 call rs232_wait_tx 784 rcall comm_rs232_wait_tx
783 785
784 ;---- Emit fiwmware hi.lo 786 ;---- Emit fiwmware hi.lo
785 movlw softwareversion_x 787 movlw softwareversion_x
786 movwf TXREG1 788 movwf TXREG1
787 call rs232_wait_tx 789 rcall comm_rs232_wait_tx
788 movlw softwareversion_y 790 movlw softwareversion_y
789 movwf TXREG1 791 movwf TXREG1
790 call rs232_wait_tx 792 rcall comm_rs232_wait_tx
791 793
792 ;---- Emit custom text 794 ;---- Emit custom text
793 movlw opt_name_length 795 movlw opt_name_length
794 movwf hi 796 movwf hi
795 lfsr FSR2,opt_name 797 lfsr FSR2,opt_name
796 798
797 common_identify_loop: 799 common_identify_loop:
798 movff POSTINC2,TXREG1 800 movff POSTINC2,TXREG1
799 call rs232_wait_tx 801 rcall comm_rs232_wait_tx
800 decfsz hi,F 802 decfsz hi,F
801 bra common_identify_loop 803 bra common_identify_loop
802 804
803 bra comm_download_mode0 ; Done. 805 bra comm_download_mode0 ; Done.
804 806
807 ; 809 ;
808 810
809 comm_hardware_descriptor: 811 comm_hardware_descriptor:
810 movlw "j" ; send echo 812 movlw "j" ; send echo
811 movwf TXREG1 813 movwf TXREG1
812 call rs232_wait_tx ; wait for UART 814 rcall comm_rs232_wait_tx ; wait for UART
813 movff hardware_flag,TXREG1 815 movff hardware_flag,TXREG1
814 bra comm_download_mode0 ; Done. 816 bra comm_download_mode0 ; Done.
815 817
816 ;----------------------------------------------------------------------------- 818 ;-----------------------------------------------------------------------------
817 819
871 bra comm_download_mode0 ; Done. Loop with timeout reset 873 bra comm_download_mode0 ; Done. Loop with timeout reset
872 874
873 comm_send_dive1: 875 comm_send_dive1:
874 ; Send header 876 ; Send header
875 clrf hi ; Counter 877 clrf hi ; Counter
876 call rs232_wait_tx ; Wait for UART 878 rcall comm_rs232_wait_tx ; Wait for UART
877 call ext_flash_read_block_start ; 1st byte 879 call ext_flash_read_block_start ; 1st byte
878 movwf TXREG1 880 movwf TXREG1
879 bra comm_send_dive_header 881 bra comm_send_dive_header
880 comm_send_dive_header2: 882 comm_send_dive_header2:
881 call ext_flash_read_block ; Read one byte 883 call ext_flash_read_block ; Read one byte
882 movwf TXREG1 ; Start new transmit 884 movwf TXREG1 ; Start new transmit
883 comm_send_dive_header: 885 comm_send_dive_header:
884 call rs232_wait_tx ; Wait for UART 886 rcall comm_rs232_wait_tx ; Wait for UART
885 decfsz hi,F 887 decfsz hi,F
886 bra comm_send_dive_header2 888 bra comm_send_dive_header2
887 call ext_flash_read_block_stop 889 call ext_flash_read_block_stop
888 890
889 ; Set address for profile 891 ; Set address for profile
894 movlw .6 ; Skip 6byte short header in profile - only for internal use 896 movlw .6 ; Skip 6byte short header in profile - only for internal use
895 call incf_ext_flash_address0_0x20 ; increases bytes in ext_flash_address:3 with 0x200000 bank switching 897 call incf_ext_flash_address0_0x20 ; increases bytes in ext_flash_address:3 with 0x200000 bank switching
896 898
897 comm_send_dive_profile: 899 comm_send_dive_profile:
898 call ext_flash_byte_read_plus_0x20 ; Read one byte into temp1, takes care of banking at 0x200000 900 call ext_flash_byte_read_plus_0x20 ; Read one byte into temp1, takes care of banking at 0x200000
899 call rs232_wait_tx ; Wait for UART 901 rcall comm_rs232_wait_tx ; Wait for UART
900 movff temp1,TXREG1 ; Send a byte 902 movff temp1,TXREG1 ; Send a byte
901 903
902 ; 24bit compare with end address 904 ; 24bit compare with end address
903 movff convert_value_temp+0,WREG 905 movff convert_value_temp+0,WREG
904 cpfseq ext_flash_address+0 906 cpfseq ext_flash_address+0
1031 comm_read_abort: 1033 comm_read_abort:
1032 comm_read_done: 1034 comm_read_done:
1033 bra comm_download_mode0 ; Done. Loop with timeout reset 1035 bra comm_download_mode0 ; Done. Loop with timeout reset
1034 1036
1035 comm_read_setting_wait: 1037 comm_read_setting_wait:
1036 goto rs232_wait_tx ; Wait for UART (and return!) 1038 bra comm_rs232_wait_tx ; Wait for UART (and return!)
1037 1039
1038 comm_read_gas1: 1040 comm_read_gas1:
1039 movff opt_gas_O2_ratio+0, TXREG1 1041 movff opt_gas_O2_ratio+0, TXREG1
1040 rcall comm_read_setting_wait ; Wait for UART 1042 rcall comm_read_setting_wait ; Wait for UART
1041 movff opt_gas_He_ratio+0, TXREG1 1043 movff opt_gas_He_ratio+0, TXREG1
1403 ;----------------------------------------------------------------------------- 1405 ;-----------------------------------------------------------------------------
1404 1406
1405 comm_send_string: 1407 comm_send_string:
1406 movlw "n" ; send echo 1408 movlw "n" ; send echo
1407 movwf TXREG1 1409 movwf TXREG1
1408 call rs232_wait_tx ; Wait for UART 1410 rcall comm_rs232_wait_tx ; Wait for UART
1409 WIN_SMALL comm_string_column, comm_string_row 1411 WIN_SMALL comm_string_column, comm_string_row
1410 movlw .16 1412 movlw .16
1411 movwf lo ; counter 1413 movwf lo ; counter
1412 comm_send_string_loop: 1414 comm_send_string_loop:
1413 rcall comm_write_get_byte 1415 rcall comm_write_get_byte