Mercurial > public > hwos_code
annotate 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 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
631 | 3 ; File comm.asm combined next generation V3.08.8 |
0 | 4 ; |
5 ; RS232 via USB | |
6 ; | |
7 ; Copyright (c) 2012, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
10 ; 2011-08-22 : [mH] Creation | |
631 | 11 ; 2012-02-11 : [jDG] Added 0x63 set custom text, and "i" identify |
0 | 12 |
275 | 13 #include "hwos.inc" |
0 | 14 #include "eeprom_rs232.inc" |
15 #include "tft.inc" | |
16 #include "wait.inc" | |
17 #include "strings.inc" | |
18 #include "convert.inc" | |
19 #include "external_flash.inc" | |
20 #include "tft_outputs.inc" | |
21 #include "surfmode.inc" | |
22 #include "rtc.inc" | |
23 #include "adc_lightsensor.inc" | |
299
6c4800af27ac
Make char_I_bottom_usage and char_I_deco_usage configurable from PC
heinrichsweikamp
parents:
275
diff
changeset
|
24 #include "shared_definitions.h" |
604 | 25 #include "math.inc" |
631 | 26 #include "i2c.inc" |
27 #include "logbook.inc" | |
28 | |
0 | 29 |
582 | 30 extern restart |
31 extern option_reset_all | |
631 | 32 extern option_check_and_store_all |
33 extern option_read_serial | |
34 extern option_write_serial | |
582 | 35 extern gaslist_cleanup_list |
631 | 36 extern eeprom_deco_data_write |
0 | 37 |
38 | |
631 | 39 ; timeouts |
40 #DEFINE timeout_comm_pre_mode .240 ; [sec] timeout before communication is established | |
41 #DEFINE timeout_service_mode .120 ; [sec] timeout when communication is established | |
582 | 42 |
631 | 43 ; positioning of title |
44 #DEFINE comm_title_row .0 | |
623 | 45 #DEFINE comm_title_column_usb .40 |
582 | 46 #DEFINE comm_title_column_ble .25 |
0 | 47 |
631 | 48 ; positioning of host-sent text messages |
49 #DEFINE comm_string_row .30 | |
582 | 50 #DEFINE comm_string_column .40 |
51 | |
631 | 52 ; positioning of COMM mode status messages |
53 #DEFINE comm_status1_row .70 | |
582 | 54 #DEFINE comm_status1_column .10 |
55 #DEFINE comm_status2_row .100 | |
56 #DEFINE comm_status2_column comm_status1_column | |
57 #DEFINE comm_status3_row .130 | |
58 #DEFINE comm_status3_column comm_status1_column | |
604 | 59 #DEFINE comm_status4_row .160 |
60 #DEFINE comm_status4_column comm_status1_column | |
61 | |
631 | 62 ; positioning of COMM mode warning icon |
63 #DEFINE comm_warning_row .160 | |
623 | 64 #DEFINE comm_warning_column .65 |
582 | 65 |
0 | 66 |
631 | 67 ;#DEFINE testloop_avail ; uncomment if testloop code is available |
68 | |
69 | |
604 | 70 comm CODE |
71 | |
72 ;============================================================================= | |
0 | 73 |
623 | 74 global comm_mode_usb |
75 comm_mode_usb: ; entry point for comm mode via USB | |
76 WAITMS d'1' ; wait 1 ms | |
77 btfss vusb_in ; USB still plugged in? | |
78 return ; NO - it was only a glitch, abort | |
631 | 79 WAITMS d'1' ; YES - wait 1 ms |
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 | |
623 | 84 |
85 global comm_mode_ble | |
86 comm_mode_ble: ; entry point for comm mode via BLE | |
87 bcf aux_flag ; remember to show BLE title | |
88 ;bra comm_mode_common ; continue with common part | |
89 | |
90 comm_mode_common: | |
631 | 91 clrf STKPTR ; reset addresses stack |
623 | 92 call TFT_ClearScreen ; clear screen |
93 WIN_COLOR color_greenish ; set color | |
631 | 94 |
623 | 95 btfss aux_flag ; shall show USB title? |
631 | 96 bra comm_mode_common_1 ; NO - show BLE title |
623 | 97 WIN_SMALL comm_title_column_usb, comm_title_row ; YES - set USB title position |
98 STRCPY_TEXT_PRINT tUsbTitle ; - print USB title text | |
631 | 99 bra comm_mode_common_2 ; - continue with common part |
100 | |
623 | 101 comm_mode_common_1: |
102 WIN_SMALL comm_title_column_ble, comm_title_row ; set BLE title position | |
103 STRCPY_TEXT_PRINT tBleTitle ; print BLE title text | |
631 | 104 ;bra comm_mode_common_2 ; continue with common part |
105 | |
623 | 106 comm_mode_common_2: |
107 call TFT_standard_color ; set standard color | |
631 | 108 WIN_TOP .10 ; set position of USB/BLE logo, row |
109 WIN_LEFT .1 ; set position of USB/BLE logo, column | |
628 | 110 btfsc battery_gauge_available ; "+" bootloader ? |
631 | 111 bra comm_mode_common_3 ; NO - show logo type 1 |
628 | 112 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_2 ; YES - show USB/BLE logo 2 |
631 | 113 bra comm_mode_common_4 ; - continue with common part |
114 | |
628 | 115 comm_mode_common_3: |
631 | 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 | |
628 | 119 comm_mode_common_4: |
631 | 120 WIN_SMALL comm_status1_column,comm_status1_row ; print status message "starting..." |
121 STRCPY_TEXT_PRINT tUsbStarting ; ... | |
122 | |
623 | 123 WIN_TINY .40,.240-.16 ; set output position to bottom line |
124 call TFT_show_serial_and_firmware ; show serial number and firmware version | |
604 | 125 |
126 IFDEF _screendump | |
631 | 127 bcf screen_dump_avail ; disable screen dump function |
604 | 128 ENDIF |
129 | |
631 | 130 bcf switch_right ; clear potential left-over right button event |
131 call enable_rs232 ; enable serial comm, also sets CPU to normal speed | |
132 | |
133 WIN_SMALL comm_status1_column+.80,comm_status1_row ; print (adding to status message) "done..." | |
134 STRCPY_TEXT_PRINT tUsbStartDone ; ... | |
135 | |
136 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet | |
137 movwf comm_timeout_timer ; initialize timeout counter | |
0 | 138 |
631 | 139 comm_mode_selection_loop: |
140 bcf trigger_full_second ; clear 'one second elapsed' flag | |
141 bcf LEDr ; switch off red LED / power down TR co-processor | |
142 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? | |
143 bra comm_service_exit ; YES - timeout, exit comm mode | |
144 ;bra comm_mode_selection_loop_1 ; NO - try to receive a byte | |
145 comm_mode_selection_loop_1: | |
146 SERIAL_CC_RECEIVE lo ; (try to) receive 1 byte | |
147 btfsc rs232_rx_timeout ; timeout? | |
148 bra comm_mode_selection_loop_2 ; YES - check for comm mode termination | |
149 movf lo,W ; NO - copy received byte to lo | |
150 xorlw 0xAA ; - service mode start byte received? | |
151 bz comm_service_mode_check ; YES - check if correct key will be send | |
152 movf lo,W ; NO - copy received byte to lo again | |
153 xorlw 0xBB ; - download mode start byte received? | |
154 bz comm_download_mode ; YES - enter command loop | |
155 ;bra comm_mode_selection_loop_2 ; NO - check for comm mode termination | |
156 comm_mode_selection_loop_2: | |
157 btfsc ble_available ; BLE available? | |
158 bra comm_mode_selection_loop_3 ; YES - skip USB check check (required for very old OSTC sport) | |
159 btfss vusb_in ; NO - USB plugged in? | |
160 bra comm_service_exit_nousb_delay ; NO - disconnected, check for vusb_in glitch | |
161 ;bra comm_mode_selection_loop_3 ; YES - check for exit button or continue looping | |
162 comm_mode_selection_loop_3: | |
163 btfsc switch_right ; right button pressed? | |
164 bra comm_service_exit ; YES - exit comm mode | |
165 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile? | |
166 bra comm_mode_selection_loop ; YES - loop with clocking down timeout counter | |
167 bra comm_mode_selection_loop_1 ; NO - loop without clocking down timeout counter | |
0 | 168 |
169 | |
170 ;----------------------------------------------------------------------------- | |
631 | 171 ; Received start byte for service mode, await service key |
0 | 172 ; |
631 | 173 comm_service_mode_check: |
174 | |
175 SERIAL_LC_SEND 0x4B ; request peer to send service key | |
176 | |
177 ; receive a 3 byte service key transmitted in big-endian, echo each byte | |
178 | |
179 clrf WREG ; clear WREG | |
180 | |
181 SERIAL_CC_RECEIVE lo ; receive 1st byte, store in lo | |
182 xorwf lo,W ; exclusive-or received byte into WREG | |
183 xorlw UPPER (comm_service_key) ; exclusive-or expected byte into WREG | |
184 SERIAL_CC_SEND lo ; echo 1st byte | |
0 | 185 |
631 | 186 SERIAL_CC_RECEIVE lo ; receive 2nd byte, store in lo |
187 xorwf lo,W ; exclusive-or received byte into WREG | |
188 xorlw HIGH (comm_service_key & 0xFFFF) ; exclusive-or expected byte into WREG | |
189 SERIAL_CC_SEND lo ; echo 2nd byte | |
190 | |
191 SERIAL_CC_RECEIVE lo ; receive 3rd byte, store in lo | |
192 xorwf lo,W ; exclusive-or received byte into WREG | |
193 xorlw LOW (comm_service_key & 0xFFFF) ; exclusive-or expected byte into WREG | |
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 | |
0 | 203 |
623 | 204 |
0 | 205 ;----------------------------------------------------------------------------- |
631 | 206 ; Received start byte for download mode |
623 | 207 ; |
631 | 208 comm_download_mode: |
209 SERIAL_LC_SEND 0xBB ; inform peer download mode will be started | |
0 | 210 |
631 | 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 | |
0 | 216 |
217 ;----------------------------------------------------------------------------- | |
631 | 218 ; Notify RX timeout occurred |
623 | 219 ; |
631 | 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 | |
0 | 228 |
623 | 229 ;----------------------------------------------------------------------------- |
631 | 230 ; Notify error in parameters |
623 | 231 ; |
631 | 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 | |
0 | 239 |
623 | 240 |
241 ;----------------------------------------------------------------------------- | |
631 | 242 ; Command loop: wait for a command |
623 | 243 ; |
631 | 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 | |
0 | 249 |
631 | 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 | |
0 | 255 |
631 | 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 | |
346
cf9ce6053dee
New option to download "Compact Headers". Improved BLE support (OSTC 2 and OSTC 3+), updated OSTC interface documentation
heinrichsweikamp
parents:
337
diff
changeset
|
276 |
cf9ce6053dee
New option to download "Compact Headers". Improved BLE support (OSTC 2 and OSTC 3+), updated OSTC interface documentation
heinrichsweikamp
parents:
337
diff
changeset
|
277 |
cf9ce6053dee
New option to download "Compact Headers". Improved BLE support (OSTC 2 and OSTC 3+), updated OSTC interface documentation
heinrichsweikamp
parents:
337
diff
changeset
|
278 ;----------------------------------------------------------------------------- |
631 | 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 | |
0 | 287 |
288 ;----------------------------------------------------------------------------- | |
631 | 289 ; Decode and execute a command |
290 ; | |
291 comm_command_decode: | |
292 bcf LEDr ; switch off red led | |
80 | 293 |
631 | 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 | |
80 | 331 |
332 ;----------------------------------------------------------------------------- | |
631 | 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 | |
0 | 339 |
631 | 340 comm_service_exit_nousb_delay: |
341 WAITMS d'200' ; wait 200 ms | |
342 btfsc vusb_in ; USB sensed again? | |
343 bra comm_mode_selection_loop_3 ; YES - was just a glitch, continue | |
344 ;bra comm_service_exit_nousb ; NO - proceed exiting | |
0 | 345 |
631 | 346 comm_service_exit_nousb: |
347 WIN_SMALL comm_status3_column, comm_status3_row ; print "Port closed" message | |
348 STRCPY_TEXT_PRINT tUsbClosed ; ... | |
349 ;bra comm_service_exit_common ; proceed exiting | |
350 | |
351 comm_service_exit_common: | |
352 SERIAL_LC_SEND 0xFF ; acknowledge exit command | |
353 call wait_1s ; wait <= 1 second | |
354 call wait_1s ; wait 1 second | |
355 call disable_rs232 ; shut down comm port | |
356 bcf LEDr ; switch off red LED | |
357 goto restart ; restart | |
358 | |
0 | 359 |
360 ;----------------------------------------------------------------------------- | |
631 | 361 ; Set Real-Time-Clock |
0 | 362 ; |
631 | 363 comm_set_time: |
364 SERIAL_LC_SEND 0x62 ; acknowledge command | |
365 | |
366 ; receive 6 bytes coming in sequence: hour, minute, second, month, day, year | |
367 SERIAL_RR_RECEIVE_RAM mpr,.6 | |
368 | |
369 ; got all 6 bytes? | |
370 btfsc rs232_rx_timeout ; timeout? | |
371 bra comm_command_timeout ; YES - abort, back to command loop | |
372 | |
373 ; map the received bytes onto the rtc_latched variables | |
374 movff mpr+0,rtc_latched_hour | |
375 movff mpr+1,rtc_latched_mins | |
376 movff mpr+2,rtc_latched_secs | |
377 movff mpr+3,rtc_latched_month | |
378 movff mpr+4,rtc_latched_day | |
379 movff mpr+5,rtc_latched_year | |
0 | 380 |
631 | 381 ; set the RTC |
382 call rtc_set_rtc ; write time and date to RTC module | |
383 | |
384 bra comm_command_loop ; done, back to command loop | |
385 | |
386 | |
387 ;----------------------------------------------------------------------------- | |
388 ; Write a 15 char text to the OSTC display | |
389 ; | |
390 comm_show_text: | |
391 ; set font and output position of the text to show | |
392 WIN_SMALL comm_string_column, comm_string_row | |
393 | |
394 SERIAL_LC_SEND 0x6E ; acknowledge command | |
395 | |
396 SERIAL_RR_RECEIVE_RAM buffer,.16 ; (try to) receive 16 chars and write them to 'buffer' using FSR2 | |
397 STRCAT_PRINT "" ; dump whatever was received to the screen | |
398 | |
399 bra comm_command_loop ; done, back to command loop | |
400 | |
0 | 401 |
402 ;----------------------------------------------------------------------------- | |
604 | 403 ; Reply Serial (2 bytes low:high), firmware (major.minor) and custom text |
0 | 404 ; |
405 comm_identify: | |
631 | 406 SERIAL_LC_SEND 0x69 ; acknowledge command |
0 | 407 |
631 | 408 ;---- send OSTC serial number |
409 call eeprom_serial_number_read ; read OSTC serial number | |
410 SERIAL_CC_SEND mpr+0 ; send serial number, low byte | |
411 SERIAL_CC_SEND mpr+1 ; send serial number, high byte | |
0 | 412 |
631 | 413 ;---- send firmware version |
414 SERIAL_LC_SEND fw_version_major ; send firmware version, major | |
415 SERIAL_LC_SEND fw_version_minor ; send firmware version, minor | |
0 | 416 |
631 | 417 ;---- send custom text |
418 SERIAL_RR_SEND_RAM opt_name,opt_name_length | |
604 | 419 |
631 | 420 bra comm_command_loop ; done, back to command loop |
0 | 421 |
623 | 422 |
235
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
223
diff
changeset
|
423 ;----------------------------------------------------------------------------- |
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
223
diff
changeset
|
424 ; Reply hardware descriptor byte |
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
223
diff
changeset
|
425 ; |
623 | 426 comm_hardware_descriptor: |
631 | 427 SERIAL_LC_SEND 0x6A ; acknowledge command |
235
23311219dacc
under construction: new hardware_flag to configure different hardware versions
heinrichsweikamp
parents:
223
diff
changeset
|
428 |
623 | 429 movf HW_descriptor,W ; get hardware descriptor |
430 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | |
431 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software | |
631 | 432 SERIAL_CC_SEND WREG ; send modified hardware descriptor |
433 | |
434 bra comm_command_loop ; done, back to command loop | |
623 | 435 |
0 | 436 |
631 | 437 ;----------------------------------------------------------------------------- |
438 ; Reply detailed hardware descriptor | |
439 ; | |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
426
diff
changeset
|
440 comm_feature_and_hardware: |
631 | 441 SERIAL_LC_SEND 0x60 ; acknowledge command |
623 | 442 |
631 | 443 SERIAL_LC_SEND 0x00 ; send hardware high byte (fixed zero) |
623 | 444 |
445 movf HW_descriptor,W ; get hardware descriptor | |
446 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | |
447 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software | |
631 | 448 SERIAL_CC_SEND WREG ; send modified hardware low byte |
623 | 449 |
631 | 450 SERIAL_LC_SEND 0x00 ; send feature high byte (fixed zero) |
451 SERIAL_LC_SEND 0x00 ; send feature low byte (fixed zero) | |
623 | 452 |
631 | 453 SERIAL_LC_SEND 0x00 ; send model descriptor byte (fixed zero) |
623 | 454 |
631 | 455 bra comm_command_loop ; done, back to command loop |
623 | 456 |
604 | 457 |
458 ;----------------------------------------------------------------------------- | |
459 | |
631 | 460 comm_send_headers_short: |
461 SERIAL_LC_SEND 0x6D ; acknowledge command | |
582 | 462 |
631 | 463 ; send short header (16 bytes/dive) |
464 ; index 0: 0x200009 - 0x200016 + 0x200050 - 0x200051 + 0x200008 | |
465 ; 1: 0x201009 - 0x201016 + 0x201050 - 0x201051 + 0x201008 | |
466 ; 2: 0x202009 - 0x202016 + 0x202050 - 0x202051 + 0x202008 | |
467 ; ... | |
468 ; 255: 0x2FF009 - 0x2FF016 + 0x2FF050 - 0x2FF051 + 0x2FF008 | |
0 | 469 |
631 | 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 | |
0 | 474 |
631 | 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 | |
0 | 479 |
631 | 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 | |
0 | 484 |
631 | 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 | |
582 | 489 |
631 | 490 ; send the assembled short header |
491 SERIAL_RR_SEND_RAM header_buffer,.16 ; send buffer, 16 bytes to do | |
582 | 492 |
631 | 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 | |
582 | 497 |
0 | 498 |
499 ;----------------------------------------------------------------------------- | |
500 | |
631 | 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 ; | |
525 comm_send_dive: | |
526 SERIAL_LC_SEND 0x66 ; acknowledge command | |
527 | |
528 SERIAL_CC_RECEIVE WREG ; (try to) receive the dive index (0-255) | |
529 btfsc rs232_rx_timeout ; got dive index? | |
530 bra comm_command_timeout ; NO - abort, back to command loop | |
531 | |
532 call log_header_addr_by_index ; compute header start address from index, result in mpr | |
533 FLASH_RR_READ mpr,header_buffer,.256; copy the complete header into the buffer | |
534 | |
535 ; get pointers and length of profile data | |
536 MOVTT header_buffer+index_profile_start_address,ext_flash_address | |
537 MOVTT header_buffer+index_profile_end_address, ext_flash_end_pointer | |
538 MOVTT header_buffer+index_profile_byte_count, ext_flash_length_counter | |
539 | |
540 ; check if profile data are available | |
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 | |
604 | 554 |
631 | 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 | |
604 | 579 |
631 | 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 | |
604 | 610 |
631 | 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 | |
582 | 653 |
631 | 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 | |
79
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
723 |
604 | 724 ;----------------------------------------------------------------------------- |
631 | 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 | |
157
5ee76921e359
make new parameters configurable through pc
heinrichsweikamp
parents:
150
diff
changeset
|
735 |
631 | 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 | |
828 movwf ext_flash_address+2 | |
829 | |
830 return ; done, complete start address available | |
831 | |
832 | |
833 ;----------------------------------------------------------------------------- | |
834 ; Receive a 3 byte length (on serial: big-endian, in memory: little-endian) | |
835 ; | |
836 comm_get_length: | |
837 SERIAL_RR_RECEIVE_RAM ext_flash_length_counter,.3 ; receive 3 bytes | |
838 btfsc rs232_rx_timeout ; timeout? | |
839 return ; YES - abort, no usable address available | |
840 | |
841 ; remap address from network byte format (big endian) to host format (little-endian) | |
842 movf ext_flash_length_counter+0,W | |
843 movff ext_flash_length_counter+2,ext_flash_length_counter+0 | |
844 movwf ext_flash_length_counter+2 | |
845 | |
846 return ; done, complete start address available | |
847 | |
848 | |
849 ;----------------------------------------------------------------------------- | |
850 ; Read an Option Value | |
851 ; | |
852 comm_read_option: | |
853 SERIAL_LC_SEND 0x72 ; acknowledge command | |
854 SERIAL_CC_RECEIVE lo ; (try to) receive option index | |
855 btfsc rs232_rx_timeout ; received option index? | |
856 bra comm_command_loop ; NO - abort, back to command loop | |
857 | |
858 ; option index 0x00 - 0x0F: unused | |
859 movlw 0x0F ; last option index of the unused range | |
860 cpfsgt lo ; received option index > end of unused range ? | |
861 bra comm_command_error ; NO - abort, back to command loop | |
862 | |
863 ; option index 0x10 - 0x19: gases & diluents | |
864 movlw 0x19 ; last option index for gases / diluents | |
865 cpfsgt lo ; received option index > end of gas/dil range ? | |
866 bra comm_read_gas_dil ; NO - process gas/dil read | |
867 | |
868 ; option index 0x1A - 0x1E: setpoints | |
869 movlw 0x1E ; last option index for setpoint | |
870 cpfsgt lo ; received option index > end of setpoint range ? | |
871 bra comm_read_sp ; NO - process setpoint read | |
872 | |
873 ; option index = 0x49 - special handling button polarity | |
874 movf lo,W ; copy option index to WREG | |
875 iorlw 0x49 ; received option index for button polarity ? | |
876 bz comm_read_button_polarity ; YES - process button polarity read | |
877 | |
878 ; option index 0x1F - 0xFF: options managed by option-table | |
879 call option_read_serial ; try to find the option and read its value | |
880 tstfsz WREG ; option found? | |
881 bra comm_read_setting_fail ; NO - send dummy value | |
882 SERIAL_CC_SEND hi ; YES - send read value | |
883 bra comm_command_loop ; - done, back to command loop | |
884 | |
885 comm_read_setting_fail: | |
886 SERIAL_LC_SEND 0x00 ; send a dummy value | |
887 bra comm_command_error ; back to command loop with failure message | |
888 | |
889 | |
890 ;----------------------------------------------------------------------------- | |
891 ; Write an Option Value | |
892 ; | |
893 comm_write_option: | |
894 SERIAL_LC_SEND 0x77 ; acknowledge command | |
895 SERIAL_CC_RECEIVE lo ; (try to) receive option index | |
896 btfsc rs232_rx_timeout ; got a byte? | |
897 bra comm_command_timeout ; NO - abort, back to command loop | |
898 | |
899 ; option index 0x00 - 0x0F: unused | |
900 movlw 0x0F ; last option index of the unused range | |
901 cpfsgt lo ; received option index > end of unused range ? | |
902 bra comm_write_unused ; NO - but need to consume the option value | |
903 | |
904 ; option index 0x10 - 0x19: gases & diluents | |
905 movlw 0x19 ; last option index for gases / diluents | |
906 cpfsgt lo ; received option index > end of gas/dil range ? | |
907 bra comm_write_gas_dil ; NO - process gas/dil write | |
908 | |
909 ; option index 0x1A - 0x1E: setpoints | |
910 movlw 0x1E ; last option index for setpoint | |
911 cpfsgt lo ; received option index > end of setpoint range ? | |
912 bra comm_write_sp ; NO - process setpoint write | |
913 | |
914 ; option index = 0x49 - special handling button polarity | |
915 movf lo,W ; copy option index to WREG | |
916 iorlw 0x49 ; received option index for button polarity ? | |
917 bz comm_write_button_polarity ; YES - process button polarity write | |
918 | |
919 ; option index 0x1F - 0xFF: options managed by option-table | |
920 SERIAL_CC_RECEIVE hi ; (try to) receive option value | |
921 btfsc rs232_rx_timeout ; got a byte? | |
922 bra comm_command_timeout ; NO - abort | |
923 call option_write_serial ; YES - try to find the option and write new value | |
924 tstfsz WREG ; - option found and new value valid ? | |
925 bra comm_command_error ; NO - back to command loop with failure message | |
926 bra comm_command_loop ; YES - done, back to command loop | |
927 | |
928 comm_write_unused: | |
929 SERIAL_CC_RECEIVE WREG ; consume unused option value | |
930 bra comm_command_error ; done, back to command loop | |
931 | |
932 | |
933 ;----------------------------------------------------------------------------- | |
934 ; Read button polarity | |
935 ; | |
936 comm_read_button_polarity: | |
937 SERIAL_CC_SEND button_polarity ; send current button polarity setting | |
938 bra comm_command_loop ; done, back to command loop | |
939 | |
940 | |
941 ;----------------------------------------------------------------------------- | |
942 ; Write button polarity | |
943 ; | |
944 comm_write_button_polarity: | |
945 SERIAL_CC_RECEIVE hi ; (try to) receive configuration value | |
946 btfsc rs232_rx_timeout ; got configuration value? | |
947 bra comm_command_timeout ; NO - abort, back to command loop | |
948 movff hi,button_polarity ; YES - store button polarity in memory and EEPROM | |
949 EEPROM_CC_WRITE button_polarity,eeprom_button_polarity | |
950 bra comm_command_loop ; - done, back to command loop | |
951 | |
952 | |
953 ;----------------------------------------------------------------------------- | |
954 ; Read a gas/diluent dataset | |
955 ; | |
604 | 956 ; Memory map is as follows: |
957 ; ------------------------- | |
958 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | |
959 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | |
960 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | |
961 ; opt_dil_He_ratio res 5 ; He ratios of diluents | |
962 ; opt_gas_type res 5 ; OC/bailout gas type | |
963 ; opt_dil_type res 5 ; dil type | |
964 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | |
965 ; opt_dil_change res 5 ; change depths for diluents | |
631 | 966 ; |
604 | 967 comm_read_gas_dil: |
968 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays | |
631 | 969 movlw 0x10 ; compute gas index from option index... |
970 subwf lo,W ; ...making WREG point to O2 ratio | |
971 SERIAL_CC_SEND PLUSW0 ; send O2 ratio | |
972 addlw .10 ; increment WREG by 10 to point to He ratio | |
973 SERIAL_CC_SEND PLUSW0 ; send He ratio | |
974 addlw .10 ; increment WREG by 10 to point to gas/diluent type | |
975 SERIAL_CC_SEND PLUSW0 ; send gas/diluent type | |
976 addlw .10 ; increment WREG by 10 to point to change depth | |
977 SERIAL_CC_SEND PLUSW0 ; send change depth | |
978 bra comm_command_loop ; done, back to command loop | |
110 | 979 |
79
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
980 |
631 | 981 ; ---------------------------------------------------------------------------- |
982 ; Write a gas/diluent dataset | |
983 ; | |
604 | 984 ; Memory map is as follows: |
985 ; ------------------------- | |
986 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | |
987 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | |
988 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | |
989 ; opt_dil_He_ratio res 5 ; He ratios of diluents | |
990 ; opt_gas_type res 5 ; OC/bailout gas type | |
991 ; opt_dil_type res 5 ; dil type | |
992 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | |
993 ; opt_dil_change res 5 ; change depths for diluents | |
631 | 994 ; |
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 | |
80 | 999 |
631 | 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 | |
604 | 1049 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays |
631 | 1050 movlw 0x10 ; compute gas index from option index... |
1051 subwf lo,W ; ...making WREG point to O2 ratio | |
1052 movff hi,PLUSW0 ; set O2 ratio | |
1053 addlw .10 ; increment WREG by 10 to point to He ratio | |
1054 movff up,PLUSW0 ; set He ratio | |
1055 addlw .10 ; increment WREG by 10 to point to gas/dil type | |
1056 movff ex,PLUSW0 ; set gas/dil type | |
1057 addlw .10 ; increment WREG by 10 to point to change depth | |
1058 movff ul,PLUSW0 ; set change depth | |
1059 | |
1060 bra comm_command_loop ; done, back to command loop | |
80 | 1061 |
604 | 1062 |
631 | 1063 ;----------------------------------------------------------------------------- |
1064 ; Read a setpoint dataset | |
1065 ; | |
604 | 1066 ; Memory map is as follows: |
1067 ; ------------------------- | |
623 | 1068 ; opt_setpoint_cbar res 5 ; setpoints in cbar |
1069 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter | |
631 | 1070 ; |
1071 comm_read_sp: | |
623 | 1072 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values |
631 | 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 ; | |
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 | |
1107 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values | |
1108 movlw 0x1A ; compute SP index from option index... | |
1109 subwf lo,W ; ...making WREG point to cbar value | |
1110 movff hi,PLUSW0 ; set cbar value | |
1111 addlw .5 ; increment WREG by 5 to point to change depth | |
1112 movff up,PLUSW0 ; set change depth | |
1113 | |
1114 bra comm_command_loop ; done, back to command loop | |
80 | 1115 |
79
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
1116 ;----------------------------------------------------------------------------- |
0fc8113ddf6d
new command in download mode: "r" - read setting
mh@mh-THINK.localdomain
parents:
69
diff
changeset
|
1117 |
582 | 1118 END |