Mercurial > public > hwos_code
comparison src/comm.asm @ 350:2fd258596af0
some cleanups
author | heinrichsweikamp |
---|---|
date | Thu, 23 Jul 2015 12:53:35 +0200 |
parents | 7e5772df60cd |
children | 043890f06bce |
comparison
equal
deleted
inserted
replaced
349:9488d565150c | 350:2fd258596af0 |
---|---|
117 ; Voltage ok. Do we have a new battery now? | 117 ; Voltage ok. Do we have a new battery now? |
118 btfsc battery_removed_in_usb ; =1: The battery has been removed in USB | 118 btfsc battery_removed_in_usb ; =1: The battery has been removed in USB |
119 goto new_battery_menu ; show "New battery dialog" | 119 goto new_battery_menu ; show "New battery dialog" |
120 | 120 |
121 comm_mode4: | 121 comm_mode4: |
122 call rs232_get_byte | 122 rcall comm_write_get_byte |
123 | 123 |
124 btfss vusb_in ; USB plugged in? | 124 btfss vusb_in ; USB plugged in? |
125 bra comm_service_exit_nousb_delay ; Disconnected -> Exit | 125 bra comm_service_exit_nousb_delay ; Disconnected -> Exit |
126 comm_mode4a: | 126 comm_mode4a: |
127 | 127 |
146 call rs232_wait_tx ; Wait for UART | 146 call 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 call rs232_get_byte ; first byte | 151 rcall comm_write_get_byte ; first byte |
152 call rs232_wait_tx ; Wait for UART | 152 call 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 call rs232_get_byte ; second byte | 157 rcall comm_write_get_byte ; second byte |
158 call rs232_wait_tx ; Wait for UART | 158 call 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 call rs232_get_byte ; third byte | 163 rcall comm_write_get_byte ; third byte |
164 call rs232_wait_tx ; Wait for UART | 164 call 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 |
170 ; Enable comm service mode | 170 ; Enable comm service mode |
171 WIN_SMALL comm_status2_column, comm_status2_row | 171 WIN_SMALL comm_status2_column, comm_status2_row |
172 STRCPY_TEXT_PRINT tUsbServiceMode ; Service mode enabled | 172 STRCPY_TEXT_PRINT tUsbServiceMode ; Service mode enabled |
173 bsf comm_service_enabled | 173 bsf comm_service_enabled ; Set flag... |
174 bra comm_download_mode0 ; Startbyte for download mode found | 174 bra comm_download_mode0 ; ... but use common routine |
175 | |
176 | 175 |
177 comm_service_exit_nousb_delay: | 176 comm_service_exit_nousb_delay: |
178 WAITMS d'200' | 177 WAITMS d'200' |
179 btfss vusb_in ; USB plugged in? | 178 btfsc vusb_in ; USB plugged in? |
180 bra comm_service_exit_nousb ; Disconnected -> Exit | |
181 bra comm_mode4a ; (Still) connected, return | 179 bra comm_mode4a ; (Still) connected, return |
182 | |
183 comm_service_exit_nousb: ; Disconnected -> Exit | 180 comm_service_exit_nousb: ; Disconnected -> Exit |
184 WIN_SMALL comm_status3_column, comm_status3_row | 181 WIN_SMALL comm_status3_column, comm_status3_row |
185 STRCPY_TEXT_PRINT tUsbClosed ; Port closed | 182 STRCPY_TEXT_PRINT tUsbClosed ; Port closed |
186 bra comm_service_exit_common | 183 bra comm_service_exit_common |
187 | 184 |
188 comm_service_exit: | 185 comm_service_exit: |
189 WIN_SMALL comm_status3_column, comm_status3_row | 186 WIN_SMALL comm_status3_column, comm_status3_row |
190 STRCPY_TEXT_PRINT tUsbExit ; Exited | 187 STRCPY_TEXT_PRINT tUsbExit ; Exited |
191 | |
192 comm_service_exit_common: | 188 comm_service_exit_common: |
193 call rs232_wait_tx ; Wait for UART | 189 call rs232_wait_tx ; Wait for UART |
194 movlw 0xFF ; Reply FF | 190 movlw 0xFF ; Reply FF |
195 movwf TXREG1 ; Send Answer | 191 movwf TXREG1 ; Send Answer |
196 | 192 |
231 movwf lo | 227 movwf lo |
232 movlw 0x55 ; 5'ft byte checksum. | 228 movlw 0x55 ; 5'ft byte checksum. |
233 movwf hi | 229 movwf hi |
234 | 230 |
235 comm_send_firmware_loop: | 231 comm_send_firmware_loop: |
236 call rs232_get_byte | 232 rcall comm_write_get_byte |
237 btfsc rs232_recieve_overflow ; Got byte? | 233 btfsc rs232_recieve_overflow ; Got byte? |
238 bra comm_send_firmware_abort ; No, abort! | 234 bra comm_send_firmware_abort ; No, abort! |
239 movf RCREG1,W | 235 movf RCREG1,W |
240 movwf POSTINC2 ; Store checksum byte. | 236 movwf POSTINC2 ; Store checksum byte. |
241 xorwf hi,F ; Also xor into checksum | 237 xorwf hi,F ; Also xor into checksum |
300 | 296 |
301 rcall comm_get_flash_address ; Get three bytes address or return | 297 rcall comm_get_flash_address ; Get three bytes address or return |
302 btfsc rs232_recieve_overflow ; Got Data? | 298 btfsc rs232_recieve_overflow ; Got Data? |
303 bra comm_download_mode0 ; No, Done. | 299 bra comm_download_mode0 ; No, Done. |
304 | 300 |
305 call rs232_get_byte | 301 rcall comm_write_get_byte |
306 btfsc rs232_recieve_overflow ; Got byte? | 302 btfsc rs232_recieve_overflow ; Got byte? |
307 bra comm_download_mode0 ; No, Done. | 303 bra comm_download_mode0 ; No, Done. |
308 movff RCREG1,lo | 304 movff RCREG1,lo |
309 ; Got 4bytes: 3bytes address and 1 bytes (lo) amount of 4kB blocks | 305 ; Got 4bytes: 3bytes address and 1 bytes (lo) amount of 4kB blocks |
310 | 306 |
344 rcall comm_get_flash_address ; Get three bytes address or return | 340 rcall comm_get_flash_address ; Get three bytes address or return |
345 btfsc rs232_recieve_overflow ; Got Data? | 341 btfsc rs232_recieve_overflow ; Got Data? |
346 bra comm_download_mode0 ; No, Done. | 342 bra comm_download_mode0 ; No, Done. |
347 | 343 |
348 comm_write_range_loop: | 344 comm_write_range_loop: |
349 call rs232_get_byte | 345 rcall comm_write_get_byte |
350 btfsc rs232_recieve_overflow ; Got byte? | 346 btfsc rs232_recieve_overflow ; Got byte? |
351 bra comm_download_mode0 ; No, Done (and send OK byte too). | 347 bra comm_download_mode0 ; No, Done (and send OK byte too). |
352 movf RCREG1,W | 348 movf RCREG1,W |
353 call ext_flash_byte_write ; write one byte | 349 call ext_flash_byte_write ; write one byte |
354 call incf_ext_flash_address_p1 ; increase address+1 | 350 call incf_ext_flash_address_p1 ; increase address+1 |
365 | 361 |
366 rcall comm_get_flash_address ; Get three bytes address or return | 362 rcall comm_get_flash_address ; Get three bytes address or return |
367 btfsc rs232_recieve_overflow ; Got Data? | 363 btfsc rs232_recieve_overflow ; Got Data? |
368 bra comm_download_mode0 ; No, Done. | 364 bra comm_download_mode0 ; No, Done. |
369 | 365 |
370 call rs232_get_byte | 366 rcall comm_write_get_byte |
371 btfsc rs232_recieve_overflow ; Got byte? | 367 btfsc rs232_recieve_overflow ; Got byte? |
372 bra comm_download_mode0 ; No, Done. | 368 bra comm_download_mode0 ; No, Done. |
373 movff RCREG1,up | 369 movff RCREG1,up |
374 call rs232_get_byte | 370 rcall comm_write_get_byte |
375 btfsc rs232_recieve_overflow ; Got byte? | 371 btfsc rs232_recieve_overflow ; Got byte? |
376 bra comm_download_mode0 ; No, Done. | 372 bra comm_download_mode0 ; No, Done. |
377 movff RCREG1,hi | 373 movff RCREG1,hi |
378 call rs232_get_byte | 374 rcall comm_write_get_byte |
379 btfsc rs232_recieve_overflow ; Got byte? | 375 btfsc rs232_recieve_overflow ; Got byte? |
380 bra comm_download_mode0 ; No, Done. | 376 bra comm_download_mode0 ; No, Done. |
381 movff RCREG1,lo | 377 movff RCREG1,lo |
382 | 378 |
383 ; If lo==0, we must precondition hi because there is to many bytes send ! | 379 ; If lo==0, we must precondition hi because there is to many bytes send ! |
416 bra comm_download_mode0 ; Done. | 412 bra comm_download_mode0 ; Done. |
417 | 413 |
418 ;----------------------------------------------------------------------------- | 414 ;----------------------------------------------------------------------------- |
419 | 415 |
420 comm_get_flash_address: | 416 comm_get_flash_address: |
421 call rs232_get_byte | 417 rcall comm_write_get_byte |
422 btfsc rs232_recieve_overflow ; Got byte? | 418 btfsc rs232_recieve_overflow ; Got byte? |
423 return ; No, return | 419 return ; No, return |
424 movff RCREG1,ext_flash_address+2 | 420 movff RCREG1,ext_flash_address+2 |
425 call rs232_get_byte | 421 rcall comm_write_get_byte |
426 btfsc rs232_recieve_overflow ; Got byte? | 422 btfsc rs232_recieve_overflow ; Got byte? |
427 return ; No, return | 423 return ; No, return |
428 movff RCREG1,ext_flash_address+1 | 424 movff RCREG1,ext_flash_address+1 |
429 call rs232_get_byte | 425 rcall comm_write_get_byte |
430 btfsc rs232_recieve_overflow ; Got byte? | 426 btfsc rs232_recieve_overflow ; Got byte? |
431 return ; No, return | 427 return ; No, return |
432 movff RCREG1,ext_flash_address+0 | 428 movff RCREG1,ext_flash_address+0 |
433 return | 429 return |
434 | 430 |
455 comm_download_mode1: | 451 comm_download_mode1: |
456 bcf onesecupdate | 452 bcf onesecupdate |
457 dcfsnz timeout_counter,F | 453 dcfsnz timeout_counter,F |
458 bra comm_service_exit ; Timeout -> Exit | 454 bra comm_service_exit ; Timeout -> Exit |
459 comm_download_mode2: | 455 comm_download_mode2: |
460 call rs232_get_byte ; Check for a byte | 456 rcall comm_write_get_byte ; Check for a byte |
461 btfsc comm_service_enabled | 457 btfsc comm_service_enabled |
462 btg LEDr ; Blink in Service mode | 458 btg LEDr ; Blink in Service mode |
463 btfss vusb_in ; USB plugged in? | 459 btfss vusb_in ; USB plugged in? |
464 bra comm_service_exit_nousb ; Disconnected -> Exit | 460 bra comm_service_exit_nousb ; Disconnected -> Exit |
465 btfsc switch_right ; Abort with right | 461 btfsc switch_right ; Abort with right |
679 call option_reset_all | 675 call option_reset_all |
680 bra comm_download_mode0 ; Done. back to loop with timeout reset | 676 bra comm_download_mode0 ; Done. back to loop with timeout reset |
681 | 677 |
682 ;----------------------------------------------------------------------------- | 678 ;----------------------------------------------------------------------------- |
683 | 679 |
680 comm_write_get_byte: | |
681 goto rs232_get_byte ; returns... | |
682 | |
683 | |
684 comm_set_time: | 684 comm_set_time: |
685 movlw "b" ; send echo | 685 movlw "b" ; send echo |
686 movwf TXREG1 | 686 movwf TXREG1 |
687 | 687 |
688 call rs232_wait_tx ; wait for UART | 688 call rs232_wait_tx ; wait for UART |
689 call rs232_get_byte | 689 rcall comm_write_get_byte |
690 btfsc rs232_recieve_overflow ; Got byte? | 690 btfsc rs232_recieve_overflow ; Got byte? |
691 bra comm_download_mode0 ; No, abort | 691 bra comm_download_mode0 ; No, abort |
692 movff RCREG1, hours | 692 movff RCREG1, hours |
693 movlw d'24' | 693 movlw d'24' |
694 cpfslt hours | 694 cpfslt hours |
695 clrf hours | 695 clrf hours |
696 call rs232_get_byte | 696 rcall comm_write_get_byte |
697 btfsc rs232_recieve_overflow ; Got byte? | 697 btfsc rs232_recieve_overflow ; Got byte? |
698 bra comm_download_mode0 ; No, abort | 698 bra comm_download_mode0 ; No, abort |
699 movff RCREG1, mins | 699 movff RCREG1, mins |
700 movlw d'60' | 700 movlw d'60' |
701 cpfslt mins | 701 cpfslt mins |
702 clrf mins | 702 clrf mins |
703 call rs232_get_byte | 703 rcall comm_write_get_byte |
704 btfsc rs232_recieve_overflow ; Got byte? | 704 btfsc rs232_recieve_overflow ; Got byte? |
705 bra comm_download_mode0 ; No, abort | 705 bra comm_download_mode0 ; No, abort |
706 movff RCREG1, secs | 706 movff RCREG1, secs |
707 movlw d'60' | 707 movlw d'60' |
708 cpfslt secs | 708 cpfslt secs |
709 clrf secs | 709 clrf secs |
710 call rs232_get_byte | 710 rcall comm_write_get_byte |
711 btfsc rs232_recieve_overflow ; Got byte? | 711 btfsc rs232_recieve_overflow ; Got byte? |
712 bra comm_download_mode0 ; No, abort | 712 bra comm_download_mode0 ; No, abort |
713 movff RCREG1, month | 713 movff RCREG1, month |
714 movlw d'13' | 714 movlw d'13' |
715 cpfslt month | 715 cpfslt month |
716 movwf month | 716 movwf month |
717 call rs232_get_byte | 717 rcall comm_write_get_byte |
718 btfsc rs232_recieve_overflow ; Got byte? | 718 btfsc rs232_recieve_overflow ; Got byte? |
719 bra comm_download_mode0 ; No, abort | 719 bra comm_download_mode0 ; No, abort |
720 call comm_check_day ; Check day | 720 call comm_check_day ; Check day |
721 call rs232_get_byte | 721 rcall comm_write_get_byte |
722 btfsc rs232_recieve_overflow ; Got byte? | 722 btfsc rs232_recieve_overflow ; Got byte? |
723 bra comm_download_mode0 ; No, abort | 723 bra comm_download_mode0 ; No, abort |
724 movff RCREG1, year | 724 movff RCREG1, year |
725 movlw d'100' | 725 movlw d'100' |
726 cpfslt year | 726 cpfslt year |
739 call rs232_wait_tx ; wait for UART | 739 call rs232_wait_tx ; wait for UART |
740 lfsr FSR2,opt_name | 740 lfsr FSR2,opt_name |
741 movlw opt_name_length | 741 movlw opt_name_length |
742 movwf lo ; counter | 742 movwf lo ; counter |
743 comm_set_ctext_loop: | 743 comm_set_ctext_loop: |
744 call rs232_get_byte | 744 rcall comm_write_get_byte |
745 btfsc rs232_recieve_overflow ; Got byte? | 745 btfsc rs232_recieve_overflow ; Got byte? |
746 bra comm_set_ctext_loop_done ; no, abort | 746 bra comm_set_ctext_loop_done ; no, abort |
747 movff RCREG1,POSTINC2 ; Store character | 747 movff RCREG1,POSTINC2 ; Store character |
748 decfsz lo,F | 748 decfsz lo,F |
749 bra comm_set_ctext_loop | 749 bra comm_set_ctext_loop |
817 | 817 |
818 comm_send_dive: | 818 comm_send_dive: |
819 movlw "f" ; send echo | 819 movlw "f" ; send echo |
820 movwf TXREG1 | 820 movwf TXREG1 |
821 | 821 |
822 call rs232_get_byte | 822 rcall comm_write_get_byte |
823 btfsc rs232_recieve_overflow ; Got byte? | 823 btfsc rs232_recieve_overflow ; Got byte? |
824 bra comm_download_mode0 ; No, abort! | 824 bra comm_download_mode0 ; No, abort! |
825 movff RCREG1,lo ; Store dive number (0-255) | 825 movff RCREG1,lo ; Store dive number (0-255) |
826 ; First, send the header (again) | 826 ; First, send the header (again) |
827 ; Set ext_flash_address:3 to TOC entry of this dive | 827 ; Set ext_flash_address:3 to TOC entry of this dive |
916 ;----------------------------------------------------------------------------- | 916 ;----------------------------------------------------------------------------- |
917 | 917 |
918 comm_read_setting: | 918 comm_read_setting: |
919 movlw "r" | 919 movlw "r" |
920 movwf TXREG1 | 920 movwf TXREG1 |
921 call rs232_get_byte | 921 rcall comm_write_get_byte |
922 btfsc rs232_recieve_overflow ; Got byte? | 922 btfsc rs232_recieve_overflow ; Got byte? |
923 bra comm_read_abort ; No, abort! | 923 bra comm_read_abort ; No, abort! |
924 rcall comm_read_setting_wait ; Wait for UART | 924 rcall comm_read_setting_wait ; Wait for UART |
925 movlw 0x0F | 925 movlw 0x0F |
926 cpfsgt RCREG1 ; 0x00-0x0F: unused | 926 cpfsgt RCREG1 ; 0x00-0x0F: unused |
1326 call gaslist_cleanup_list ; Takes care that only one gas can be first and first has 0m change depth | 1326 call gaslist_cleanup_list ; Takes care that only one gas can be first and first has 0m change depth |
1327 call get_first_gas_to_WREG ; Makes sure at least one Gas is "First" | 1327 call get_first_gas_to_WREG ; Makes sure at least one Gas is "First" |
1328 call get_first_dil_to_WREG ; Makes sure at least one Diluent is "First" | 1328 call get_first_dil_to_WREG ; Makes sure at least one Diluent is "First" |
1329 bra comm_download_mode0 ; Done. Loop with timeout reset | 1329 bra comm_download_mode0 ; Done. Loop with timeout reset |
1330 | 1330 |
1331 comm_write_get_byte: | |
1332 call rs232_get_byte | |
1333 return | |
1334 | |
1335 comm_write_dil1: | 1331 comm_write_dil1: |
1336 movff RCREG1,opt_dil_O2_ratio+0 | 1332 movff RCREG1,opt_dil_O2_ratio+0 |
1337 rcall comm_write_get_byte | 1333 rcall comm_write_get_byte |
1338 movff RCREG1,opt_dil_He_ratio+0 | 1334 movff RCREG1,opt_dil_He_ratio+0 |
1339 rcall comm_write_get_byte | 1335 rcall comm_write_get_byte |
1412 call rs232_wait_tx ; Wait for UART | 1408 call rs232_wait_tx ; Wait for UART |
1413 WIN_SMALL comm_string_column, comm_string_row | 1409 WIN_SMALL comm_string_column, comm_string_row |
1414 movlw .16 | 1410 movlw .16 |
1415 movwf lo ; counter | 1411 movwf lo ; counter |
1416 comm_send_string_loop: | 1412 comm_send_string_loop: |
1417 call rs232_get_byte | 1413 rcall comm_write_get_byte |
1418 btfsc rs232_recieve_overflow ; Got byte? | 1414 btfsc rs232_recieve_overflow ; Got byte? |
1419 bra comm_send_string_abort ; No, abort! | 1415 bra comm_send_string_abort ; No, abort! |
1420 movff RCREG1,POSTINC2 ; Store character | 1416 movff RCREG1,POSTINC2 ; Store character |
1421 decfsz lo,F | 1417 decfsz lo,F |
1422 bra comm_send_string_loop | 1418 bra comm_send_string_loop |