Mercurial > public > hwos_code
comparison src/comm.asm @ 631:185ba2f91f59
3.09 beta 1 release
author | heinrichsweikamp |
---|---|
date | Fri, 28 Feb 2020 15:45:07 +0100 |
parents | cd58f7fc86db |
children | 4050675965ea |
comparison
equal
deleted
inserted
replaced
630:4cd81bdbf15c | 631:185ba2f91f59 |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File comm.asm combined next generation V3.04.3 | 3 ; File comm.asm combined next generation V3.08.8 |
4 ; | 4 ; |
5 ; RS232 via USB | 5 ; RS232 via USB |
6 ; | 6 ; |
7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
9 ; HISTORY | 9 ; HISTORY |
10 ; 2011-08-22 : [mH] Creation | 10 ; 2011-08-22 : [mH] Creation |
11 ; 2012-02-11 : [jDG] Added "c" set custom text, and "i" identify | 11 ; 2012-02-11 : [jDG] Added 0x63 set custom text, and "i" identify |
12 | 12 |
13 #include "hwos.inc" | 13 #include "hwos.inc" |
14 #include "eeprom_rs232.inc" | 14 #include "eeprom_rs232.inc" |
15 #include "tft.inc" | 15 #include "tft.inc" |
16 #include "wait.inc" | 16 #include "wait.inc" |
21 #include "surfmode.inc" | 21 #include "surfmode.inc" |
22 #include "rtc.inc" | 22 #include "rtc.inc" |
23 #include "adc_lightsensor.inc" | 23 #include "adc_lightsensor.inc" |
24 #include "shared_definitions.h" | 24 #include "shared_definitions.h" |
25 #include "math.inc" | 25 #include "math.inc" |
26 #include "i2c.inc" | |
27 #include "logbook.inc" | |
28 | |
26 | 29 |
27 extern restart | 30 extern restart |
28 extern option_reset_all | 31 extern option_reset_all |
29 extern option_check_all | 32 extern option_check_and_store_all |
33 extern option_read_serial | |
34 extern option_write_serial | |
30 extern gaslist_cleanup_list | 35 extern gaslist_cleanup_list |
31 extern option_save_all | 36 extern eeprom_deco_data_write |
32 extern vault_decodata_into_eeprom | 37 |
33 | 38 |
34 | 39 ; timeouts |
35 #DEFINE timeout_comm_pre_mode .240 ; timeout before communication is established | 40 #DEFINE timeout_comm_pre_mode .240 ; [sec] timeout before communication is established |
36 #DEFINE timeout_service_mode .120 ; timeout when communication is established | 41 #DEFINE timeout_service_mode .120 ; [sec] timeout when communication is established |
37 | 42 |
38 #DEFINE comm_title_row .0 ; positioning of title | 43 ; positioning of title |
44 #DEFINE comm_title_row .0 | |
39 #DEFINE comm_title_column_usb .40 | 45 #DEFINE comm_title_column_usb .40 |
40 #DEFINE comm_title_column_ble .25 | 46 #DEFINE comm_title_column_ble .25 |
41 | 47 |
42 #DEFINE comm_string_row .30 ; positioning of host-sent text messages | 48 ; positioning of host-sent text messages |
49 #DEFINE comm_string_row .30 | |
43 #DEFINE comm_string_column .40 | 50 #DEFINE comm_string_column .40 |
44 | 51 |
45 #DEFINE comm_status1_row .70 ; positioning of COMM mode status messages | 52 ; positioning of COMM mode status messages |
53 #DEFINE comm_status1_row .70 | |
46 #DEFINE comm_status1_column .10 | 54 #DEFINE comm_status1_column .10 |
47 #DEFINE comm_status2_row .100 | 55 #DEFINE comm_status2_row .100 |
48 #DEFINE comm_status2_column comm_status1_column | 56 #DEFINE comm_status2_column comm_status1_column |
49 #DEFINE comm_status3_row .130 | 57 #DEFINE comm_status3_row .130 |
50 #DEFINE comm_status3_column comm_status1_column | 58 #DEFINE comm_status3_column comm_status1_column |
51 #DEFINE comm_status4_row .160 | 59 #DEFINE comm_status4_row .160 |
52 #DEFINE comm_status4_column comm_status1_column | 60 #DEFINE comm_status4_column comm_status1_column |
53 | 61 |
54 #DEFINE comm_warning_row .160 ; positioning of COMM mode warning messages | 62 ; positioning of COMM mode warning icon |
63 #DEFINE comm_warning_row .160 | |
55 #DEFINE comm_warning_column .65 | 64 #DEFINE comm_warning_column .65 |
65 | |
66 | |
67 ;#DEFINE testloop_avail ; uncomment if testloop code is available | |
56 | 68 |
57 | 69 |
58 comm CODE | 70 comm CODE |
59 | 71 |
60 ;============================================================================= | 72 ;============================================================================= |
61 | 73 |
62 global comm_mode_usb | 74 global comm_mode_usb |
63 comm_mode_usb: ; entry point for comm mode via USB | 75 comm_mode_usb: ; entry point for comm mode via USB |
64 WAITMS d'1' ; wait 1 ms | 76 WAITMS d'1' ; wait 1 ms |
65 btfss vusb_in ; USB still plugged in? | 77 btfss vusb_in ; USB still plugged in? |
66 return ; NO - it was only a glitch, abort | |
67 WAITMS d'1' ; wait 1 ms | |
68 btfss vusb_in ; USB still plugged in? | |
69 return ; NO - it was only a glitch, abort | 78 return ; NO - it was only a glitch, abort |
70 bsf aux_flag ; YES - remember to show USB title | 79 WAITMS d'1' ; YES - wait 1 ms |
71 bra comm_mode_common ; - continue with common part | 80 btfss vusb_in ; - USB still plugged in? |
81 return ; NO - it was only a glitch, abort | |
82 bsf aux_flag ; YES - remember to show USB title | |
83 bra comm_mode_common ; - continue with common part | |
72 | 84 |
73 global comm_mode_ble | 85 global comm_mode_ble |
74 comm_mode_ble: ; entry point for comm mode via BLE | 86 comm_mode_ble: ; entry point for comm mode via BLE |
75 bcf aux_flag ; remember to show BLE title | 87 bcf aux_flag ; remember to show BLE title |
76 ;bra comm_mode_common ; continue with common part | 88 ;bra comm_mode_common ; continue with common part |
77 | 89 |
78 comm_mode_common: | 90 comm_mode_common: |
79 clrf STKPTR ; clear return addresses stack | 91 clrf STKPTR ; reset addresses stack |
80 call TFT_ClearScreen ; clear screen | 92 call TFT_ClearScreen ; clear screen |
81 WIN_COLOR color_greenish ; set color | 93 WIN_COLOR color_greenish ; set color |
94 | |
82 btfss aux_flag ; shall show USB title? | 95 btfss aux_flag ; shall show USB title? |
83 bra comm_mode_common_1 ; NO | 96 bra comm_mode_common_1 ; NO - show BLE title |
84 WIN_SMALL comm_title_column_usb, comm_title_row ; YES - set USB title position | 97 WIN_SMALL comm_title_column_usb, comm_title_row ; YES - set USB title position |
85 STRCPY_TEXT_PRINT tUsbTitle ; - print USB title text | 98 STRCPY_TEXT_PRINT tUsbTitle ; - print USB title text |
86 bra comm_mode_common_2 | 99 bra comm_mode_common_2 ; - continue with common part |
100 | |
87 comm_mode_common_1: | 101 comm_mode_common_1: |
88 WIN_SMALL comm_title_column_ble, comm_title_row ; set BLE title position | 102 WIN_SMALL comm_title_column_ble, comm_title_row ; set BLE title position |
89 STRCPY_TEXT_PRINT tBleTitle ; print BLE title text | 103 STRCPY_TEXT_PRINT tBleTitle ; print BLE title text |
104 ;bra comm_mode_common_2 ; continue with common part | |
105 | |
90 comm_mode_common_2: | 106 comm_mode_common_2: |
91 call TFT_standard_color ; set standard color | 107 call TFT_standard_color ; set standard color |
92 WIN_TOP .10 ; positioning of USB/BLE logo, row | 108 WIN_TOP .10 ; set position of USB/BLE logo, row |
93 WIN_LEFT .1 ; positioning of USB/BLE logo, column | 109 WIN_LEFT .1 ; set position of USB/BLE logo, column |
94 btfsc battery_gauge_available ; "+" bootloader ? | 110 btfsc battery_gauge_available ; "+" bootloader ? |
95 bra comm_mode_common_3 ; NO | 111 bra comm_mode_common_3 ; NO - show logo type 1 |
96 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_2 ; YES - show USB/BLE logo 2 | 112 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_2 ; YES - show USB/BLE logo 2 |
97 bra comm_mode_common_4 | 113 bra comm_mode_common_4 ; - continue with common part |
114 | |
98 comm_mode_common_3: | 115 comm_mode_common_3: |
99 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_1 ; NO - show USB/BLE logo 1 | 116 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_1 ; show logo type 1 |
117 ;bra comm_mode_common_4 ; continue with common part | |
118 | |
100 comm_mode_common_4: | 119 comm_mode_common_4: |
101 WIN_SMALL comm_status1_column,comm_status1_row ; positioning of status message | 120 WIN_SMALL comm_status1_column,comm_status1_row ; print status message "starting..." |
102 STRCPY_TEXT_PRINT tUsbStarting ; print status message "starting..." | 121 STRCPY_TEXT_PRINT tUsbStarting ; ... |
122 | |
103 WIN_TINY .40,.240-.16 ; set output position to bottom line | 123 WIN_TINY .40,.240-.16 ; set output position to bottom line |
104 call TFT_show_serial_and_firmware ; show serial number and firmware version | 124 call TFT_show_serial_and_firmware ; show serial number and firmware version |
105 call option_save_all ; save all settings into EEPROM (comm mode may be entered after settings have been changed without leaving the menu in between) | |
106 | 125 |
107 IFDEF _screendump | 126 IFDEF _screendump |
108 bcf screen_dump_avail ; disable screen dump function | 127 bcf screen_dump_avail ; disable screen dump function |
109 ENDIF | 128 ENDIF |
110 | 129 |
111 bcf switch_right ; clear left-over right button event | 130 bcf switch_right ; clear potential left-over right button event |
112 bcf comm_service_enabled ; communication is not yet established | 131 call enable_rs232 ; enable serial comm, also sets CPU to normal speed |
113 bsf surfmode_menu ; flag that restart will be entered from surface menu / comm mode | 132 |
114 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet | 133 WIN_SMALL comm_status1_column+.80,comm_status1_row ; print (adding to status message) "done..." |
115 movwf comm_timeout_timer ; initialize timeout counter | 134 STRCPY_TEXT_PRINT tUsbStartDone ; ... |
116 WIN_SMALL comm_status1_column+.80,comm_status1_row | 135 |
117 STRCPY_TEXT_PRINT tUsbStartDone ; add to status message "done..." | 136 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet |
118 call enable_rs232 ; enable serial comm, also sets CPU to normal speed | 137 movwf comm_timeout_timer ; initialize timeout counter |
119 comm_mode1: | 138 |
120 bcf trigger_full_second ; clear 'one second elapsed' flag | 139 comm_mode_selection_loop: |
121 bcf LEDr ; switch off red LED / power down TR co-processor | 140 bcf trigger_full_second ; clear 'one second elapsed' flag |
122 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? | 141 bcf LEDr ; switch off red LED / power down TR co-processor |
123 bra comm_service_exit ; YES - timeout, exit comm mode | 142 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? |
124 comm_mode2: | 143 bra comm_service_exit ; YES - timeout, exit comm mode |
125 rcall comm_get_byte ; read 1 byte from RX buffer | 144 ;bra comm_mode_selection_loop_1 ; NO - try to receive a byte |
126 movlw 0xAA ; coding of service mode start byte: 0xAA | 145 comm_mode_selection_loop_1: |
127 cpfseq RCREG1 ; received service mode start byte? | 146 SERIAL_CC_RECEIVE lo ; (try to) receive 1 byte |
128 bra comm_mode2a ; NO - probe for download mode | 147 btfsc rs232_rx_timeout ; timeout? |
129 bra comm_mode2b ; YES - received start byte for service mode | 148 bra comm_mode_selection_loop_2 ; YES - check for comm mode termination |
130 comm_mode2a: | 149 movf lo,W ; NO - copy received byte to lo |
131 movlw 0xBB ; coding of download mode start byte: 0xBB | 150 xorlw 0xAA ; - service mode start byte received? |
132 cpfseq RCREG1 ; received download mode start byte? | 151 bz comm_service_mode_check ; YES - check if correct key will be send |
133 bra comm_mode2c ; NO | 152 movf lo,W ; NO - copy received byte to lo again |
134 bra comm_download_mode ; YES - received start byte for download mode | 153 xorlw 0xBB ; - download mode start byte received? |
135 comm_mode2c: | 154 bz comm_download_mode ; YES - enter command loop |
136 btfsc ble_available ; BLE available? | 155 ;bra comm_mode_selection_loop_2 ; NO - check for comm mode termination |
137 bra comm_mode4a ; YES - skip USB check check (required for very old OSTC sport) | 156 comm_mode_selection_loop_2: |
138 btfss vusb_in ; USB plugged in? | 157 btfsc ble_available ; BLE available? |
139 bra comm_service_exit_nousb_delay; NO - disconnected, exit comm mode | 158 bra comm_mode_selection_loop_3 ; YES - skip USB check check (required for very old OSTC sport) |
140 comm_mode4a: | 159 btfss vusb_in ; NO - USB plugged in? |
141 btfsc switch_right ; right button pressed? | 160 bra comm_service_exit_nousb_delay ; NO - disconnected, check for vusb_in glitch |
142 bra comm_service_exit ; YES - exit comm mode | 161 ;bra comm_mode_selection_loop_3 ; YES - check for exit button or continue looping |
143 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile? | 162 comm_mode_selection_loop_3: |
144 bra comm_mode1 ; YES - loop with clocking down timeout counter | 163 btfsc switch_right ; right button pressed? |
145 bra comm_mode2 ; NO - loop without clocking down timeout counter | 164 bra comm_service_exit ; YES - exit comm mode |
146 | 165 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile? |
147 ; received start byte for service mode | 166 bra comm_mode_selection_loop ; YES - loop with clocking down timeout counter |
148 comm_mode2b: | 167 bra comm_mode_selection_loop_1 ; NO - loop without clocking down timeout counter |
149 rcall comm_write_byte ; wait for completion of transmit | 168 |
150 movlw 0x4B ; prepare answer | 169 |
151 movwf TXREG1 ; send answer | 170 ;----------------------------------------------------------------------------- |
152 ; check if correct service key is received | 171 ; Received start byte for service mode, await service key |
153 rcall comm_get_byte ; receive first byte | 172 ; |
154 rcall comm_write_byte ; wait for completion of transmit | 173 comm_service_mode_check: |
155 movff RCREG1,TXREG1 ; echo received byte | 174 |
156 movlw UPPER comm_service_key ; load expected byte | 175 SERIAL_LC_SEND 0x4B ; request peer to send service key |
157 cpfseq RCREG1 ; received expected byte? | 176 |
158 bra comm_mode1 ; NO - restart | 177 ; receive a 3 byte service key transmitted in big-endian, echo each byte |
159 rcall comm_get_byte ; receive second byte | 178 |
160 rcall comm_write_byte ; wait for completion of transmit | 179 clrf WREG ; clear WREG |
161 movff RCREG1,TXREG1 ; echo received byte | 180 |
162 movlw HIGH (comm_service_key & 0xFFFF) ; load expected byte | 181 SERIAL_CC_RECEIVE lo ; receive 1st byte, store in lo |
163 cpfseq RCREG1 ; received expected byte? | 182 xorwf lo,W ; exclusive-or received byte into WREG |
164 bra comm_mode1 ; NO - restart | 183 xorlw UPPER (comm_service_key) ; exclusive-or expected byte into WREG |
165 rcall comm_get_byte ; receive third byte | 184 SERIAL_CC_SEND lo ; echo 1st byte |
166 rcall comm_write_byte ; wait for completion of transmit | 185 |
167 movff RCREG1,TXREG1 ; echo received byte | 186 SERIAL_CC_RECEIVE lo ; receive 2nd byte, store in lo |
168 movlw LOW comm_service_key ; load expected byte | 187 xorwf lo,W ; exclusive-or received byte into WREG |
169 cpfseq RCREG1 ; received expected byte? | 188 xorlw HIGH (comm_service_key & 0xFFFF) ; exclusive-or expected byte into WREG |
170 bra comm_mode1 ; NO - restart | 189 SERIAL_CC_SEND lo ; echo 2nd byte |
171 ; YES to all - enable com service mode | 190 |
172 WIN_SMALL comm_status2_column, comm_status2_row | 191 SERIAL_CC_RECEIVE lo ; receive 3rd byte, store in lo |
173 STRCPY_TEXT_PRINT tUsbServiceMode ; print service mode enabled message | 192 xorwf lo,W ; exclusive-or received byte into WREG |
174 bsf comm_service_enabled ; set flag for com service mode enabled | 193 xorlw LOW (comm_service_key & 0xFFFF) ; exclusive-or expected byte into WREG |
175 bra comm_download_mode0 ; continue using common routine | 194 SERIAL_CC_SEND lo ; echo 3rd byte |
195 | |
196 ; check for correct service key | |
197 tstfsz WREG ; received expected service key? | |
198 bra comm_mode_selection_loop ; NO - back to mode selection loop | |
199 WIN_SMALL comm_status2_column, comm_status2_row ; YES - print service mode enabled message | |
200 STRCPY_TEXT_PRINT tUsbServiceMode ; - ... | |
201 bsf comm_service_mode ; - enable service mode commands | |
202 bra comm_command_loop ; - enter command loop | |
203 | |
204 | |
205 ;----------------------------------------------------------------------------- | |
206 ; Received start byte for download mode | |
207 ; | |
208 comm_download_mode: | |
209 SERIAL_LC_SEND 0xBB ; inform peer download mode will be started | |
210 | |
211 WIN_SMALL comm_status2_column, comm_status2_row ; print download mode enabled message | |
212 STRCPY_TEXT_PRINT tUsbDownloadMode ; ... | |
213 bcf comm_service_mode ; disable service mode commands | |
214 bra comm_command_loop ; enter command loop | |
215 | |
216 | |
217 ;----------------------------------------------------------------------------- | |
218 ; Notify RX timeout occurred | |
219 ; | |
220 comm_command_timeout: | |
221 ; select font and output position | |
222 WIN_SMALL comm_string_column, comm_string_row | |
223 call TFT_warning_color ; select color | |
224 STRCPY_PRINT "Data Rx Timeout" ; print failure message (fill to 15 chars) | |
225 call TFT_standard_color ; back to standard color | |
226 bra comm_command_loop ; re-enter command loop | |
227 | |
228 | |
229 ;----------------------------------------------------------------------------- | |
230 ; Notify error in parameters | |
231 ; | |
232 comm_command_error: | |
233 ; select font and output position | |
234 WIN_SMALL comm_string_column, comm_string_row | |
235 call TFT_warning_color ; switch to waring color | |
236 STRCPY_PRINT "Parameter Error" ; print failure message (fill to 15 chars) | |
237 call TFT_standard_color ; back to standard color | |
238 ;bra comm_command_loop ; re-enter command loop | |
239 | |
240 | |
241 ;----------------------------------------------------------------------------- | |
242 ; Command loop: wait for a command | |
243 ; | |
244 comm_command_loop: | |
245 ; (re-)initialize | |
246 bsf INTCON,GIE ; re-enable all interrupts | |
247 movlw timeout_service_mode ; get timeout value | |
248 movwf comm_timeout_timer ; reload timeout timer | |
249 | |
250 ; request peer to send a command | |
251 movlw 0x4D ; default request code is 0x4D for download mode active | |
252 btfsc comm_service_mode ; service mode enabled? | |
253 movlw 0x4C ; YES - change request to 0x4C for service mode active | |
254 SERIAL_CC_SEND WREG ; send request | |
255 | |
256 ; wait for peer to send a command | |
257 comm_command_loop_wait: | |
258 SERIAL_CC_RECEIVE lo ; (try to) receive a command byte | |
259 btfss rs232_rx_timeout ; timeout? | |
260 bra comm_command_decode ; NO - decode and execute the command | |
261 btfsc comm_service_mode ; YES - service mode enabled? | |
262 btg LEDr ; YES - blink in service mode | |
263 btfsc ble_available ; - BLE available? | |
264 bra comm_command_loop_wait_1 ; YES - skip USB check (required for very old OSTC sport) | |
265 btfss vusb_in ; NO - USB still plugged in? | |
266 bra comm_service_exit_nousb ; NO - disconnected -> exit comm mode | |
267 comm_command_loop_wait_1: | |
268 btfsc switch_right ; right button (abort) pressed? | |
269 bra comm_service_exit ; YES - exit comm mode | |
270 btfss trigger_full_second ; NO - did 1 second elapsed meanwhile? | |
271 bra comm_command_loop_wait ; NO - loop | |
272 dcfsnz comm_timeout_timer,F ; YES - decrement the timeout timer, reached zero? | |
273 bra comm_service_exit ; YES - exit comm mode | |
274 bcf trigger_full_second ; NO - clear 'one second elapsed' flag | |
275 bra comm_command_loop_wait ; - loop | |
276 | |
277 | |
278 ;----------------------------------------------------------------------------- | |
279 ; Macro for easier writing of command decoding rules | |
280 ; | |
281 command_decode macro command_id,command_function | |
282 movf lo,W ; copy received command to WREG | |
283 xorlw command_id ; exclusive-or with command ID | |
284 btfsc STATUS,Z ; received command = command ID ? | |
285 goto command_function ; YES - execute command | |
286 endm | |
287 | |
288 ;----------------------------------------------------------------------------- | |
289 ; Decode and execute a command | |
290 ; | |
291 comm_command_decode: | |
292 bcf LEDr ; switch off red led | |
293 | |
294 ; decode and execute standard commands | |
295 command_decode 0x6E,comm_show_text ; n show a text on the screen | |
296 command_decode 0x69,comm_identify ; i send ID: serial, firmware, and custom text | |
297 command_decode 0x6A,comm_hardware_descriptor ; j send ID: hardware descriptor byte | |
298 command_decode 0x60,comm_feature_and_hardware ; ' send ID: more detailed information | |
299 command_decode 0x6D,comm_send_headers_short ; m send all headers in compact format | |
300 command_decode 0x61,comm_send_headers_full ; a send all headers is full format | |
301 command_decode 0x66,comm_send_dive ; f send header and profile for one dive | |
302 command_decode 0x62,comm_set_time ; b set the real time clock | |
303 command_decode 0x63,comm_set_custom_text ; c write a new custom text | |
304 command_decode 0x72,comm_read_option ; r read an option value | |
305 command_decode 0x77,comm_write_option ; w write an option value (into RAM) | |
306 command_decode 0x78,comm_option_reset_all ; x reset all option values to their factory default | |
307 command_decode 0xFF,comm_service_exit ; exit comm mode | |
308 IFDEF _screendump | |
309 command_decode 0x6C,TFT_dump_screen ; l dump the screen contents | |
310 ENDIF | |
311 | |
312 btfss comm_service_mode ; service mode enabled? | |
313 bra comm_command_loop ; NO - ignore unrecognized command, back to command loop | |
314 | |
315 ; decode and execute additional service mode commands | |
316 command_decode 0x23,comm_reset_battery_gauge ; # reset the battery gauge registers | |
317 command_decode 0x22,comm_erase_complete_logbook ; " reset all logbook pointers and the logbook | |
318 command_decode 0x20,comm_read_range ;' ' read a memory range from the external FLASH | |
319 command_decode 0x40,comm_erase_4kb ; @ erase one 4 kB block - Warning: no confirmation or built-in safety here... | |
320 command_decode 0x42,comm_erase_range4kb ; B erase a range of 4 kB blocks - Warning: no confirmation or built-in safety here... | |
321 command_decode 0x30,comm_write_range_stream ; 0 write a stream of bytes starting at ext_flash_address:3 until timeout | |
322 command_decode 0x31,comm_write_range_block ; 1 write a block of 256 bytes starting at ext_flash_address:3 | |
323 command_decode 0x50,comm_firmware_update ; P initiate firmware update | |
324 command_decode 0xC1,comm_cold_start ; start low-level bootloader | |
325 IFDEF testloop_avail | |
326 command_decode 0x74,testloop ; t start raw-data test loop | |
327 ENDIF | |
328 | |
329 bra comm_command_loop ; ignore unrecognized command, back to command loop | |
330 | |
331 | |
332 ;----------------------------------------------------------------------------- | |
333 ; Exit comm mode | |
334 ; | |
335 comm_service_exit: | |
336 WIN_SMALL comm_status3_column, comm_status3_row ; print "Exited" message | |
337 STRCPY_TEXT_PRINT tUsbExit ; ... | |
338 bra comm_service_exit_common ; acknowledge exit command and restart | |
176 | 339 |
177 comm_service_exit_nousb_delay: | 340 comm_service_exit_nousb_delay: |
178 WAITMS d'200' ; wait 200 ms | 341 WAITMS d'200' ; wait 200 ms |
179 btfsc vusb_in ; USB plugged in? | 342 btfsc vusb_in ; USB sensed again? |
180 bra comm_mode4a ; YES - (still) connected, return | 343 bra comm_mode_selection_loop_3 ; YES - was just a glitch, continue |
344 ;bra comm_service_exit_nousb ; NO - proceed exiting | |
345 | |
181 comm_service_exit_nousb: | 346 comm_service_exit_nousb: |
182 bcf LEDr ; switch off red LED | 347 WIN_SMALL comm_status3_column, comm_status3_row ; print "Port closed" message |
183 WIN_SMALL comm_status3_column, comm_status3_row | 348 STRCPY_TEXT_PRINT tUsbClosed ; ... |
184 STRCPY_TEXT_PRINT tUsbClosed ; print port closed message | 349 ;bra comm_service_exit_common ; proceed exiting |
185 bra comm_service_exit_common ; exit to restart | 350 |
186 | |
187 comm_service_exit: | |
188 WIN_SMALL comm_status3_column, comm_status3_row | |
189 STRCPY_TEXT_PRINT tUsbExit ; print exited message | |
190 comm_service_exit_common: | 351 comm_service_exit_common: |
191 rcall comm_write_byte ; wait for completion of transmit | 352 SERIAL_LC_SEND 0xFF ; acknowledge exit command |
192 movlw 0xFF ; prepare reply "FF" | 353 call wait_1s ; wait <= 1 second |
193 movwf TXREG1 ; send reply | 354 call wait_1s ; wait 1 second |
194 call wait_1s ; wait <= 1 second | 355 call disable_rs232 ; shut down comm port |
195 call wait_1s ; wait 1 second | 356 bcf LEDr ; switch off red LED |
196 call disable_rs232 ; shut down comm port | 357 goto restart ; restart |
197 goto restart ; restart | 358 |
198 | 359 |
199 | 360 ;----------------------------------------------------------------------------- |
200 ;----------------------------------------------------------------------------- | 361 ; Set Real-Time-Clock |
201 ; Start Bootloader | 362 ; |
202 ; | 363 comm_set_time: |
203 comm_service_ll_bootloader: | 364 SERIAL_LC_SEND 0x62 ; acknowledge command |
204 bsf LEDr ; switch on red LED | 365 |
205 WIN_SMALL comm_status3_column, comm_status3_row | 366 ; receive 6 bytes coming in sequence: hour, minute, second, month, day, year |
206 STRCPY_TEXT_PRINT tUsbLlBld ; print low level bootloader started message | 367 SERIAL_RR_RECEIVE_RAM mpr,.6 |
207 WIN_TOP comm_warning_row ; set row for icon | 368 |
208 WIN_LEFT comm_warning_column ; set column for icon | 369 ; got all 6 bytes? |
209 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show the warning icon | 370 btfsc rs232_rx_timeout ; timeout? |
210 goto 0x1FF0C ; jump into the bootloader code | 371 bra comm_command_timeout ; YES - abort, back to command loop |
211 | 372 |
212 | 373 ; map the received bytes onto the rtc_latched variables |
213 ;----------------------------------------------------------------------------- | 374 movff mpr+0,rtc_latched_hour |
214 ; Send Firmware to Bootloader | 375 movff mpr+1,rtc_latched_mins |
215 ; | 376 movff mpr+2,rtc_latched_secs |
216 comm_send_firmware: | 377 movff mpr+3,rtc_latched_month |
217 movlw 0x50 ; prepare reply | 378 movff mpr+4,rtc_latched_day |
218 movwf TXREG1 ; send reply | 379 movff mpr+5,rtc_latched_year |
219 rcall comm_write_byte ; wait for completion of transmit | 380 |
220 lfsr FSR2,buffer ; load base address of buffer | 381 ; set the RTC |
221 movlw .5 ; read 5 bytes into buffer | 382 call rtc_set_rtc ; write time and date to RTC module |
222 movwf lo ; initialize loop counter | 383 |
223 movlw 0x55 ; initialize checksum byte | 384 bra comm_command_loop ; done, back to command loop |
224 movwf hi ; store in hi | 385 |
225 comm_send_firmware_loop: | 386 |
226 rcall comm_get_byte ; receive one byte | 387 ;----------------------------------------------------------------------------- |
227 btfsc rs232_rx_timeout ; got a byte? | 388 ; Write a 15 char text to the OSTC display |
228 bra comm_send_firmware_abort ; NO - abort | 389 ; |
229 movf RCREG1,W ; YES - copy received byte to WREG | 390 comm_show_text: |
230 movwf POSTINC2 ; - copy received byte to buffer | 391 ; set font and output position of the text to show |
231 xorwf hi,F ; - xor received byte into checksum | |
232 rlncf hi,F ; - rotate checksum byte | |
233 decfsz lo,F ; - decrement loop counter, done? | |
234 bra comm_send_firmware_loop ; NO - loop | |
235 movf hi,W ; YES - copy checksum to WREG, zero flag set? | |
236 bnz comm_send_firmware_failed ; NO - checksum test failed | |
237 movlw 0x4C ; YES - checksum ok, prepare reply | |
238 movwf TXREG1 ; - send reply | |
239 rcall comm_write_byte ; - wait for completion of transmit | |
240 call vault_decodata_into_eeprom ; - store last deco data (and time/date) to EEPROM | |
241 goto 0x1FDF0 ; - jump into the bootloader code | |
242 | |
243 comm_send_firmware_failed: | |
244 WIN_SMALL comm_string_column, comm_string_row | 392 WIN_SMALL comm_string_column, comm_string_row |
245 call TFT_warning_color ; set warning color | 393 |
246 STRCPY_PRINT "Checksum failed" ; print failure message | 394 SERIAL_LC_SEND 0x6E ; acknowledge command |
247 comm_send_firmware_abort: | 395 |
248 movlw 0xFF ; prepare reply for ABORTED | 396 SERIAL_RR_RECEIVE_RAM buffer,.16 ; (try to) receive 16 chars and write them to 'buffer' using FSR2 |
249 movwf TXREG1 ; send reply | 397 STRCAT_PRINT "" ; dump whatever was received to the screen |
250 bra comm_download_mode0 ; done | 398 |
251 | 399 bra comm_command_loop ; done, back to command loop |
252 | 400 |
253 ;----------------------------------------------------------------------------- | |
254 ; Reset to Dive 1 in Logbook | |
255 ; | |
256 comm_reset_logbook_pointers: | |
257 call eeprom_reset_logbook_pointers ; clear logbook pointers in EEPROM | |
258 call ext_flash_erase_logbook ; clear complete logbook(!) | |
259 bra comm_download_mode0 ; done | |
260 | |
261 ;----------------------------------------------------------------------------- | |
262 ; Reset Battery Gauge | |
263 ; | |
264 comm_reset_battery_gauge: ; reset battery gauge registers | |
265 call reset_battery_pointer ; reset battery pointer 0x07-0x0C and battery gauge | |
266 bra comm_download_mode0 ; done | |
267 | |
268 ;----------------------------------------------------------------------------- | |
269 ; Erase a Memory Range given byte Start Address and Number of 4 kB Blocks | |
270 ; | |
271 comm_erase_range4kb: | |
272 movlw 0x42 ; prepare reply | |
273 movwf TXREG1 ; send reply | |
274 rcall comm_write_byte ; wait for completion of transmit | |
275 bcf INTCON,GIE ; disable all interrupts | |
276 rcall comm_get_flash_address ; get three bytes start address or return | |
277 btfsc rs232_rx_timeout ; got start address? | |
278 bra comm_download_mode0 ; NO - done | |
279 rcall comm_get_byte ; YES - get number of blocks | |
280 btfsc rs232_rx_timeout ; - got number? | |
281 bra comm_download_mode0 ; NO - done | |
282 movff RCREG1,lo ; YES - copy number of blocks to lo | |
283 comm_erase_range4kb_loop: | |
284 call ext_flash_erase4kB ; - erase a memory block | |
285 movlw 0x10 ; - increase start address by 4096 (0x1000) | |
286 addwf ext_flash_address+1,F ; - ... | |
287 movlw .0 ; - ... | |
288 addwfc ext_flash_address+2,F ; - ... | |
289 decfsz lo,F ; - decrement block counter, all blocks done? | |
290 bra comm_erase_range4kb_loop ; NO - loop | |
291 bra comm_download_mode0 ; YES - done | |
292 | |
293 ;----------------------------------------------------------------------------- | |
294 ; Erase one Memory Block of 4 kB Size | |
295 ; | |
296 comm_erase_4kb: | |
297 bcf INTCON,GIE ; disable all interrupts | |
298 rcall comm_get_flash_address ; get three bytes start address or return | |
299 btfsc rs232_rx_timeout ; got start address? | |
300 bra comm_download_mode0 ; NO - done | |
301 call ext_flash_erase4kB ; YES - erase memory block | |
302 bra comm_download_mode0 ; - done | |
303 | |
304 ;----------------------------------------------------------------------------- | |
305 ; Write a Stream of Data Bytes to Memory | |
306 ; | |
307 comm_write_range: | |
308 movlw 0x30 ; prepare reply | |
309 movwf TXREG1 ; send reply | |
310 rcall comm_write_byte ; wait for completion of transmit | |
311 bcf INTCON,GIE ; disable all interrupts | |
312 rcall comm_get_flash_address ; get three bytes starts address or return | |
313 btfsc rs232_rx_timeout ; got start address? | |
314 bra comm_download_mode0 ; NO - done | |
315 comm_write_range_loop: | |
316 rcall comm_get_byte ; YES - get data byte to write to memory | |
317 btfsc rs232_rx_timeout ; got byte? | |
318 bra comm_download_mode0 ; NO - done | |
319 movf RCREG1,W ; YES - copy received data byte to WREG | |
320 ; bsf NCTS ; - hold Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
321 call ext_flash_byte_write_comms ; - write data byte to flash memory | |
322 ; bcf NCTS ; - release Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
323 call incf_ext_flash_address_p1 ; - increase address | |
324 bra comm_write_range_loop ; - loop | |
325 | |
326 | |
327 ;----------------------------------------------------------------------------- | |
328 ; Read a Memory Section given by Start Address and Length | |
329 ; | |
330 comm_send_range: | |
331 movlw 0x20 ; prepare reply | |
332 movwf TXREG1 ; send reply | |
333 rcall comm_write_byte ; wait for completion of transmit | |
334 bcf INTCON,GIE ; disable all interrupts | |
335 rcall comm_get_flash_address ; get three bytes start address or return | |
336 btfsc rs232_rx_timeout ; got start address? | |
337 bra comm_download_mode0 ; NO - done | |
338 rcall comm_get_byte ; get length, 3rd byte | |
339 btfsc rs232_rx_timeout ; got byte? | |
340 bra comm_download_mode0 ; NO - done | |
341 movff RCREG1,up ; store length, 3rd byte | |
342 rcall comm_get_byte ; get length, 2nd byte | |
343 btfsc rs232_rx_timeout ; got byte? | |
344 bra comm_download_mode0 ; NO - done | |
345 movff RCREG1,hi ; store length, 2nd byte | |
346 rcall comm_get_byte ; get length, 1st byte | |
347 btfsc rs232_rx_timeout ; got byte? | |
348 bra comm_download_mode0 ; NO - done | |
349 movff RCREG1,lo ; store length, 1st byte | |
350 ; if lo==0, we must precondition hi because there are too many bytes sent | |
351 movf lo,W | |
352 bnz $+4 | |
353 decf hi,F | |
354 movlw 0x40 | |
355 cpfslt up ; up > 0x3F ? | |
356 bra comm_download_mode0 ; YES - abort | |
357 ; 6 bytes received, send data | |
358 ; needs ext_flash_address:3 start address and up:hi:lo amount | |
359 call ext_flash_read_block_start | |
360 movwf TXREG1 | |
361 bra comm_send_range24 ; counter 24 bit | |
362 comm_send_range24_loop: | |
363 call ext_flash_read_block ; read one byte | |
364 movwf TXREG1 ; start new transmit | |
365 comm_send_range24: | |
366 rcall comm_write_byte ; wait for completion of transmit | |
367 decfsz lo,F | |
368 bra comm_send_range24_loop | |
369 decf hi,F | |
370 movlw 0xFF | |
371 cpfseq hi | |
372 bra comm_send_range24_loop | |
373 decf up,F | |
374 movlw 0xFF | |
375 cpfseq up | |
376 bra comm_send_range24_loop | |
377 call ext_flash_read_block_stop | |
378 bra comm_download_mode0 ; done | |
379 | |
380 ;----------------------------------------------------------------------------- | |
381 | |
382 comm_get_flash_address: | |
383 rcall comm_get_byte | |
384 btfsc rs232_rx_timeout ; got byte? | |
385 return ; NO - return | |
386 movff RCREG1,ext_flash_address+2 | |
387 rcall comm_get_byte | |
388 btfsc rs232_rx_timeout ; got byte? | |
389 return ; NO - return | |
390 movff RCREG1,ext_flash_address+1 | |
391 rcall comm_get_byte | |
392 btfsc rs232_rx_timeout ; got byte? | |
393 return ; NO - return | |
394 movff RCREG1,ext_flash_address+0 | |
395 return | |
396 | |
397 ;----------------------------------------------------------------------------- | |
398 | |
399 comm_download_mode: | |
400 ; Enable comm download mode | |
401 WIN_SMALL comm_status2_column, comm_status2_row | |
402 STRCPY_TEXT_PRINT tUsbDownloadMode ; download mode enabled | |
403 bsf INTCON,GIE ; all interrupts on | |
404 rcall comm_write_byte ; wait for completion of transmit | |
405 movlw 0xBB ; command echo | |
406 movwf TXREG1 ; send answer | |
407 comm_download_mode0: | |
408 bsf INTCON,GIE ; all interrupts on | |
409 rcall comm_write_byte ; wait for completion of transmit | |
410 movlw 0x4C ; default reply is 4C for service mode | |
411 btfss comm_service_enabled ; com service enabled? | |
412 movlw 0x4D ; NO - change to reply 4D for download mode | |
413 movwf TXREG1 ; send answer | |
414 movlw timeout_service_mode ; get timeout value | |
415 movwf comm_timeout_timer ; load into timeout counter | |
416 bcf switch_right ; clear left-over button event | |
417 comm_download_mode1: | |
418 bcf trigger_full_second ; clear 'one second elapsed' flag | |
419 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? | |
420 bra comm_service_exit ; YES - exit | |
421 comm_download_mode2: | |
422 rcall comm_get_byte ; NO - check for a byte | |
423 btfsc comm_service_enabled ; com service mode enabled? | |
424 btg LEDr ; YES - blink in service mode | |
425 btfsc ble_available ; BLE available? | |
426 bra comm_download_mode3 ; YES - skip USB check (required for very old OSTC sport) | |
427 btfss vusb_in ; USB plugged in? | |
428 bra comm_service_exit_nousb ; NO - disconnected -> exit | |
429 comm_download_mode3: | |
430 btfsc switch_right ; shall abort? | |
431 bra comm_service_exit ; YES | |
432 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile? | |
433 bra comm_download_mode1 ; YES - check for timeout | |
434 btfsc rs232_rx_timeout ; NO - got a byte? | |
435 bra comm_download_mode2 ; NO - loop waiting for command byte | |
436 ; Command received | |
437 bcf LEDr | |
438 movlw 0xFF | |
439 cpfseq RCREG1 | |
440 bra $+4 | |
441 bra comm_service_exit ; exit | |
442 movlw "a" | |
443 cpfseq RCREG1 | |
444 bra $+4 | |
445 bra comm_send_headers ; send all 256 dive headers | |
446 movlw "b" | |
447 cpfseq RCREG1 | |
448 bra $+4 | |
449 bra comm_set_time ; read time and date from the PC and set clock | |
450 movlw "c" | |
451 cpfseq RCREG1 | |
452 bra $+4 | |
453 bra comm_set_custom_text ; send a opt_name_length byte string of custom text | |
454 movlw "f" ; 0x66 | |
455 cpfseq RCREG1 | |
456 bra $+4 | |
457 bra comm_send_dive ; send header and profile for one dive | |
458 movlw "i" | |
459 cpfseq RCREG1 | |
460 bra $+4 | |
461 bra comm_identify ; send firmware, serial, etc. | |
462 movlw "j" | |
463 cpfseq RCREG1 | |
464 bra $+4 | |
465 bra comm_hardware_descriptor ; send hardware descriptor byte | |
466 movlw 0x60 | |
467 cpfseq RCREG1 | |
468 bra $+4 | |
469 bra comm_feature_and_hardware ; send more detailed information | |
470 movlw "n" | |
471 cpfseq RCREG1 | |
472 bra $+4 | |
473 goto comm_send_string ; send a 15 byte string to the screen | |
474 movlw "m" | |
475 cpfseq RCREG1 | |
476 bra $+4 | |
477 goto comm_send_compact_headers ; send all 256 compact headers | |
478 IFDEF _screendump | |
479 movlw "l" | |
480 cpfseq RCREG1 | |
481 bra $+4 | |
482 call TFT_dump_screen ; dump the screen contents | |
483 ENDIF | |
484 movlw "r" | |
485 cpfseq RCREG1 | |
486 bra $+4 | |
487 bra comm_read_setting ; read a setting (and send via USB) | |
488 movlw "w" | |
489 cpfseq RCREG1 | |
490 bra $+4 | |
491 bra comm_write_setting ; write a setting (into RAM) | |
492 movlw "x" | |
493 cpfseq RCREG1 | |
494 bra $+4 | |
495 bra comm_option_reset_all ; reset all options to factory default | |
496 | |
497 btfss comm_service_enabled ; done for download mode | |
498 bra comm_download_mode0 ; loop with timeout reset | |
499 | |
500 movlw 0x20 | |
501 cpfseq RCREG1 | |
502 bra $+4 | |
503 bra comm_send_range ; send hi:lo:ext_flash_rw bytes starting from ext_flash_address:3 | |
504 movlw 0x22 | |
505 cpfseq RCREG1 | |
506 bra $+4 | |
507 bra comm_reset_logbook_pointers ; reset all logbook pointers and the logbook | |
508 movlw 0x23 | |
509 cpfseq RCREG1 | |
510 bra $+4 | |
511 bra comm_reset_battery_gauge ; reset battery gauge registers | |
512 movlw 0x30 | |
513 cpfseq RCREG1 | |
514 bra $+4 | |
515 bra comm_write_range ; write bytes starting from ext_flash_address:3 (stop when timeout) | |
516 movlw 0x40 | |
517 cpfseq RCREG1 | |
518 bra $+4 | |
519 bra comm_erase_4kb ; erase 4 kB block from ext_flash_address:3 (Warning: no confirmation or built-in security here...) | |
520 movlw 0x42 | |
521 cpfseq RCREG1 | |
522 bra $+4 | |
523 bra comm_erase_range4kb ; erase range in 4 kB steps (get 3 bytes address and 1 byte amount of 4 kB blocks) | |
524 movlw 0x50 | |
525 cpfseq RCREG1 | |
526 bra $+4 | |
527 bra comm_send_firmware ; send firmware to bootloader | |
528 ; movlw "t" | |
529 ; cpfseq RCREG1 | |
530 ; bra $+4 | |
531 ; goto testloop ; start raw-data test loop | |
532 movlw 0xC1 | |
533 cpfseq RCREG1 | |
534 bra $+4 | |
535 bra comm_service_ll_bootloader ; start low-level bootloader | |
536 bra comm_download_mode0 ; loop with timeout reset | |
537 | |
538 ;----------------------------------------------------------------------------- | |
539 | |
540 comm_send_compact_headers: | |
541 movlw "m" ; send echo | |
542 movwf TXREG1 | |
543 ; send 13 bytes/dive (compact header) | |
544 ; 1st: 200009h-200016h | |
545 ; 2nd: 201009h-201016h | |
546 ; 3rd: 202009h-202016h | |
547 ; 100: 264009h-264016h | |
548 ; 256: 2FF009h-2FF016h | |
549 movlw 0x1F | |
550 movwf ext_flash_address+2 | |
551 movlw 0xF0 | |
552 movwf ext_flash_address+1 | |
553 | |
554 comm_send_compact_headers2: | |
555 movlw 0x09 | |
556 movwf ext_flash_address+0 | |
557 ; adjust address for next dive | |
558 movlw 0x10 | |
559 addwf ext_flash_address+1 | |
560 movlw 0x00 | |
561 addwfc ext_flash_address+2 | |
562 | |
563 movlw 0x30 | |
564 cpfseq ext_flash_address+2 ; all 256 dive send? | |
565 bra comm_send_compact_headers4 ; NO - continue | |
566 bra comm_download_mode0 ; done, loop with timeout reset | |
567 | |
568 comm_send_compact_headers4: | |
569 movlw .13 | |
570 movwf lo ; counter | |
571 rcall comm_write_byte ; wait for completion of transmit | |
572 call ext_flash_read_block_start ; 1st byte | |
573 movwf TXREG1 | |
574 bra comm_send_compact_headers3 ; counter 24 bit | |
575 comm_send_compact_headers_loop: | |
576 call ext_flash_read_block ; read one byte | |
577 movwf TXREG1 ; start new transmit | |
578 comm_send_compact_headers3: | |
579 rcall comm_write_byte ; wait for completion of transmit | |
580 decfsz lo,F | |
581 bra comm_send_compact_headers_loop | |
582 call ext_flash_read_block_stop | |
583 | |
584 ; Offset to total dive counter | |
585 movlw .80 | |
586 movwf ext_flash_address+0 | |
587 call ext_flash_read_block_start ; 1st byte | |
588 movwf TXREG1 | |
589 rcall comm_write_byte ; wait for completion of transmit | |
590 call ext_flash_read_block ; 2nd byte | |
591 movwf TXREG1 | |
592 call ext_flash_read_block_stop | |
593 rcall comm_write_byte ; wait for completion of transmit | |
594 | |
595 ; Offset to Logbook-Profile version | |
596 movlw .8 | |
597 movwf ext_flash_address+0 | |
598 call ext_flash_byte_read ; get byte | |
599 movwf TXREG1 | |
600 rcall comm_write_byte ; wait for completion of transmit | |
601 bra comm_send_compact_headers2 ; continue | |
602 | |
603 | |
604 ;----------------------------------------------------------------------------- | |
605 | |
606 comm_send_headers: | |
607 movlw "a" ; send echo | |
608 movwf TXREG1 | |
609 ; Send 256 bytes/dive (Header) | |
610 ; 1st: 200000h-2000FFh | |
611 ; 2nd: 201000h-2010FFh | |
612 ; 3rd: 202000h-2020FFh | |
613 ; 100: 264000h-2640FFh | |
614 ; 256: 2FF000h-2FF0FFh | |
615 movlw 0x1F | |
616 movwf ext_flash_address+2 | |
617 movlw 0xF0 | |
618 movwf ext_flash_address+1 | |
619 comm_send_headers2: | |
620 clrf ext_flash_address+0 | |
621 ; Adjust address for next dive | |
622 movlw 0x10 | |
623 addwf ext_flash_address+1 | |
624 movlw 0x00 | |
625 addwfc ext_flash_address+2 | |
626 movlw 0x30 | |
627 cpfseq ext_flash_address+2 ; all 256 dive send? | |
628 bra comm_send_headers4 ; NO - continue | |
629 bra comm_download_mode0 ; done, loop with timeout reset | |
630 comm_send_headers4: | |
631 clrf lo ; counter | |
632 rcall comm_write_byte ; wait for completion of transmit | |
633 call ext_flash_read_block_start ; 1st byte | |
634 movwf TXREG1 | |
635 bra comm_send_headers3 ; counter 24 bit | |
636 comm_send_headers_loop: | |
637 call ext_flash_read_block ; read one byte | |
638 movwf TXREG1 ; start new transmit | |
639 comm_send_headers3: | |
640 rcall comm_write_byte ; wait for completion of transmit | |
641 decfsz lo,F | |
642 bra comm_send_headers_loop | |
643 call ext_flash_read_block_stop | |
644 bra comm_send_headers2 ; continue | |
645 | |
646 ;----------------------------------------------------------------------------- | |
647 | |
648 comm_option_reset_all: ; reset all options to factory default | |
649 movlw "x" ; send echo | |
650 movwf TXREG1 | |
651 call option_reset_all | |
652 bra comm_download_mode0 ; done, back to loop with timeout reset | |
653 | |
654 ;----------------------------------------------------------------------------- | |
655 | |
656 comm_set_time: | |
657 movlw "b" ; send echo | |
658 movwf TXREG1 | |
659 | |
660 rcall comm_write_byte ; wait for completion of transmit | |
661 rcall comm_get_byte | |
662 btfsc rs232_rx_timeout ; got byte? | |
663 bra comm_download_mode0 ; NO - abort | |
664 movff RCREG1, rtc_latched_hour | |
665 rcall comm_get_byte | |
666 btfsc rs232_rx_timeout ; got byte? | |
667 bra comm_download_mode0 ; NO - abort | |
668 movff RCREG1, rtc_latched_mins | |
669 rcall comm_get_byte | |
670 btfsc rs232_rx_timeout ; got byte? | |
671 bra comm_download_mode0 ; NO - abort | |
672 movff RCREG1, rtc_latched_secs | |
673 rcall comm_get_byte | |
674 btfsc rs232_rx_timeout ; got byte? | |
675 bra comm_download_mode0 ; NO - abort | |
676 movff RCREG1, rtc_latched_month | |
677 rcall comm_get_byte | |
678 btfsc rs232_rx_timeout ; got byte? | |
679 bra comm_download_mode0 ; NO - abort | |
680 movff RCREG1, rtc_latched_day | |
681 rcall comm_get_byte | |
682 btfsc rs232_rx_timeout ; got byte? | |
683 bra comm_download_mode0 ; NO - abort | |
684 movff RCREG1, rtc_latched_year | |
685 call rtc_set_rtc ; write time and date to RTC module | |
686 bra comm_download_mode0 ; done, back to loop with timeout reset | |
687 | |
688 ;----------------------------------------------------------------------------- | |
689 ; Set custom text string (opt_name_length ASCII chars) | |
690 ; | |
691 | |
692 comm_set_custom_text: | |
693 movlw "c" ; send echo | |
694 movwf TXREG1 | |
695 rcall comm_write_byte ; wait for completion of transmit | |
696 lfsr FSR2,opt_name | |
697 movlw opt_name_length | |
698 movwf lo ; counter | |
699 comm_set_ctext_loop: | |
700 rcall comm_get_byte | |
701 btfsc rs232_rx_timeout ; got byte? | |
702 bra comm_set_ctext_loop_done ; NO - abort | |
703 movff RCREG1,POSTINC2 ; store character | |
704 decfsz lo,F | |
705 bra comm_set_ctext_loop | |
706 comm_set_ctext_loop_done: | |
707 tstfsz lo ; got opt_name_length bytes? | |
708 bra comm_set_ctext_loop_done2 ; NO - clear remaining chars | |
709 bra comm_download_mode0 ; done, loop with timeout reset | |
710 comm_set_ctext_loop_done2: | |
711 clrf POSTINC2 | |
712 decfsz lo,F | |
713 bra comm_set_ctext_loop_done2 | |
714 bra comm_download_mode0 ; done, loop with timeout reset | |
715 | 401 |
716 ;----------------------------------------------------------------------------- | 402 ;----------------------------------------------------------------------------- |
717 ; Reply Serial (2 bytes low:high), firmware (major.minor) and custom text | 403 ; Reply Serial (2 bytes low:high), firmware (major.minor) and custom text |
718 ; | 404 ; |
719 | |
720 comm_identify: | 405 comm_identify: |
721 movlw "i" ; send echo | 406 SERIAL_LC_SEND 0x69 ; acknowledge command |
722 movwf TXREG1 | 407 |
723 rcall comm_write_byte ; wait for completion of transmit | 408 ;---- send OSTC serial number |
724 | 409 call eeprom_serial_number_read ; read OSTC serial number |
725 ;---- Read serial from internal EEPROM address 0000 | 410 SERIAL_CC_SEND mpr+0 ; send serial number, low byte |
726 clrf EEADRH | 411 SERIAL_CC_SEND mpr+1 ; send serial number, high byte |
727 clrf EEADR ; get serial number LOW | 412 |
728 call read_eeprom ; read byte | 413 ;---- send firmware version |
729 movff EEDATA,lo | 414 SERIAL_LC_SEND fw_version_major ; send firmware version, major |
730 incf EEADR,F ; get serial number HIGH | 415 SERIAL_LC_SEND fw_version_minor ; send firmware version, minor |
731 call read_eeprom ; read byte | 416 |
732 movff EEDATA,hi | 417 ;---- send custom text |
733 | 418 SERIAL_RR_SEND_RAM opt_name,opt_name_length |
734 ;---- Emit serial number | 419 |
735 movff lo,TXREG1 | 420 bra comm_command_loop ; done, back to command loop |
736 rcall comm_write_byte ; wait for completion of transmit | |
737 movff hi,TXREG1 | |
738 rcall comm_write_byte ; wait for completion of transmit | |
739 | |
740 ;---- Emit firmware hi.lo | |
741 movlw softwareversion_x | |
742 movwf TXREG1 | |
743 rcall comm_write_byte ; wait for completion of transmit | |
744 movlw softwareversion_y | |
745 movwf TXREG1 | |
746 rcall comm_write_byte ; wait for completion of transmit | |
747 | |
748 ;---- Emit custom text | |
749 movlw opt_name_length | |
750 movwf hi | |
751 lfsr FSR2,opt_name | |
752 | |
753 common_identify_loop: | |
754 movff POSTINC2,TXREG1 | |
755 rcall comm_write_byte ; wait for completion of transmit | |
756 decfsz hi,F | |
757 bra common_identify_loop | |
758 | |
759 bra comm_download_mode0 ; done | |
760 | |
761 ;----------------------------------------------------------------------------- | |
762 | |
763 comm_get_byte: | |
764 goto rs232_get_byte ; ... and return | |
765 | |
766 comm_write_byte: ; wait for completion of transmit | |
767 goto rs232_wait_tx ; ... and return | |
768 | 421 |
769 | 422 |
770 ;----------------------------------------------------------------------------- | 423 ;----------------------------------------------------------------------------- |
771 ; Reply hardware descriptor byte | 424 ; Reply hardware descriptor byte |
772 ; | 425 ; |
773 comm_hardware_descriptor: | 426 comm_hardware_descriptor: |
774 movlw "j" ; prepare echo | 427 SERIAL_LC_SEND 0x6A ; acknowledge command |
775 movwf TXREG1 ; send echo | |
776 rcall comm_write_byte ; wait for completion of transmit | |
777 | 428 |
778 movf HW_descriptor,W ; get hardware descriptor | 429 movf HW_descriptor,W ; get hardware descriptor |
779 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | 430 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software |
780 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software | 431 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software |
781 movwf TXREG1 ; send hardware descriptor | 432 SERIAL_CC_SEND WREG ; send modified hardware descriptor |
782 | 433 |
783 bra comm_download_mode0 ; done | 434 bra comm_command_loop ; done, back to command loop |
784 | 435 |
436 | |
437 ;----------------------------------------------------------------------------- | |
438 ; Reply detailed hardware descriptor | |
439 ; | |
785 comm_feature_and_hardware: | 440 comm_feature_and_hardware: |
786 movlw 0x60 ; send echo | 441 SERIAL_LC_SEND 0x60 ; acknowledge command |
787 movwf TXREG1 | 442 |
788 rcall comm_write_byte ; wait for completion of transmit | 443 SERIAL_LC_SEND 0x00 ; send hardware high byte (fixed zero) |
789 | |
790 movlw 0x00 ; hardware high byte | |
791 movwf TXREG1 | |
792 rcall comm_write_byte ; wait for completion of transmit | |
793 | 444 |
794 movf HW_descriptor,W ; get hardware descriptor | 445 movf HW_descriptor,W ; get hardware descriptor |
795 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | 446 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software |
796 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software | 447 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software |
797 movwf TXREG1 ; send hardware descriptor | 448 SERIAL_CC_SEND WREG ; send modified hardware low byte |
798 rcall comm_write_byte ; wait for completion of transmit | 449 |
799 | 450 SERIAL_LC_SEND 0x00 ; send feature high byte (fixed zero) |
800 movlw 0x00 ; feature high Byte | 451 SERIAL_LC_SEND 0x00 ; send feature low byte (fixed zero) |
801 movwf TXREG1 | 452 |
802 rcall comm_write_byte ; wait for completion of transmit | 453 SERIAL_LC_SEND 0x00 ; send model descriptor byte (fixed zero) |
803 | 454 |
804 movlw 0x00 ; feature low Byte | 455 bra comm_command_loop ; done, back to command loop |
805 movwf TXREG1 | 456 |
806 rcall comm_write_byte ; wait for completion of transmit | 457 |
807 | 458 ;----------------------------------------------------------------------------- |
808 movlw 0x00 ; model descriptor byte | 459 |
809 movwf TXREG1 | 460 comm_send_headers_short: |
810 | 461 SERIAL_LC_SEND 0x6D ; acknowledge command |
811 bra comm_download_mode0 ; done | 462 |
812 | 463 ; send short header (16 bytes/dive) |
813 ;----------------------------------------------------------------------------- | 464 ; index 0: 0x200009 - 0x200016 + 0x200050 - 0x200051 + 0x200008 |
814 | 465 ; 1: 0x201009 - 0x201016 + 0x201050 - 0x201051 + 0x201008 |
466 ; 2: 0x202009 - 0x202016 + 0x202050 - 0x202051 + 0x202008 | |
467 ; ... | |
468 ; 255: 0x2FF009 - 0x2FF016 + 0x2FF050 - 0x2FF051 + 0x2FF008 | |
469 | |
470 clrf ex ; start with dive having index 0 | |
471 comm_send_headers_short_loop: | |
472 movf ex,W ; get index into WREG | |
473 call log_header_addr_by_index ; compute header start address from index, result in mpr | |
474 | |
475 ; assemble the short header - part 1 | |
476 movlw index_profile_byte_count ; adjust start address to first block to go into the short header | |
477 movwf mpr+0 ; ... | |
478 FLASH_RR_READ mpr,header_buffer,.13 ; read 13 bytes from header into buffer | |
479 | |
480 ; assemble the short header - part 2 | |
481 movlw index_total_dives ; adjust start address to second block to into the short header | |
482 movwf mpr+0 ; ... | |
483 FLASH_RR_READ mpr,header_buffer+.13,.2 ; read 2 bytes from header into buffer | |
484 | |
485 ; assemble the short header - part 3 | |
486 movlw index_profile_version ; adjust start address to third block to go into the short header | |
487 movwf mpr+0 ; ... | |
488 FLASH_RR_READ mpr,header_buffer+.15,.1 ; read 1 byte from header into buffer | |
489 | |
490 ; send the assembled short header | |
491 SERIAL_RR_SEND_RAM header_buffer,.16 ; send buffer, 16 bytes to do | |
492 | |
493 ; go to next header | |
494 incfsz ex ; increment index, wrap-around. i.e. all dives done ? | |
495 bra comm_send_headers_short_loop ; NO - loop | |
496 bra comm_command_loop ; YES - done, back to command loop | |
497 | |
498 | |
499 ;----------------------------------------------------------------------------- | |
500 | |
501 comm_send_headers_full: | |
502 SERIAL_LC_SEND 0x61 ; acknowledge command | |
503 | |
504 ; send complete headers (256 bytes/dive) | |
505 ; index 0: 0x200000 - 0x2000FF | |
506 ; 1: 0x201000 - 0x2010FF | |
507 ; 2: 0x202000 - 0x2020FF | |
508 ; ... | |
509 ; 255: 0x2FF000 - 0x2FF0FF | |
510 | |
511 clrf ex ; start with dive having index 0 | |
512 comm_send_headers_full_loop: | |
513 movf ex,W ; get index into WREG | |
514 call log_header_addr_by_index ; compute header start address from index, result in mpr | |
515 FLASH_RR_READ mpr,header_buffer,.256 ; get header from FLASH into memory | |
516 SERIAL_RR_SEND_RAM header_buffer,.256 ; send the header from memory to RS232 | |
517 incfsz ex ; increment index, wrap-around. i.e. all dives done ? | |
518 bra comm_send_headers_full_loop ; NO - loop | |
519 bra comm_command_loop ; YES - done, back to command loop | |
520 | |
521 | |
522 ;----------------------------------------------------------------------------- | |
523 ; Send one full dive | |
524 ; | |
815 comm_send_dive: | 525 comm_send_dive: |
816 movlw "f"; 0x66 ; send echo | 526 SERIAL_LC_SEND 0x66 ; acknowledge command |
817 movwf TXREG1 | 527 |
818 | 528 SERIAL_CC_RECEIVE WREG ; (try to) receive the dive index (0-255) |
819 rcall comm_get_byte | 529 btfsc rs232_rx_timeout ; got dive index? |
820 btfsc rs232_rx_timeout ; got byte? | 530 bra comm_command_timeout ; NO - abort, back to command loop |
821 bra comm_download_mode0 ; NO - abort! | 531 |
822 movff RCREG1,lo ; store dive number (0-255) | 532 call log_header_addr_by_index ; compute header start address from index, result in mpr |
823 ; First, send the header (again) | 533 FLASH_RR_READ mpr,header_buffer,.256; copy the complete header into the buffer |
824 ; set ext_flash_address:3 to TOC entry of this dive | 534 |
825 ; 1st: 200000h-200FFFh -> lo=0 | 535 ; get pointers and length of profile data |
826 ; 2nd: 201000h-201FFFh -> lo=1 | 536 MOVTT header_buffer+index_profile_start_address,ext_flash_address |
827 ; 3rd: 202000h-202FFFh -> lo=2 | 537 MOVTT header_buffer+index_profile_end_address, ext_flash_end_pointer |
828 ; 256: 2FF000h-2FFFFFh -> lo=255 | 538 MOVTT header_buffer+index_profile_byte_count, ext_flash_length_counter |
829 clrf ext_flash_address+0 | 539 |
830 clrf ext_flash_address+1 | 540 ; check if profile data are available |
831 movlw 0x20 | 541 movf ext_flash_address+0,W ; compare low byte of start and end pointer |
542 cpfseq ext_flash_end_pointer+0 ; equal? | |
543 bra comm_send_dive1 ; NO - profile data available, continue | |
544 | |
545 movf ext_flash_address+1,W ; compare high byte of start and end pointer | |
546 cpfseq ext_flash_end_pointer+1 ; equal? | |
547 bra comm_send_dive1 ; NO - profile data available, continue | |
548 | |
549 movf ext_flash_address+2,W ; compare upper byte of start and end pointer | |
550 cpfseq ext_flash_end_pointer+2 ; equal? | |
551 bra comm_send_dive1 ; NO - profile data available, continue | |
552 | |
553 bra comm_command_loop ; start = end -> no profile data available, abort, back to command loop | |
554 | |
555 comm_send_dive1: | |
556 ; send the header from the buffer | |
557 SERIAL_RR_SEND_RAM header_buffer,.256 | |
558 | |
559 ; send the profile directly from the FLASH | |
560 ext_flash_inc_address_0x20 .6 ; skip the first 6 bytes (short header) of the profile data | |
561 ext_flash_dec_length .3 ; adopt the length count (short by 3 bytes) | |
562 ext_flash_dec_length .1 ; decrement length count by 1 so that all bytes will be | |
563 ; done when the counter has wrapped around to 0xFFFFFF | |
564 movlw 0x20 ; now the length count is allowed to be 0x1FFFFF at max | |
565 cpfslt ext_flash_length_counter+2 ; length count < 0x20(0000) ? | |
566 bra comm_command_error ; NO - abort, back to command loop | |
567 call ext_flash_read_block_start ; YES - read first byte from FLASH into WREG | |
568 bra comm_send_dive_loop_start ; - jump into transmit loop | |
569 comm_send_dive_loop: | |
570 call ext_flash_read_block_0x20 ; read next byte into WREG | |
571 comm_send_dive_loop_start: | |
572 SERIAL_CC_SEND WREG ; transmit byte | |
573 ext_flash_dec_length .1 ; decrement length counter | |
574 btfss ext_flash_length_counter+2,7; under-run? | |
575 bra comm_send_dive_loop ; NO - continue loop | |
576 call ext_flash_read_block_stop ; YES - end reading from FLASH | |
577 bra comm_command_loop ; - done, back to command loop | |
578 | |
579 | |
580 ;----------------------------------------------------------------------------- | |
581 ; Reset all Options to Factory Default | |
582 ; | |
583 comm_option_reset_all: | |
584 SERIAL_LC_SEND 0x78 ; acknowledge command | |
585 call option_reset_all ; reset all options to factory default | |
586 bra comm_command_loop ; done, back to command loop | |
587 | |
588 | |
589 ;----------------------------------------------------------------------------- | |
590 ; Set Custom Text String (opt_name_length ASCII chars) | |
591 ; | |
592 comm_set_custom_text: | |
593 CLRR opt_name,opt_name_length ; clear old custom text | |
594 SERIAL_LC_SEND 0x63 ; acknowledge command | |
595 | |
596 ; receive new custom text (less than opt_name_length characters may be sent) | |
597 SERIAL_RR_RECEIVE_RAM opt_name,opt_name_length | |
598 | |
599 bra comm_command_loop ; done, back to command loop | |
600 | |
601 | |
602 ;----------------------------------------------------------------------------- | |
603 ; Reset Battery Gauge | |
604 ; | |
605 comm_reset_battery_gauge: | |
606 ; SERIAL_LC_SEND 0x23 ; acknowledge command (not done) | |
607 call reset_battery_gauge_and_lt2942 ; reset battery registers and battery gauge chip | |
608 bra comm_command_loop ; done, back to command loop | |
609 | |
610 | |
611 ;----------------------------------------------------------------------------- | |
612 ; Erase complete Logbook | |
613 ; | |
614 comm_erase_complete_logbook: | |
615 ; SERIAL_LC_SEND 0x22 ; acknowledge command (not done) | |
616 call erase_complete_logbook ; erase complete logbook | |
617 bra comm_command_loop ; done, back to command loop | |
618 | |
619 | |
620 ;----------------------------------------------------------------------------- | |
621 ; Start Bootloader (aka perform cold start) | |
622 ; | |
623 comm_cold_start: | |
624 ; SERIAL_LC_SEND 0xC1 ; acknowledge command (not done) | |
625 ; call rs232_wait_tx ; wait for completion of transmit before hardware goes into reboot | |
626 | |
627 WIN_SMALL comm_status3_column, comm_status3_row ; print "Low-level Bootloader" message | |
628 STRCPY_TEXT_PRINT tUsbLlBld ; ... | |
629 | |
630 WIN_TOP comm_warning_row ; set row for icon | |
631 WIN_LEFT comm_warning_column ; set column for icon | |
632 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show a warning icon | |
633 | |
634 bsf LEDr ; switch on red LED | |
635 | |
636 call eeprom_deco_data_write ; update deco data in EEPROM | |
637 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | |
638 btfsc options_changed ; do the options need to be stored to EEPROM ? | |
639 call option_check_and_store_all ; YES - check and store all option values in EEPROM | |
640 | |
641 goto 0x1FF0C ; jump into the bootloader code | |
642 | |
643 | |
644 ;----------------------------------------------------------------------------- | |
645 ; Send Firmware to Bootloader (aka initiate firmware update) | |
646 ; | |
647 comm_firmware_update: | |
648 SERIAL_LC_SEND 0x50 ; acknowledge command | |
649 | |
650 SERIAL_RR_RECEIVE_RAM buffer,.5 ; (try to) receive 5 byte checksum | |
651 btfsc rs232_rx_timeout ; got all 5 bytes? | |
652 bra comm_send_firmware_abort ; NO - abort | |
653 | |
654 ; check the checksum | |
655 movlw 0x55 ; initialize checksum check-byte | |
656 movwf hi ; store in hi | |
657 lfsr FSR2,buffer ; load base address of buffer | |
658 movlw .5 ; 5 bytes to process | |
659 movwf lo ; initialize loop counter | |
660 comm_firmware_update_loop: | |
661 movf POSTINC2,W ; get a checksum byte | |
662 xorwf hi,F ; xor checksum byte with check-byte | |
663 rlncf hi,F ; rotate check-byte | |
664 decfsz lo,F ; decrement loop counter, done? | |
665 bra comm_firmware_update_loop ; NO - loop | |
666 tstfsz hi ; YES - check-byte zero? | |
667 bra comm_send_firmware_failed ; NO - checksum not valid | |
668 | |
669 ; checksum is valid | |
670 SERIAL_LC_SEND 0x4C ; inform checksum is ok | |
671 call rs232_wait_tx ; wait for completion of transmit before hardware goes into reboot | |
672 | |
673 call eeprom_deco_data_write ; update deco data in EEPROM | |
674 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | |
675 btfsc options_changed ; do the options need to be stored to EEPROM ? | |
676 call option_check_and_store_all ; YES - check and store all option values in EEPROM | |
677 | |
678 goto 0x1FDF0 ; jump into the bootloader code | |
679 | |
680 comm_send_firmware_failed: | |
681 ; select font and output position | |
682 WIN_SMALL comm_string_column, comm_string_row | |
683 call TFT_warning_color ; select color | |
684 STRCPY_PRINT "Checksum failed" ; print failure message (fill to 15 chars) | |
685 call TFT_standard_color ; back to standard color | |
686 ;bra comm_send_firmware_abort ; abort | |
687 | |
688 comm_send_firmware_abort: | |
689 SERIAL_LC_SEND 0xFF ; send abort message | |
690 bra comm_command_loop ; done, back to command loop | |
691 | |
692 | |
693 ;----------------------------------------------------------------------------- | |
694 ; Erase a Memory Range given byte Start Address and Number of 4 kB Blocks | |
695 ; | |
696 comm_erase_range4kb: | |
697 SERIAL_LC_SEND 0x42 ; acknowledge command | |
698 bcf INTCON,GIE ; disable all interrupts | |
699 rcall comm_get_start_address ; (try to) get the start address | |
700 btfsc rs232_rx_timeout ; got start address? | |
701 bra comm_command_timeout ; NO - abort, back to command loop | |
702 | |
703 ; (try to) receive the block count (1 byte) | |
704 SERIAL_CC_RECEIVE ext_flash_length_counter | |
705 btfsc rs232_rx_timeout ; got block count? | |
706 bra comm_command_timeout ; NO - abort, back to command loop | |
707 | |
708 ; erase blocks (number of blocks to do was received in ext_flash_length_counter:1) | |
709 comm_erase_range4kb_loop: | |
710 call ext_flash_erase_4kB ; erase a 4 kB block | |
711 ; increase start address by 0x1000 (4kB): | |
712 ; nothing to do with low byte | |
713 movlw 0x10 ; add 0x10... | |
714 addwf ext_flash_address+1,F ; ... to high byte | |
715 movlw 0x00 ; add 0x00... | |
716 addwfc ext_flash_address+2,F ; ... plus carry bit to upper byte | |
717 btfsc ext_flash_address+2,6 ; reached 0x400000 ? | |
718 bra comm_command_loop ; YES - at end of address range, back to command loop | |
719 decfsz ext_flash_length_counter,F ; NO - decrement number of blocks to do, all blocks done? | |
720 bra comm_erase_range4kb_loop ; NO - loop | |
721 bra comm_command_loop ; YES - done, back to command loop | |
722 | |
723 | |
724 ;----------------------------------------------------------------------------- | |
725 ; Erase one Memory Block of 4 kB Size | |
726 ; | |
727 comm_erase_4kb: | |
728 ; SERIAL_LC_SEND 0x40 ; acknowledge command (not done) | |
729 bcf INTCON,GIE ; disable all interrupts | |
730 rcall comm_get_start_address ; (try to) get the start address | |
731 btfsc rs232_rx_timeout ; got a complete start address? | |
732 bra comm_command_timeout ; NO - abort, back to command loop | |
733 call ext_flash_erase_4kB ; YES - erase memory block | |
734 bra comm_command_loop ; - done, back to command loop | |
735 | |
736 | |
737 ;----------------------------------------------------------------------------- | |
738 ; Write a stream of bytes to the FLASH beginning at given start address, end on timeout | |
739 ; | |
740 comm_write_range_stream: | |
741 SERIAL_LC_SEND 0x30 ; acknowledge command | |
742 bcf INTCON,GIE ; disable all interrupts | |
743 rcall comm_get_start_address ; (try to) get the start address | |
744 btfsc rs232_rx_timeout ; got a complete start address? | |
745 bra comm_command_timeout ; NO - abort, back to command loop | |
746 | |
747 ; steam bytes to FLASH | |
748 comm_write_range_loop: | |
749 SERIAL_CC_RECEIVE WREG ; (try to) receive a byte | |
750 btfsc rs232_rx_timeout ; got a byte? | |
751 bra comm_command_loop ; NO - end of byte stream, done, back to command loop | |
752 ; bsf NCTS ; YES - hold Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
753 call write_byte_ext_flash_plus_comms ; - write data byte to FLASH and increase address with rollover at 0x400000 | |
754 ; bcf NCTS ; - release Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
755 bra comm_write_range_loop ; - loop | |
756 | |
757 | |
758 ;----------------------------------------------------------------------------- | |
759 ; Write a block of 256 bytes to the FLASH beginning at given start address (low byte needs to be zero) | |
760 ; | |
761 comm_write_range_block: | |
762 SERIAL_LC_SEND 0x31 ; acknowledge command | |
763 bcf INTCON,GIE ; disable all interrupts | |
764 | |
765 rcall comm_get_start_address ; (try to) get the start address | |
766 btfsc rs232_rx_timeout ; got a complete start address? | |
767 bra comm_command_timeout ; NO - abort, back to command loop | |
768 | |
769 tstfsz ext_flash_address+0 ; low byte of address = 0 ? | |
770 bra comm_command_error ; NO - abort, back to command loop | |
771 | |
772 SERIAL_RR_RECEIVE_RAM buffer,.256 ; (try to) receive 256 byte and buffer them in memory | |
773 btfsc rs232_rx_timeout ; got all 256 bytes? | |
774 bra comm_command_timeout ; NO - abort, back to command loop | |
775 | |
776 FLASH_RR_WRITE buffer,ext_flash_address,.256 ; copy from memory to FLASH | |
777 bra comm_command_loop ; done, back to command loop | |
778 | |
779 | |
780 ;----------------------------------------------------------------------------- | |
781 ; Read a range from FLASH given by start address and length | |
782 ; | |
783 comm_read_range: | |
784 SERIAL_LC_SEND 0x20 ; acknowledge command | |
785 bcf INTCON,GIE ; disable all interrupts | |
786 | |
787 ; receive start address | |
788 rcall comm_get_start_address ; (try to) get the start address | |
789 btfsc rs232_rx_timeout ; got a complete start address? | |
790 bra comm_command_timeout ; NO - abort, back to command loop | |
791 | |
792 ; receive length | |
793 rcall comm_get_length ; (try to) get the length | |
794 btfsc rs232_rx_timeout ; got a complete length? | |
795 bra comm_command_timeout ; NO - abort, back to command loop | |
796 | |
797 ; stream bytes from FLASH | |
798 ext_flash_dec_length .1 ; decrement length count by 1 so that all bytes will be | |
799 ; done when the counter has wrapped around to 0xFFFFFF | |
800 | |
801 movlw 0x40 ; now the length count is allowed to be 0x3FFFFF at max | |
802 cpfslt ext_flash_length_counter+2 ; length count < 0x40(0000) ? | |
803 bra comm_command_error ; NO - abort, back to command loop | |
804 call ext_flash_read_block_start ; YES - read first byte from FLASH into WREG | |
805 bra comm_read_range_loop_start ; - jump into transmit loop | |
806 comm_read_range_loop: | |
807 call ext_flash_read_block_0x40 ; read next byte into WREG | |
808 comm_read_range_loop_start: | |
809 SERIAL_CC_SEND WREG ; transmit byte | |
810 ext_flash_dec_length .1 ; decrement length counter | |
811 btfss ext_flash_length_counter+2,7; under-run? | |
812 bra comm_read_range_loop ; NO - continue loop | |
813 call ext_flash_read_block_stop ; YES - end reading from FLASH | |
814 bra comm_command_loop ; - done, back to command loop | |
815 | |
816 | |
817 ;----------------------------------------------------------------------------- | |
818 ; Receive a 3 byte FLASH address (on serial: big-endian, in memory: little-endian) | |
819 ; | |
820 comm_get_start_address: | |
821 SERIAL_RR_RECEIVE_RAM ext_flash_address,.3 ; receive 3 bytes | |
822 btfsc rs232_rx_timeout ; timeout? | |
823 return ; YES - abort, no usable address available | |
824 | |
825 ; remap address from network byte format (big endian) to host format (little-endian) | |
826 movf ext_flash_address+0,W | |
827 movff ext_flash_address+2,ext_flash_address+0 | |
832 movwf ext_flash_address+2 | 828 movwf ext_flash_address+2 |
833 movlw .16 | 829 |
834 mulwf lo ; lo*16 = offset to 0x2000 (up:hi) | 830 return ; done, complete start address available |
835 movf PRODL,W | 831 |
836 addwf ext_flash_address+1,F | 832 |
837 movf PRODH,W | 833 ;----------------------------------------------------------------------------- |
838 addwfc ext_flash_address+2,F | 834 ; Receive a 3 byte length (on serial: big-endian, in memory: little-endian) |
839 | 835 ; |
840 incf_ext_flash_address d'2' ; skip 0xFA, 0xFA | 836 comm_get_length: |
841 call ext_flash_byte_read_plus ; read start address of profile | 837 SERIAL_RR_RECEIVE_RAM ext_flash_length_counter,.3 ; receive 3 bytes |
842 movff ext_flash_rw,ext_flash_log_pointer+0 | 838 btfsc rs232_rx_timeout ; timeout? |
843 call ext_flash_byte_read_plus ; read start address of profile | 839 return ; YES - abort, no usable address available |
844 movff ext_flash_rw,ext_flash_log_pointer+1 | 840 |
845 call ext_flash_byte_read_plus ; read start address of profile | 841 ; remap address from network byte format (big endian) to host format (little-endian) |
846 movff ext_flash_rw,ext_flash_log_pointer+2 | 842 movf ext_flash_length_counter+0,W |
847 call ext_flash_byte_read_plus ; read end address of profile | 843 movff ext_flash_length_counter+2,ext_flash_length_counter+0 |
848 movff ext_flash_rw,ext_flash_end_pointer+0 | 844 movwf ext_flash_length_counter+2 |
849 call ext_flash_byte_read_plus ; read end address of profile | 845 |
850 movff ext_flash_rw,ext_flash_end_pointer+1 | 846 return ; done, complete start address available |
851 call ext_flash_byte_read_plus ; read end address of profile | 847 |
852 movff ext_flash_rw,ext_flash_end_pointer+2 | 848 |
853 decf_ext_flash_address d'8' ; back again to first 0xFA in header | 849 ;----------------------------------------------------------------------------- |
854 | 850 ; Read an Option Value |
855 movf ext_flash_log_pointer+0,W | 851 ; |
856 cpfseq ext_flash_end_pointer+0 ; equal? | 852 comm_read_option: |
857 bra comm_send_dive1 ; NO - send header | 853 SERIAL_LC_SEND 0x72 ; acknowledge command |
858 | 854 SERIAL_CC_RECEIVE lo ; (try to) receive option index |
859 movf ext_flash_log_pointer+1,W | 855 btfsc rs232_rx_timeout ; received option index? |
860 cpfseq ext_flash_end_pointer+1 ; equal? | 856 bra comm_command_loop ; NO - abort, back to command loop |
861 bra comm_send_dive1 ; NO - send header | 857 |
862 | 858 ; option index 0x00 - 0x0F: unused |
863 movf ext_flash_log_pointer+2,W | 859 movlw 0x0F ; last option index of the unused range |
864 cpfseq ext_flash_end_pointer+2 ; equal? | 860 cpfsgt lo ; received option index > end of unused range ? |
865 bra comm_send_dive1 ; NO - send header | 861 bra comm_command_error ; NO - abort, back to command loop |
866 | 862 |
867 ; Start=End -> Not good, abort | 863 ; option index 0x10 - 0x19: gases & diluents |
868 bra comm_download_mode0 ; done, loop with timeout reset | 864 movlw 0x19 ; last option index for gases / diluents |
869 | 865 cpfsgt lo ; received option index > end of gas/dil range ? |
870 comm_send_dive1: | 866 bra comm_read_gas_dil ; NO - process gas/dil read |
871 ; Send header | 867 |
872 clrf hi ; counter | 868 ; option index 0x1A - 0x1E: setpoints |
873 rcall comm_write_byte ; wait for completion of transmit | 869 movlw 0x1E ; last option index for setpoint |
874 call ext_flash_read_block_start ; 1st byte | 870 cpfsgt lo ; received option index > end of setpoint range ? |
875 movwf TXREG1 | 871 bra comm_read_sp ; NO - process setpoint read |
876 bra comm_send_dive_header | 872 |
877 comm_send_dive_header2: | 873 ; option index = 0x49 - special handling button polarity |
878 call ext_flash_read_block ; read one byte | 874 movf lo,W ; copy option index to WREG |
879 movwf TXREG1 ; start new transmit | 875 iorlw 0x49 ; received option index for button polarity ? |
880 comm_send_dive_header: | 876 bz comm_read_button_polarity ; YES - process button polarity read |
881 rcall comm_write_byte ; wait for completion of transmit | 877 |
882 decfsz hi,F | 878 ; option index 0x1F - 0xFF: options managed by option-table |
883 bra comm_send_dive_header2 | 879 call option_read_serial ; try to find the option and read its value |
884 call ext_flash_read_block_stop | 880 tstfsz WREG ; option found? |
885 | 881 bra comm_read_setting_fail ; NO - send dummy value |
886 ; Set address for profile | 882 SERIAL_CC_SEND hi ; YES - send read value |
887 movff ext_flash_log_pointer+0,ext_flash_address+0 | 883 bra comm_command_loop ; - done, back to command loop |
888 movff ext_flash_log_pointer+1,ext_flash_address+1 | 884 |
889 movff ext_flash_log_pointer+2,ext_flash_address+2 | 885 comm_read_setting_fail: |
890 | 886 SERIAL_LC_SEND 0x00 ; send a dummy value |
891 movlw .6 ; skip 6 byte short header in profile - only for internal use | 887 bra comm_command_error ; back to command loop with failure message |
892 call incf_ext_flash_address0_0x20 ; increases bytes in ext_flash_address:3 with 0x200000 bank switching | 888 |
893 | 889 |
894 ; Set address for short header/compact header, Byte 0 | 890 ;----------------------------------------------------------------------------- |
895 | 891 ; Write an Option Value |
896 comm_send_dive_profile: | 892 ; |
897 call ext_flash_byte_read_plus_0x20 ; read one byte into ext_flash_rw, takes care of banking at 0x200000 | 893 comm_write_option: |
898 rcall comm_write_byte ; wait for completion of transmit | 894 SERIAL_LC_SEND 0x77 ; acknowledge command |
899 movff ext_flash_rw,TXREG1 ; send a byte | 895 SERIAL_CC_RECEIVE lo ; (try to) receive option index |
900 | 896 btfsc rs232_rx_timeout ; got a byte? |
901 ; 24bit compare with end address | 897 bra comm_command_timeout ; NO - abort, back to command loop |
902 movff ext_flash_end_pointer+0,WREG | 898 |
903 cpfseq ext_flash_address+0 | 899 ; option index 0x00 - 0x0F: unused |
904 bra comm_send_dive_profile | 900 movlw 0x0F ; last option index of the unused range |
905 movff ext_flash_end_pointer+1,WREG | 901 cpfsgt lo ; received option index > end of unused range ? |
906 cpfseq ext_flash_address+1 | 902 bra comm_write_unused ; NO - but need to consume the option value |
907 bra comm_send_dive_profile | 903 |
908 movff ext_flash_end_pointer+2,WREG | 904 ; option index 0x10 - 0x19: gases & diluents |
909 cpfseq ext_flash_address+2 | 905 movlw 0x19 ; last option index for gases / diluents |
910 bra comm_send_dive_profile | 906 cpfsgt lo ; received option index > end of gas/dil range ? |
911 | 907 bra comm_write_gas_dil ; NO - process gas/dil write |
912 rcall comm_write_byte ; wait for completion of transmit | 908 |
913 bra comm_download_mode0 ; done, loop with timeout reset | 909 ; option index 0x1A - 0x1E: setpoints |
914 | 910 movlw 0x1E ; last option index for setpoint |
915 ;----------------------------------------------------------------------------- | 911 cpfsgt lo ; received option index > end of setpoint range ? |
916 | 912 bra comm_write_sp ; NO - process setpoint write |
917 comm_read_setting: | 913 |
918 movlw "r" | 914 ; option index = 0x49 - special handling button polarity |
919 movwf TXREG1 | 915 movf lo,W ; copy option index to WREG |
920 rcall comm_get_byte | 916 iorlw 0x49 ; received option index for button polarity ? |
921 btfsc rs232_rx_timeout ; got byte? | 917 bz comm_write_button_polarity ; YES - process button polarity write |
922 bra comm_read_abort ; NO - abort | 918 |
923 rcall comm_write_byte ; wait for completion of transmit | 919 ; option index 0x1F - 0xFF: options managed by option-table |
924 movlw 0x0F | 920 SERIAL_CC_RECEIVE hi ; (try to) receive option value |
925 cpfsgt RCREG1 ; 0x00-0x0F: unused | 921 btfsc rs232_rx_timeout ; got a byte? |
926 bra comm_read_abort ; abort! | 922 bra comm_command_timeout ; NO - abort |
927 subwf RCREG1,W ; subtract unused commands | 923 call option_write_serial ; YES - try to find the option and write new value |
928 | 924 tstfsz WREG ; - option found and new value valid ? |
929 clrf up ; set gas/dil index to 0 (0 = gas 1) | 925 bra comm_command_error ; NO - back to command loop with failure message |
930 dcfsnz WREG | 926 bra comm_command_loop ; YES - done, back to command loop |
931 bra comm_read_gas_dil ; RCREG1=0x10 | 927 |
932 incf up ; increment gas/dil index (1 = gas 2) | 928 comm_write_unused: |
933 dcfsnz WREG | 929 SERIAL_CC_RECEIVE WREG ; consume unused option value |
934 bra comm_read_gas_dil ; RCREG1=0x11 | 930 bra comm_command_error ; done, back to command loop |
935 incf up ; increment gas/dil index (2 = gas 3) | 931 |
936 dcfsnz WREG | 932 |
937 bra comm_read_gas_dil ; RCREG1=0x12 | 933 ;----------------------------------------------------------------------------- |
938 incf up ; increment gas/dil index (3 = gas 4) | 934 ; Read button polarity |
939 dcfsnz WREG | 935 ; |
940 bra comm_read_gas_dil ; RCREG1=0x13 | 936 comm_read_button_polarity: |
941 incf up ; increment gas/dil index (4 = gas 5) | 937 SERIAL_CC_SEND button_polarity ; send current button polarity setting |
942 dcfsnz WREG | 938 bra comm_command_loop ; done, back to command loop |
943 bra comm_read_gas_dil ; RCREG1=0x14 | 939 |
944 incf up ; increment gas/dil index (5 = dil 1) | 940 |
945 dcfsnz WREG | 941 ;----------------------------------------------------------------------------- |
946 bra comm_read_gas_dil ; RCREG1=0x15 | 942 ; Write button polarity |
947 incf up ; increment gas/dil index (6 = dil 2) | 943 ; |
948 dcfsnz WREG | 944 comm_write_button_polarity: |
949 bra comm_read_gas_dil ; RCREG1=0x16 | 945 SERIAL_CC_RECEIVE hi ; (try to) receive configuration value |
950 incf up ; increment gas/dil index (7 = dil 3) | 946 btfsc rs232_rx_timeout ; got configuration value? |
951 dcfsnz WREG | 947 bra comm_command_timeout ; NO - abort, back to command loop |
952 bra comm_read_gas_dil ; RCREG1=0x17 | 948 movff hi,button_polarity ; YES - store button polarity in memory and EEPROM |
953 incf up ; increment gas/dil index (8 = dil 4) | 949 EEPROM_CC_WRITE button_polarity,eeprom_button_polarity |
954 dcfsnz WREG | 950 bra comm_command_loop ; - done, back to command loop |
955 bra comm_read_gas_dil ; RCREG1=0x18 | 951 |
956 incf up ; increment gas/dil index (9 = dil 5) | 952 |
957 dcfsnz WREG | 953 ;----------------------------------------------------------------------------- |
958 bra comm_read_gas_dil ; RCREG1=0x19 | 954 ; Read a gas/diluent dataset |
959 | 955 ; |
960 clrf up ; set setpoint index to 0 (0 = SP 1) | |
961 dcfsnz WREG | |
962 bra comm_read_sp ; RCREG1=0x1A | |
963 incf up ; increment setpoint index (1 = SP2) | |
964 dcfsnz WREG | |
965 bra comm_read_sp ; RCREG1=0x1B | |
966 incf up ; increment setpoint index (2 = SP3) | |
967 dcfsnz WREG | |
968 bra comm_read_sp ; RCREG1=0x1C | |
969 incf up ; increment setpoint index (3 = SP4) | |
970 dcfsnz WREG | |
971 bra comm_read_sp ; RCREG1=0x1D | |
972 incf up ; increment setpoint index (4 = SP5) | |
973 dcfsnz WREG | |
974 bra comm_read_sp ; RCREG1=0x1E | |
975 | |
976 dcfsnz WREG | |
977 movff opt_ccr_mode, TXREG1 ; RCREG1=0x1F | |
978 dcfsnz WREG | |
979 movff opt_dive_mode, TXREG1 ; RCREG1=0x20 | |
980 dcfsnz WREG | |
981 movff char_I_deco_model, TXREG1 ; RCREG1=0x21 | |
982 dcfsnz WREG | |
983 movff char_I_ppO2_max_work, TXREG1 ; RCREG1=0x22 | |
984 dcfsnz WREG | |
985 movff char_I_ppO2_min, TXREG1 ; RCREG1=0x23 | |
986 dcfsnz WREG | |
987 movff char_I_extra_time, TXREG1 ; RCREG1=0x24 | |
988 dcfsnz WREG | |
989 movff opt_GF_low, TXREG1 ; RCREG1=0x25 | |
990 dcfsnz WREG | |
991 movff opt_GF_high, TXREG1 ; RCREG1=0x26 | |
992 dcfsnz WREG | |
993 movff opt_aGF_low, TXREG1 ; RCREG1=0x27 | |
994 dcfsnz WREG | |
995 movff opt_aGF_high, TXREG1 ; RCREG1=0x28 | |
996 dcfsnz WREG | |
997 movff opt_enable_aGF, TXREG1 ; RCREG1=0x29 | |
998 dcfsnz WREG | |
999 movff opt_sat_multiplier_non_gf, TXREG1 ; RCREG1=0x2A | |
1000 dcfsnz WREG | |
1001 movff opt_desat_multiplier_non_gf,TXREG1 ; RCREG1=0x2B | |
1002 dcfsnz WREG | |
1003 movff opt_last_stop, TXREG1 ; RCREG1=0x2C | |
1004 dcfsnz WREG | |
1005 movff opt_brightness, TXREG1 ; RCREG1=0x2D | |
1006 dcfsnz WREG | |
1007 movff opt_units, TXREG1 ; RCREG1=0x2E | |
1008 dcfsnz WREG | |
1009 movff opt_sampling_rate, TXREG1 ; RCREG1=0x2F | |
1010 dcfsnz WREG | |
1011 movff opt_salinity, TXREG1 ; RCREG1=0x30 | |
1012 dcfsnz WREG | |
1013 movff opt_dive_color_scheme, TXREG1 ; RCREG1=0x31 | |
1014 dcfsnz WREG | |
1015 movff opt_language, TXREG1 ; RCREG1=0x32 | |
1016 dcfsnz WREG | |
1017 movff opt_dateformat, TXREG1 ; RCREG1=0x33 | |
1018 dcfsnz WREG | |
1019 movff opt_compass_gain, TXREG1 ; RCREG1=0x34 | |
1020 dcfsnz WREG | |
1021 movff opt_pressure_adjust, TXREG1 ; RCREG1=0x35 | |
1022 dcfsnz WREG | |
1023 movff opt_enable_safetystop, TXREG1 ; RCREG1=0x36 | |
1024 dcfsnz WREG | |
1025 movff opt_calibration_O2_ratio, TXREG1 ; RCREG1=0x37 | |
1026 dcfsnz WREG | |
1027 clrf TXREG1 ; RCREG1=0x38 NOT USED ANYMORE (ex opt_sensor_fallback) | |
1028 dcfsnz WREG | |
1029 movff opt_flip_screen, TXREG1 ; RCREG1=0x39 | |
1030 dcfsnz WREG | |
1031 movff opt_cR_button_left, TXREG1 ; RCREG1=0x3A | |
1032 dcfsnz WREG | |
1033 movff opt_cR_button_right, TXREG1 ; RCREG1=0x3B | |
1034 dcfsnz WREG | |
1035 movff char_I_SAC_work, TXREG1 ; RCREG1=0x3C | |
1036 dcfsnz WREG | |
1037 movff char_I_SAC_deco, TXREG1 ; RCREG1=0x3D | |
1038 dcfsnz WREG | |
1039 movff opt_modwarning, TXREG1 ; RCREG1=0x3E | |
1040 dcfsnz WREG | |
1041 movff opt_vsitextv2, TXREG1 ; RCREG1=0x3F | |
1042 dcfsnz WREG | |
1043 movff opt_vsigraph, TXREG1 ; RCREG1=0x40 | |
1044 dcfsnz WREG | |
1045 movff opt_showppo2, TXREG1 ; RCREG1=0x41, always show ppO2 | |
1046 dcfsnz WREG | |
1047 movff opt_temperature_adjust, TXREG1 ; RCREG1=0x42 | |
1048 dcfsnz WREG | |
1049 movff opt_safety_stop_length, TXREG1 ; RCREG1=0x43 | |
1050 dcfsnz WREG | |
1051 movff opt_safety_stop_start, TXREG1 ; RCREG1=0x44 | |
1052 dcfsnz WREG | |
1053 movff opt_safety_stop_end, TXREG1 ; RCREG1=0x45 | |
1054 dcfsnz WREG | |
1055 movff opt_safety_stop_reset, TXREG1 ; RCREG1=0x46 | |
1056 dcfsnz WREG | |
1057 clrf TXREG1 ; RCREG1=0x47, ignore conservatism in hwOS tech firmware | |
1058 dcfsnz WREG | |
1059 movff opt_diveTimeout, TXREG1 ; RCREG1=0x48 | |
1060 dcfsnz WREG | |
1061 movff button_polarity, TXREG1 ; RCREG1=0x49 | |
1062 dcfsnz WREG | |
1063 movff char_I_PSCR_drop, TXREG1 ; RCREG1=0x4A | |
1064 dcfsnz WREG | |
1065 movff char_I_PSCR_lungratio, TXREG1 ; RCREG1=0x4B | |
1066 dcfsnz WREG | |
1067 movff char_I_ppO2_max_deco, TXREG1 ; RCREG1=0x4C | |
1068 dcfsnz WREG | |
1069 movff char_I_ppO2_min_loop, TXREG1 ; RCREG1=0x4D | |
1070 dcfsnz WREG | |
1071 movff char_I_gas_avail_size+0, TXREG1 ; RCREG1=0x4E | |
1072 dcfsnz WREG | |
1073 movff char_I_gas_avail_size+1, TXREG1 ; RCREG1=0x4F | |
1074 dcfsnz WREG | |
1075 movff char_I_gas_avail_size+2, TXREG1 ; RCREG1=0x50 | |
1076 dcfsnz WREG | |
1077 movff char_I_gas_avail_size+3, TXREG1 ; RCREG1=0x51 | |
1078 dcfsnz WREG | |
1079 movff char_I_gas_avail_size+4, TXREG1 ; RCREG1=0x52 | |
1080 dcfsnz WREG | |
1081 movff char_I_gas_avail_pres+0, TXREG1 ; RCREG1=0x53 | |
1082 dcfsnz WREG | |
1083 movff char_I_gas_avail_pres+1, TXREG1 ; RCREG1=0x54 | |
1084 dcfsnz WREG | |
1085 movff char_I_gas_avail_pres+2, TXREG1 ; RCREG1=0x55 | |
1086 dcfsnz WREG | |
1087 movff char_I_gas_avail_pres+3, TXREG1 ; RCREG1=0x56 | |
1088 dcfsnz WREG | |
1089 movff char_I_gas_avail_pres+4, TXREG1 ; RCREG1=0x57 | |
1090 dcfsnz WREG | |
1091 movff char_I_CC_max_frac_O2, TXREG1 ; RCREG1=0x58 | |
1092 dcfsnz WREG | |
1093 movff opt_sim_setpoint_number, TXREG1 ; RCREG1=0x59 | |
1094 dcfsnz WREG | |
1095 movff opt_calc_asc_gasvolume, TXREG1 ; RCREG1=0x5A | |
1096 dcfsnz WREG | |
1097 movff opt_sim_use_aGF, TXREG1 ; RCREG1=0x5B | |
1098 dcfsnz WREG | |
1099 movff char_I_altitude_wait, TXREG1 ; RCREG1=0x5C | |
1100 dcfsnz WREG | |
1101 movff opt_enable_IBCD, TXREG1 ; RCREG1=0x5D | |
1102 dcfsnz WREG | |
1103 movff opt_sat_multiplier_gf, TXREG1 ; RCREG1=0x5E | |
1104 dcfsnz WREG | |
1105 movff opt_desat_multiplier_gf, TXREG1 ; RCREG1=0x5F | |
1106 dcfsnz WREG | |
1107 movff opt_transmitter_id_1+0, TXREG1 ; RCREG1=0x60 | |
1108 dcfsnz WREG | |
1109 movff opt_transmitter_id_1+1, TXREG1 ; RCREG1=0x61 | |
1110 dcfsnz WREG | |
1111 movff opt_transmitter_id_2+0, TXREG1 ; RCREG1=0x62 | |
1112 dcfsnz WREG | |
1113 movff opt_transmitter_id_2+1, TXREG1 ; RCREG1=0x63 | |
1114 dcfsnz WREG | |
1115 movff opt_transmitter_id_3+0, TXREG1 ; RCREG1=0x64 | |
1116 dcfsnz WREG | |
1117 movff opt_transmitter_id_3+1, TXREG1 ; RCREG1=0x65 | |
1118 dcfsnz WREG | |
1119 movff opt_transmitter_id_4+0, TXREG1 ; RCREG1=0x66 | |
1120 dcfsnz WREG | |
1121 movff opt_transmitter_id_4+1, TXREG1 ; RCREG1=0x67 | |
1122 dcfsnz WREG | |
1123 movff opt_transmitter_id_5+0, TXREG1 ; RCREG1=0x68 | |
1124 dcfsnz WREG | |
1125 movff opt_transmitter_id_5+1, TXREG1 ; RCREG1=0x69 | |
1126 dcfsnz WREG | |
1127 movff opt_transmitter_id_6+0, TXREG1 ; RCREG1=0x6A | |
1128 dcfsnz WREG | |
1129 movff opt_transmitter_id_6+1, TXREG1 ; RCREG1=0x6B | |
1130 dcfsnz WREG | |
1131 movff opt_transmitter_id_7+0, TXREG1 ; RCREG1=0x6C | |
1132 dcfsnz WREG | |
1133 movff opt_transmitter_id_7+1, TXREG1 ; RCREG1=0x6D | |
1134 dcfsnz WREG | |
1135 movff opt_transmitter_id_8+0, TXREG1 ; RCREG1=0x6E | |
1136 dcfsnz WREG | |
1137 movff opt_transmitter_id_8+1, TXREG1 ; RCREG1=0x6F | |
1138 dcfsnz WREG | |
1139 movff opt_transmitter_id_9+0, TXREG1 ; RCREG1=0x70 | |
1140 dcfsnz WREG | |
1141 movff opt_transmitter_id_9+1, TXREG1 ; RCREG1=0x71 | |
1142 dcfsnz WREG | |
1143 movff opt_transmitter_id_10+0, TXREG1 ; RCREG1=0x72 | |
1144 dcfsnz WREG | |
1145 movff opt_transmitter_id_10+1, TXREG1 ; RCREG1=0x73 | |
1146 dcfsnz WREG | |
1147 movff char_I_gas_avail_size+5, TXREG1 ; RCREG1=0x74 | |
1148 dcfsnz WREG | |
1149 movff char_I_gas_avail_size+6, TXREG1 ; RCREG1=0x75 | |
1150 dcfsnz WREG | |
1151 movff char_I_gas_avail_size+7, TXREG1 ; RCREG1=0x76 | |
1152 dcfsnz WREG | |
1153 movff char_I_gas_avail_size+8, TXREG1 ; RCREG1=0x77 | |
1154 dcfsnz WREG | |
1155 movff char_I_gas_avail_size+9, TXREG1 ; RCREG1=0x78 | |
1156 dcfsnz WREG | |
1157 movff char_I_gas_avail_pres+5, TXREG1 ; RCREG1=0x79 | |
1158 dcfsnz WREG | |
1159 movff char_I_gas_avail_pres+6, TXREG1 ; RCREG1=0x7A | |
1160 dcfsnz WREG | |
1161 movff char_I_gas_avail_pres+7, TXREG1 ; RCREG1=0x7B | |
1162 dcfsnz WREG | |
1163 movff char_I_gas_avail_pres+8, TXREG1 ; RCREG1=0x7C | |
1164 dcfsnz WREG | |
1165 movff char_I_gas_avail_pres+9, TXREG1 ; RCREG1=0x7D | |
1166 dcfsnz WREG | |
1167 movff opt_TR_mode, TXREG1 ; RCREG1=0x7E | |
1168 dcfsnz WREG | |
1169 movff opt_TR_1st_pres, TXREG1 ; RCREG1=0x7F | |
1170 dcfsnz WREG | |
1171 movff opt_TR_2nd_pres, TXREG1 ; RCREG1=0x80 | |
1172 dcfsnz WREG | |
1173 movff opt_TR_Bail_pres, TXREG1 ; RCREG1=0x81 | |
1174 dcfsnz WREG | |
1175 movff char_I_max_pres_diff, TXREG1 ; RCREG1=0x82 | |
1176 dcfsnz WREG | |
1177 movff opt_ZfactorUse, TXREG1 ; RCREG1=0x83 | |
1178 dcfsnz WREG | |
1179 movff opt_ZfactorTemp, TXREG1 ; RCREG1=0x84 | |
1180 dcfsnz WREG | |
1181 movff opt_2ndDepthDisp, TXREG1 ; RCREG1=0x85 | |
1182 dcfsnz WREG | |
1183 movff opt_max_depth, TXREG1 ; RCREG1=0x86 | |
1184 dcfsnz WREG | |
1185 movff char_I_descent_speed, TXREG1 ; RCREG1=0x87 | |
1186 dcfsnz WREG | |
1187 movff opt_store_apnoe_dive, TXREG1 ; RCREG1=0x88 | |
1188 dcfsnz WREG | |
1189 movff opt_tissue_graphics, TXREG1 ; RCREG1=0x89 | |
1190 dcfsnz WREG | |
1191 movff opt_layout, TXREG1 ; RCREG1=0x8A | |
1192 dcfsnz WREG | |
1193 movff opt_extended_stops, TXREG1 ; RCREG1=0x8B | |
1194 dcfsnz WREG | |
1195 movff char_I_gas_density_att, TXREG1 ; RCREG1=0x8C | |
1196 dcfsnz WREG | |
1197 movff char_I_gas_density_warn, TXREG1 ; RCREG1=0x8D | |
1198 dcfsnz WREG | |
1199 movff char_I_dil_ppO2_check, TXREG1 ; RCREG1=0x8E | |
1200 | |
1201 comm_read_abort: | |
1202 comm_read_done: | |
1203 bra comm_download_mode0 ; done, loop with timeout reset | |
1204 | |
1205 ;----------------------------------------------------------------------------- | |
1206 | |
1207 ; Memory map is as follows: | 956 ; Memory map is as follows: |
1208 ; ------------------------- | 957 ; ------------------------- |
1209 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | 958 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases |
1210 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | 959 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents |
1211 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | 960 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases |
1212 ; opt_dil_He_ratio res 5 ; He ratios of diluents | 961 ; opt_dil_He_ratio res 5 ; He ratios of diluents |
1213 ; opt_gas_type res 5 ; OC/bailout gas type | 962 ; opt_gas_type res 5 ; OC/bailout gas type |
1214 ; opt_dil_type res 5 ; dil type | 963 ; opt_dil_type res 5 ; dil type |
1215 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | 964 ; opt_gas_change res 5 ; change depths for OC/Bailout gases |
1216 ; opt_dil_change res 5 ; change depths for diluents | 965 ; opt_dil_change res 5 ; change depths for diluents |
1217 | 966 ; |
1218 comm_read_gas_dil: | 967 comm_read_gas_dil: |
1219 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays | 968 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays |
1220 movf up,W ; load index (0-9) of gas/dil into WREG, addressing O2 ratio | 969 movlw 0x10 ; compute gas index from option index... |
1221 movff PLUSW0, TXREG1 ; transmit O2 ratio | 970 subwf lo,W ; ...making WREG point to O2 ratio |
1222 rcall comm_write_byte ; wait for completion of transmit | 971 SERIAL_CC_SEND PLUSW0 ; send O2 ratio |
1223 addlw .10 ; increment index by 10, addressing He ratio now | 972 addlw .10 ; increment WREG by 10 to point to He ratio |
1224 movff PLUSW0, TXREG1 ; transmit He ratio | 973 SERIAL_CC_SEND PLUSW0 ; send He ratio |
1225 rcall comm_write_byte ; wait for completion of transmit | 974 addlw .10 ; increment WREG by 10 to point to gas/diluent type |
1226 addlw .10 ; increment index by 10, addressing gas/dil type now | 975 SERIAL_CC_SEND PLUSW0 ; send gas/diluent type |
1227 movff PLUSW0, TXREG1 ; transmit gas/dil type | 976 addlw .10 ; increment WREG by 10 to point to change depth |
1228 rcall comm_write_byte ; wait for completion of transmit | 977 SERIAL_CC_SEND PLUSW0 ; send change depth |
1229 addlw .10 ; increment index by 10, addressing change depth now | 978 bra comm_command_loop ; done, back to command loop |
1230 movff PLUSW0,TXREG1 ; transmit change depth | 979 |
1231 bra comm_read_done ; done, wait for UART and loop with timeout reset | 980 |
1232 | 981 ; ---------------------------------------------------------------------------- |
1233 | 982 ; Write a gas/diluent dataset |
1234 ; Memory map is as follows: | 983 ; |
1235 ; ------------------------- | |
1236 ; opt_setpoint_cbar res 5 ; setpoints in cbar | |
1237 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter | |
1238 | |
1239 comm_read_sp: | |
1240 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values | |
1241 movf up,W ; load index (0-4) of setpoint into WREG, addressing cbar value | |
1242 movff PLUSW0, TXREG1 ; transmit setpoint cbar value | |
1243 rcall comm_write_byte ; wait for completion of transmit | |
1244 addlw .5 ; increment index by 5, addressing change depth now | |
1245 movff PLUSW0, TXREG1 ; transmit change depth | |
1246 bra comm_read_done ; done, wait for UART and loop with timeout reset | |
1247 | |
1248 ;----------------------------------------------------------------------------- | |
1249 | |
1250 comm_write_setting: | |
1251 movlw "w" | |
1252 movwf TXREG1 | |
1253 rcall comm_get_byte ; "Byte 2" | |
1254 btfsc rs232_rx_timeout ; got a byte? | |
1255 bra comm_write_abort ; NO - abort | |
1256 movff RCREG1,lo ; copy | |
1257 rcall comm_get_byte ; "Byte 3" | |
1258 rcall comm_write_byte ; wait for completion of transmit | |
1259 movlw 0x0F | |
1260 cpfsgt lo ; 0x00-0x0F: unused | |
1261 bra comm_write_abort ; abort! | |
1262 subwf lo,W ; subtract unused commands | |
1263 | |
1264 clrf up ; set gas/dil index to 0 (0 = gas 1) | |
1265 dcfsnz WREG | |
1266 bra comm_write_gas_dil ; RCREG1=0x10 | |
1267 incf up ; increment gas/dil index (1 = gas 2) | |
1268 dcfsnz WREG | |
1269 bra comm_write_gas_dil ; RCREG1=0x11 | |
1270 incf up ; increment gas/dil index (2 = gas 3) | |
1271 dcfsnz WREG | |
1272 bra comm_write_gas_dil ; RCREG1=0x12 | |
1273 incf up ; increment gas/dil index (3 = gas 4) | |
1274 dcfsnz WREG | |
1275 bra comm_write_gas_dil ; RCREG1=0x13 | |
1276 incf up ; increment gas/dil index (4 = gas 5) | |
1277 dcfsnz WREG | |
1278 bra comm_write_gas_dil ; RCREG1=0x14 | |
1279 incf up ; increment gas/dil index (5 = dil 1) | |
1280 dcfsnz WREG | |
1281 bra comm_write_gas_dil ; RCREG1=0x15 | |
1282 incf up ; increment gas/dil index (6 = dil 2) | |
1283 dcfsnz WREG | |
1284 bra comm_write_gas_dil ; RCREG1=0x16 | |
1285 incf up ; increment gas/dil index (7 = dil 3) | |
1286 dcfsnz WREG | |
1287 bra comm_write_gas_dil ; RCREG1=0x17 | |
1288 incf up ; increment gas/dil index (8 = dil 4) | |
1289 dcfsnz WREG | |
1290 bra comm_write_gas_dil ; RCREG1=0x18 | |
1291 incf up ; increment gas/dil index (9 = dil 5) | |
1292 dcfsnz WREG | |
1293 bra comm_write_gas_dil ; RCREG1=0x19 | |
1294 | |
1295 clrf up ; set setpoint index to 0 (0 = SP 1) | |
1296 dcfsnz WREG | |
1297 bra comm_write_sp ; RCREG1=0x1A | |
1298 incf up ; increment setpoint index (1 = SP2) | |
1299 dcfsnz WREG | |
1300 bra comm_write_sp ; RCREG1=0x1B | |
1301 incf up ; increment setpoint index (2 = SP3) | |
1302 dcfsnz WREG | |
1303 bra comm_write_sp ; RCREG1=0x1C | |
1304 incf up ; increment setpoint index (3 = SP4) | |
1305 dcfsnz WREG | |
1306 bra comm_write_sp ; RCREG1=0x1D | |
1307 incf up ; increment setpoint index (4 = SP5) | |
1308 dcfsnz WREG | |
1309 bra comm_write_sp ; RCREG1=0x1E | |
1310 | |
1311 dcfsnz WREG | |
1312 movff RCREG1, opt_ccr_mode ; RCREG1=0x1F | |
1313 dcfsnz WREG | |
1314 movff RCREG1, opt_dive_mode ; RCREG1=0x20 | |
1315 dcfsnz WREG | |
1316 movff RCREG1, char_I_deco_model ; RCREG1=0x21 | |
1317 dcfsnz WREG | |
1318 movff RCREG1, char_I_ppO2_max_work ; RCREG1=0x22 | |
1319 dcfsnz WREG | |
1320 movff RCREG1, char_I_ppO2_min ; RCREG1=0x23 | |
1321 dcfsnz WREG | |
1322 movff RCREG1, char_I_extra_time ; RCREG1=0x24 | |
1323 dcfsnz WREG | |
1324 movff RCREG1, opt_GF_low ; RCREG1=0x25 | |
1325 dcfsnz WREG | |
1326 movff RCREG1, opt_GF_high ; RCREG1=0x26 | |
1327 dcfsnz WREG | |
1328 movff RCREG1, opt_aGF_low ; RCREG1=0x27 | |
1329 dcfsnz WREG | |
1330 movff RCREG1, opt_aGF_high ; RCREG1=0x28 | |
1331 dcfsnz WREG | |
1332 movff RCREG1, opt_enable_aGF ; RCREG1=0x29 | |
1333 dcfsnz WREG | |
1334 movff RCREG1, opt_sat_multiplier_non_gf ; RCREG1=0x2A | |
1335 dcfsnz WREG | |
1336 movff RCREG1, opt_desat_multiplier_non_gf ; RCREG1=0x2B | |
1337 dcfsnz WREG | |
1338 movff RCREG1, opt_last_stop ; RCREG1=0x2C | |
1339 dcfsnz WREG | |
1340 movff RCREG1, opt_brightness ; RCREG1=0x2D | |
1341 dcfsnz WREG | |
1342 movff RCREG1, opt_units ; RCREG1=0x2E | |
1343 dcfsnz WREG | |
1344 movff RCREG1, opt_sampling_rate ; RCREG1=0x2F | |
1345 dcfsnz WREG | |
1346 movff RCREG1, opt_salinity ; RCREG1=0x30 | |
1347 dcfsnz WREG | |
1348 movff RCREG1, opt_dive_color_scheme ; RCREG1=0x31 | |
1349 dcfsnz WREG | |
1350 movff RCREG1, opt_language ; RCREG1=0x32 | |
1351 dcfsnz WREG | |
1352 movff RCREG1, opt_dateformat ; RCREG1=0x33 | |
1353 dcfsnz WREG | |
1354 movff RCREG1, opt_compass_gain ; RCREG1=0x34 | |
1355 dcfsnz WREG | |
1356 movff RCREG1, opt_pressure_adjust ; RCREG1=0x35 | |
1357 dcfsnz WREG | |
1358 movff RCREG1, opt_enable_safetystop ; RCREG1=0x36 | |
1359 dcfsnz WREG | |
1360 movff RCREG1, opt_calibration_O2_ratio; RCREG1=0x37 | |
1361 dcfsnz WREG | |
1362 nop ; RCREG1=0x38 NOT USED ANYMORE (ex opt_sensor_fallback) | |
1363 dcfsnz WREG | |
1364 movff RCREG1, opt_flip_screen ; RCREG1=0x39 | |
1365 dcfsnz WREG | |
1366 movff RCREG1, opt_cR_button_left ; RCREG1=0x3A | |
1367 dcfsnz WREG | |
1368 movff RCREG1, opt_cR_button_right ; RCREG1=0x3B | |
1369 dcfsnz WREG | |
1370 movff RCREG1, char_I_SAC_work ; RCREG1=0x3C | |
1371 dcfsnz WREG | |
1372 movff RCREG1, char_I_SAC_deco ; RCREG1=0x3D | |
1373 dcfsnz WREG | |
1374 movff RCREG1, opt_modwarning ; RCREG1=0x3E | |
1375 dcfsnz WREG | |
1376 movff RCREG1, opt_vsitextv2 ; RCREG1=0x3F | |
1377 dcfsnz WREG | |
1378 movff RCREG1, opt_vsigraph ; RCREG1=0x40 | |
1379 dcfsnz WREG | |
1380 movff RCREG1, opt_showppo2 ; RCREG1=0x41, always show ppO2 | |
1381 dcfsnz WREG | |
1382 movff RCREG1, opt_temperature_adjust ; RCREG1=0x42 | |
1383 dcfsnz WREG | |
1384 movff RCREG1, opt_safety_stop_length ; RCREG1=0x43 | |
1385 dcfsnz WREG | |
1386 movff RCREG1, opt_safety_stop_start ; RCREG1=0x44 | |
1387 dcfsnz WREG | |
1388 movff RCREG1, opt_safety_stop_end ; RCREG1=0x45 | |
1389 dcfsnz WREG | |
1390 movff RCREG1, opt_safety_stop_reset ; RCREG1=0x46 | |
1391 dcfsnz WREG | |
1392 nop ; RCREG1=0x47, ignore conservatism for standard hwOS | |
1393 dcfsnz WREG | |
1394 movff RCREG1, opt_diveTimeout ; RCREG1=0x48 | |
1395 dcfsnz WREG | |
1396 bra comm_write_button_polarity ; RCREG1=0x49 | |
1397 dcfsnz WREG | |
1398 movff RCREG1, char_I_PSCR_drop ; RCREG1=0x4A | |
1399 dcfsnz WREG | |
1400 movff RCREG1, char_I_PSCR_lungratio ; RCREG1=0x4B | |
1401 dcfsnz WREG | |
1402 movff RCREG1, char_I_ppO2_max_deco ; RCREG1=0x4C | |
1403 dcfsnz WREG | |
1404 movff RCREG1, char_I_ppO2_min_loop ; RCREG1=0x4D | |
1405 dcfsnz WREG | |
1406 movff RCREG1, char_I_gas_avail_size+0 ; RCREG1=0x4E | |
1407 dcfsnz WREG | |
1408 movff RCREG1, char_I_gas_avail_size+1 ; RCREG1=0x4F | |
1409 dcfsnz WREG | |
1410 movff RCREG1, char_I_gas_avail_size+2 ; RCREG1=0x50 | |
1411 dcfsnz WREG | |
1412 movff RCREG1, char_I_gas_avail_size+3 ; RCREG1=0x51 | |
1413 dcfsnz WREG | |
1414 movff RCREG1, char_I_gas_avail_size+4 ; RCREG1=0x52 | |
1415 dcfsnz WREG | |
1416 movff RCREG1, char_I_gas_avail_pres+0 ; RCREG1=0x53 | |
1417 dcfsnz WREG | |
1418 movff RCREG1, char_I_gas_avail_pres+1 ; RCREG1=0x54 | |
1419 dcfsnz WREG | |
1420 movff RCREG1, char_I_gas_avail_pres+2 ; RCREG1=0x55 | |
1421 dcfsnz WREG | |
1422 movff RCREG1, char_I_gas_avail_pres+3 ; RCREG1=0x56 | |
1423 dcfsnz WREG | |
1424 movff RCREG1, char_I_gas_avail_pres+4 ; RCREG1=0x57 | |
1425 dcfsnz WREG | |
1426 movff RCREG1, char_I_CC_max_frac_O2 ; RCREG1=0x58 | |
1427 dcfsnz WREG | |
1428 movff RCREG1, opt_sim_setpoint_number ; RCREG1=0x59 | |
1429 dcfsnz WREG | |
1430 movff RCREG1, opt_calc_asc_gasvolume ; RCREG1=0x5A | |
1431 dcfsnz WREG | |
1432 movff RCREG1, opt_sim_use_aGF ; RCREG1=0x5B | |
1433 dcfsnz WREG | |
1434 movff RCREG1, char_I_altitude_wait ; RCREG1=0x5C | |
1435 dcfsnz WREG | |
1436 movff RCREG1, opt_enable_IBCD ; RCREG1=0x5D | |
1437 dcfsnz WREG | |
1438 movff RCREG1, opt_sat_multiplier_gf ; RCREG1=0x5E | |
1439 dcfsnz WREG | |
1440 movff RCREG1, opt_desat_multiplier_gf ; RCREG1=0x5F | |
1441 dcfsnz WREG | |
1442 movff RCREG1, opt_transmitter_id_1+0 ; RCREG1=0x60 | |
1443 dcfsnz WREG | |
1444 movff RCREG1, opt_transmitter_id_1+1 ; RCREG1=0x61 | |
1445 dcfsnz WREG | |
1446 movff RCREG1, opt_transmitter_id_2+0 ; RCREG1=0x62 | |
1447 dcfsnz WREG | |
1448 movff RCREG1, opt_transmitter_id_2+1 ; RCREG1=0x63 | |
1449 dcfsnz WREG | |
1450 movff RCREG1, opt_transmitter_id_3+0 ; RCREG1=0x64 | |
1451 dcfsnz WREG | |
1452 movff RCREG1, opt_transmitter_id_3+1 ; RCREG1=0x65 | |
1453 dcfsnz WREG | |
1454 movff RCREG1, opt_transmitter_id_4+0 ; RCREG1=0x66 | |
1455 dcfsnz WREG | |
1456 movff RCREG1, opt_transmitter_id_4+1 ; RCREG1=0x67 | |
1457 dcfsnz WREG | |
1458 movff RCREG1, opt_transmitter_id_5+0 ; RCREG1=0x68 | |
1459 dcfsnz WREG | |
1460 movff RCREG1, opt_transmitter_id_5+1 ; RCREG1=0x69 | |
1461 dcfsnz WREG | |
1462 movff RCREG1, opt_transmitter_id_6+0 ; RCREG1=0x6A | |
1463 dcfsnz WREG | |
1464 movff RCREG1, opt_transmitter_id_6+1 ; RCREG1=0x6B | |
1465 dcfsnz WREG | |
1466 movff RCREG1, opt_transmitter_id_7+0 ; RCREG1=0x6C | |
1467 dcfsnz WREG | |
1468 movff RCREG1, opt_transmitter_id_7+1 ; RCREG1=0x6D | |
1469 dcfsnz WREG | |
1470 movff RCREG1, opt_transmitter_id_8+0 ; RCREG1=0x6E | |
1471 dcfsnz WREG | |
1472 movff RCREG1, opt_transmitter_id_8+1 ; RCREG1=0x6F | |
1473 dcfsnz WREG | |
1474 movff RCREG1, opt_transmitter_id_9+0 ; RCREG1=0x70 | |
1475 dcfsnz WREG | |
1476 movff RCREG1, opt_transmitter_id_9+1 ; RCREG1=0x71 | |
1477 dcfsnz WREG | |
1478 movff RCREG1, opt_transmitter_id_10+0 ; RCREG1=0x72 | |
1479 dcfsnz WREG | |
1480 movff RCREG1, opt_transmitter_id_10+1 ; RCREG1=0x73 | |
1481 dcfsnz WREG | |
1482 movff RCREG1, char_I_gas_avail_size+5 ; RCREG1=0x74 | |
1483 dcfsnz WREG | |
1484 movff RCREG1, char_I_gas_avail_size+6 ; RCREG1=0x75 | |
1485 dcfsnz WREG | |
1486 movff RCREG1, char_I_gas_avail_size+7 ; RCREG1=0x76 | |
1487 dcfsnz WREG | |
1488 movff RCREG1, char_I_gas_avail_size+8 ; RCREG1=0x77 | |
1489 dcfsnz WREG | |
1490 movff RCREG1, char_I_gas_avail_size+9 ; RCREG1=0x78 | |
1491 dcfsnz WREG | |
1492 movff RCREG1, char_I_gas_avail_pres+5 ; RCREG1=0x79 | |
1493 dcfsnz WREG | |
1494 movff RCREG1, char_I_gas_avail_pres+6 ; RCREG1=0x7A | |
1495 dcfsnz WREG | |
1496 movff RCREG1, char_I_gas_avail_pres+7 ; RCREG1=0x7B | |
1497 dcfsnz WREG | |
1498 movff RCREG1, char_I_gas_avail_pres+8 ; RCREG1=0x7C | |
1499 dcfsnz WREG | |
1500 movff RCREG1, char_I_gas_avail_pres+9 ; RCREG1=0x7D | |
1501 dcfsnz WREG | |
1502 movff RCREG1, opt_TR_mode ; RCREG1=0x7E | |
1503 dcfsnz WREG | |
1504 movff RCREG1, opt_TR_1st_pres ; RCREG1=0x7F | |
1505 dcfsnz WREG | |
1506 movff RCREG1, opt_TR_2nd_pres ; RCREG1=0x80 | |
1507 dcfsnz WREG | |
1508 movff RCREG1, opt_TR_Bail_pres ; RCREG1=0x81 | |
1509 dcfsnz WREG | |
1510 movff RCREG1, char_I_max_pres_diff ; RCREG1=0x82 | |
1511 dcfsnz WREG | |
1512 movff RCREG1, opt_ZfactorUse ; RCREG1=0x83 | |
1513 dcfsnz WREG | |
1514 movff RCREG1, opt_ZfactorTemp ; RCREG1=0x84 | |
1515 dcfsnz WREG | |
1516 movff RCREG1, opt_2ndDepthDisp ; RCREG1=0x85 | |
1517 dcfsnz WREG | |
1518 movff RCREG1, opt_max_depth ; RCREG1=0x86 | |
1519 dcfsnz WREG | |
1520 movff RCREG1, char_I_descent_speed ; RCREG1=0x87 | |
1521 dcfsnz WREG | |
1522 movff RCREG1, opt_store_apnoe_dive ; RCREG1=0x88 | |
1523 dcfsnz WREG | |
1524 movff RCREG1, opt_tissue_graphics ; RCREG1=0x89 | |
1525 dcfsnz WREG | |
1526 movff RCREG1, opt_layout ; RCREG1=0x8A | |
1527 dcfsnz WREG | |
1528 movff RCREG1, opt_extended_stops ; RCREG1=0x8B | |
1529 dcfsnz WREG | |
1530 movff RCREG1, char_I_gas_density_att ; RCREG1=0x8C | |
1531 dcfsnz WREG | |
1532 movff RCREG1, char_I_gas_density_warn ; RCREG1=0x8D | |
1533 dcfsnz WREG | |
1534 movff RCREG1, char_I_dil_ppO2_check ; RCREG1=0x8E | |
1535 | |
1536 | |
1537 comm_write_abort: | |
1538 comm_write_done: | |
1539 ; check options, gases and diluents | |
1540 call option_check_all ; check all options (and reset if not within their min/max boundaries) | |
1541 goto comm_download_mode0 ; done, loop with timeout reset | |
1542 | |
1543 ;----------------------------------------------------------------------------- | |
1544 | |
1545 ; Memory map is as follows: | 984 ; Memory map is as follows: |
1546 ; ------------------------- | 985 ; ------------------------- |
1547 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | 986 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases |
1548 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | 987 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents |
1549 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | 988 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases |
1550 ; opt_dil_He_ratio res 5 ; He ratios of diluents | 989 ; opt_dil_He_ratio res 5 ; He ratios of diluents |
1551 ; opt_gas_type res 5 ; OC/bailout gas type | 990 ; opt_gas_type res 5 ; OC/bailout gas type |
1552 ; opt_dil_type res 5 ; dil type | 991 ; opt_dil_type res 5 ; dil type |
1553 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | 992 ; opt_gas_change res 5 ; change depths for OC/Bailout gases |
1554 ; opt_dil_change res 5 ; change depths for diluents | 993 ; opt_dil_change res 5 ; change depths for diluents |
1555 | 994 ; |
1556 comm_write_gas_dil: | 995 comm_write_gas_dil: |
996 SERIAL_RR_RECEIVE_RAM hi,.4 ; (try to) receive 4 option values | |
997 btfsc rs232_rx_timeout ; got all 4 bytes? | |
998 bra comm_command_timeout ; NO - abort, back to command loop | |
999 | |
1000 ; check validity of O2 value | |
1001 movlw gaslist_min_o2-.1 ; get min value minus 1 | |
1002 cpfsgt hi ; received O2% >= min ? | |
1003 bra comm_command_error ; NO - abort, back to command loop | |
1004 movlw gaslist_max_o2+.1 ; get max value plus 1 | |
1005 cpfslt hi ; received O2% <= max ? | |
1006 bra comm_command_error ; NO - abort, back to command loop | |
1007 | |
1008 ; check validity of He value | |
1009 movlw gaslist_max_He+.1 ; get max value plus 1 | |
1010 cpfslt up ; received O2% <= max ? | |
1011 bra comm_command_error ; NO - abort, back to command loop | |
1012 | |
1013 ; check O2% + He% <= 100% | |
1014 movlw .100 ; load 100% | |
1015 bsf STATUS,C ; set carry = clear borrow | |
1016 subfwb hi,W ; subtract O2% from 100% | |
1017 btfss STATUS,C ; result negative? | |
1018 bra comm_command_error ; YES - abort, back to command loop | |
1019 subfwb up,W ; NO - subtract He% | |
1020 btfss STATUS,C ; - now negative? | |
1021 bra comm_command_error ; YES - abort, back to command loop | |
1022 | |
1023 ; check validity of type | |
1024 movlw 0x14 ; last option index for gases | |
1025 cpfsgt lo ; received option index > end of gas range ? | |
1026 bra comm_write_dil ; YES - check type for diluents | |
1027 ;bra comm_write_gas ; NO - check type for gases | |
1028 | |
1029 comm_write_gas: | |
1030 ; check validity of type for a gas | |
1031 movlw num_gas_types ; load number of gas types | |
1032 bra comm_write_gas_dil_common ; continue with common part | |
1033 | |
1034 comm_write_dil: | |
1035 ; check validity of type for a diluent | |
1036 movlw num_dil_types ; load number of diluent types | |
1037 ;bra comm_write_gas_dil_common ; continue with common part | |
1038 | |
1039 comm_write_gas_dil_common: | |
1040 cpfslt ex ; received type < max ? | |
1041 bra comm_command_error ; NO - abort, back to command loop | |
1042 | |
1043 ; check validity of change depth | |
1044 movlw gaslist_max_change_depth+.1 ; get max value plus 1 | |
1045 cpfslt ul ; received change depth <= max ? | |
1046 bra comm_command_error ; NO - abort, back to command loop | |
1047 | |
1048 ; all values ok, can finally be written | |
1557 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays | 1049 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays |
1558 movf up,W ; load index (0-9) of gas/dil into WREG, addressing O2 ratio | 1050 movlw 0x10 ; compute gas index from option index... |
1559 movff RCREG1,PLUSW0 ; receive O2 ratio | 1051 subwf lo,W ; ...making WREG point to O2 ratio |
1560 rcall comm_get_byte ; wait for UART | 1052 movff hi,PLUSW0 ; set O2 ratio |
1561 addlw .10 ; increment index by 10, addressing He ratio now | 1053 addlw .10 ; increment WREG by 10 to point to He ratio |
1562 movff RCREG1,PLUSW0 ; receive He ratio | 1054 movff up,PLUSW0 ; set He ratio |
1563 rcall comm_get_byte ; wait for UART | 1055 addlw .10 ; increment WREG by 10 to point to gas/dil type |
1564 addlw .10 ; increment index by 10, addressing gas/dil type now | 1056 movff ex,PLUSW0 ; set gas/dil type |
1565 movff RCREG1,PLUSW0 ; receive gas/dil type | 1057 addlw .10 ; increment WREG by 10 to point to change depth |
1566 rcall comm_get_byte ; wait for UART | 1058 movff ul,PLUSW0 ; set change depth |
1567 addlw .10 ; increment index by 10, addressing change depth now | 1059 |
1568 movff RCREG1,PLUSW0 ; receive change depth | 1060 bra comm_command_loop ; done, back to command loop |
1569 bra comm_write_done ; done, loop with timeout reset | 1061 |
1570 | 1062 |
1571 | 1063 ;----------------------------------------------------------------------------- |
1064 ; Read a setpoint dataset | |
1065 ; | |
1572 ; Memory map is as follows: | 1066 ; Memory map is as follows: |
1573 ; ------------------------- | 1067 ; ------------------------- |
1574 ; opt_setpoint_cbar res 5 ; setpoints in cbar | 1068 ; opt_setpoint_cbar res 5 ; setpoints in cbar |
1575 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter | 1069 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter |
1576 | 1070 ; |
1071 comm_read_sp: | |
1072 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values | |
1073 movlw 0x1A ; compute SP index from option index... | |
1074 subwf lo,W ; ...making WREG point to cbar value | |
1075 SERIAL_CC_SEND PLUSW0 ; send setpoint cbar value | |
1076 addlw .5 ; increment WREG by 5 to point to change depth | |
1077 SERIAL_CC_SEND PLUSW0 ; send change depth | |
1078 bra comm_command_loop ; done, back to command loop | |
1079 | |
1080 | |
1081 ;----------------------------------------------------------------------------- | |
1082 ; Write a setpoint dataset | |
1083 ; | |
1084 ; Memory map is as follows: | |
1085 ; ------------------------- | |
1086 ; opt_setpoint_cbar res 5 ; setpoints in cbar | |
1087 ; opt_setpoint_change res 5 ; change depths in meter | |
1088 ; | |
1577 comm_write_sp: | 1089 comm_write_sp: |
1090 SERIAL_RR_RECEIVE_RAM hi,.2 ; (try to) receive 2 option values | |
1091 btfsc rs232_rx_timeout ; got both bytes? | |
1092 bra comm_command_timeout ; NO - abort, back to command loop | |
1093 | |
1094 ; check validity of setpoint value | |
1095 movlw gaslist_sp_min-.1 ; get min value minus 1 | |
1096 cpfsgt hi ; received O2% >= min ? | |
1097 bra comm_command_error ; NO - abort, back to command loop | |
1098 movlw gaslist_sp_max+.1 ; get max value plus 1 | |
1099 cpfslt hi ; received O2% <= max ? | |
1100 bra comm_command_error ; NO - abort, back to command loop | |
1101 | |
1102 ; check validity of change depth | |
1103 movlw sp_max_change_depth+.1 ; get max value plus 1 | |
1104 cpfslt up ; received change depth <= max ? | |
1105 bra comm_command_error ; NO - abort, back to command loop | |
1106 | |
1578 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values | 1107 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values |
1579 movf up,W ; load index (0-4) of setpoint into WREG, addressing cbar value | 1108 movlw 0x1A ; compute SP index from option index... |
1580 movff RCREG1,PLUSW0 ; receive setpoint cbar value | 1109 subwf lo,W ; ...making WREG point to cbar value |
1581 rcall comm_get_byte ; wait for UART | 1110 movff hi,PLUSW0 ; set cbar value |
1582 addlw .5 ; increment index by 5, addressing change depth now | 1111 addlw .5 ; increment WREG by 5 to point to change depth |
1583 movff RCREG1,PLUSW0 ; receive change depth | 1112 movff up,PLUSW0 ; set change depth |
1584 bra comm_write_done ; done, loop with timeout reset | 1113 |
1585 | 1114 bra comm_command_loop ; done, back to command loop |
1586 ;----------------------------------------------------------------------------- | 1115 |
1587 | 1116 ;----------------------------------------------------------------------------- |
1588 comm_send_string: | 1117 |
1589 movlw "n" ; send echo | |
1590 movwf TXREG1 | |
1591 call comm_write_byte ; wait for completion of transmit | |
1592 WIN_SMALL comm_string_column, comm_string_row | |
1593 movlw .16 | |
1594 movwf lo ; counter | |
1595 comm_send_string_loop: | |
1596 call comm_get_byte | |
1597 btfsc rs232_rx_timeout ; got a byte? | |
1598 bra comm_send_string_abort ; NO - abort | |
1599 movff RCREG1,POSTINC2 ; store character | |
1600 decfsz lo,F | |
1601 bra comm_send_string_loop | |
1602 comm_send_string_abort: | |
1603 STRCAT_PRINT "" ; show the text | |
1604 goto comm_download_mode0 ; done, loop with timeout reset | |
1605 | |
1606 ;----------------------------------------------------------------------------- | |
1607 | |
1608 comm_write_button_polarity: | |
1609 ; store RCREG1 into EEPROM .897 | |
1610 movlw LOW .897 | |
1611 movwf EEADR | |
1612 movlw HIGH .897 | |
1613 movwf EEADRH | |
1614 movff RCREG1,EEDATA | |
1615 movff EEDATA,button_polarity ; 0xFF (both normal), 0x00 (both inverted), 0x01 (left inverted only), 0x02 (right inverted only) | |
1616 call write_eeprom ; EEDATA into EEPROM@EEADR | |
1617 clrf EEADRH ; reset EEADRH | |
1618 goto comm_download_mode0 ; done, loop with timeout reset | |
1619 | |
1620 ;---------------------------------------------------------------------------- | |
1621 END | 1118 END |