Mercurial > public > hwos_code
comparison src/comm.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 2737ddc643bb |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File comm.asm combined next generation V3.08.8 | 3 ; File comm.asm * combined next generation V3.09.5 |
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 ;============================================================================= |
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" | 26 #include "i2c.inc" |
27 #include "logbook.inc" | 27 #include "logbook.inc" |
28 #include "colorschemes.inc" | |
28 | 29 |
29 | 30 |
30 extern restart | 31 extern restart |
31 extern option_reset_all | 32 extern option_reset_all |
32 extern option_check_and_store_all | 33 extern option_check_and_store_all |
33 extern option_read_serial | 34 extern option_read_serial |
34 extern option_write_serial | 35 extern option_write_serial |
35 extern gaslist_cleanup_list | 36 extern gaslist_cleanup_list |
36 extern eeprom_deco_data_write | 37 extern eeprom_deco_data_write |
38 extern eeprom_memorize_fw_checksum | |
37 | 39 |
38 | 40 |
39 ; timeouts | 41 ; timeouts |
40 #DEFINE timeout_comm_pre_mode .240 ; [sec] timeout before communication is established | 42 #DEFINE timeout_comm_pre_mode .240 ; [sec] timeout before communication is established |
41 #DEFINE timeout_service_mode .120 ; [sec] timeout when communication is established | 43 #DEFINE timeout_service_mode .120 ; [sec] timeout when communication is established |
56 #DEFINE comm_status2_column comm_status1_column | 58 #DEFINE comm_status2_column comm_status1_column |
57 #DEFINE comm_status3_row .130 | 59 #DEFINE comm_status3_row .130 |
58 #DEFINE comm_status3_column comm_status1_column | 60 #DEFINE comm_status3_column comm_status1_column |
59 #DEFINE comm_status4_row .160 | 61 #DEFINE comm_status4_row .160 |
60 #DEFINE comm_status4_column comm_status1_column | 62 #DEFINE comm_status4_column comm_status1_column |
63 #DEFINE comm_status5_row .190 | |
64 #DEFINE comm_status5_column comm_status1_column | |
65 | |
61 | 66 |
62 ; positioning of COMM mode warning icon | 67 ; positioning of COMM mode warning icon |
63 #DEFINE comm_warning_row .160 | 68 #DEFINE comm_warning_row .160 |
64 #DEFINE comm_warning_column .65 | 69 #DEFINE comm_warning_column .65 |
65 | 70 |
66 | 71 |
67 ;#DEFINE testloop_avail ; uncomment if testloop code is available | 72 ;#DEFINE testloop_avail ; uncomment if testloop code is available |
68 | 73 |
69 | 74 ;============================================================================= |
70 comm CODE | 75 comm CODE |
71 | |
72 ;============================================================================= | 76 ;============================================================================= |
73 | 77 |
78 ;----------------------------------------------------------------------------- | |
79 ; Entry Point for Comm Mode / USB | |
80 ; | |
74 global comm_mode_usb | 81 global comm_mode_usb |
75 comm_mode_usb: ; entry point for comm mode via USB | 82 comm_mode_usb: ; entry point for comm mode via USB |
76 WAITMS d'1' ; wait 1 ms | 83 WAITMS d'1' ; wait 1 ms |
77 btfss vusb_in ; USB still plugged in? | 84 btfss vusb_in ; USB still plugged in? |
78 return ; NO - it was only a glitch, abort | 85 return ; NO - it was only a glitch, abort |
80 btfss vusb_in ; - USB still plugged in? | 87 btfss vusb_in ; - USB still plugged in? |
81 return ; NO - it was only a glitch, abort | 88 return ; NO - it was only a glitch, abort |
82 bsf aux_flag ; YES - remember to show USB title | 89 bsf aux_flag ; YES - remember to show USB title |
83 bra comm_mode_common ; - continue with common part | 90 bra comm_mode_common ; - continue with common part |
84 | 91 |
85 global comm_mode_ble | 92 |
86 comm_mode_ble: ; entry point for comm mode via BLE | 93 ;----------------------------------------------------------------------------- |
94 ; Entry Point for Comm Mode / BT | |
95 ; | |
96 global comm_mode_bt | |
97 comm_mode_bt: ; entry point for comm mode via BT | |
87 bcf aux_flag ; remember to show BLE title | 98 bcf aux_flag ; remember to show BLE title |
88 ;bra comm_mode_common ; continue with common part | 99 ;bra comm_mode_common ; continue with common part |
89 | 100 |
101 | |
102 ;----------------------------------------------------------------------------- | |
103 ; Common Part of Comm Mode Entry | |
104 ; | |
90 comm_mode_common: | 105 comm_mode_common: |
91 clrf STKPTR ; reset addresses stack | 106 clrf STKPTR ; reset addresses stack |
92 call TFT_ClearScreen ; clear screen | 107 call TFT_ClearScreen ; clear screen |
93 WIN_COLOR color_greenish ; set color | 108 FONT_COLOR color_greenish ; set color |
94 | 109 |
95 btfss aux_flag ; shall show USB title? | 110 btfss aux_flag ; shall show USB title? |
96 bra comm_mode_common_1 ; NO - show BLE title | 111 bra comm_mode_common_bt ; NO - show BT title |
97 WIN_SMALL comm_title_column_usb, comm_title_row ; YES - set USB title position | 112 ;bra comm_mode_common_usb ; YES - show USB title |
98 STRCPY_TEXT_PRINT tUsbTitle ; - print USB title text | 113 |
99 bra comm_mode_common_2 ; - continue with common part | 114 comm_mode_common_usb: |
100 | 115 WIN_SMALL comm_title_column_usb, comm_title_row ; set USB title position |
101 comm_mode_common_1: | 116 STRCPY_TEXT_PRINT tUsbTitle ; print USB title text |
102 WIN_SMALL comm_title_column_ble, comm_title_row ; set BLE title position | 117 bra comm_mode_common_logo ; continue with logo |
103 STRCPY_TEXT_PRINT tBleTitle ; print BLE title text | 118 |
104 ;bra comm_mode_common_2 ; continue with common part | 119 comm_mode_common_bt: |
105 | 120 WIN_SMALL comm_title_column_ble, comm_title_row ; set BT title position |
106 comm_mode_common_2: | 121 STRCPY_TEXT_PRINT tBleTitle ; print BT title text |
107 call TFT_standard_color ; set standard color | 122 ;bra comm_mode_common_logo ; continue with logo |
123 | |
124 comm_mode_common_logo: | |
108 WIN_TOP .10 ; set position of USB/BLE logo, row | 125 WIN_TOP .10 ; set position of USB/BLE logo, row |
109 WIN_LEFT .1 ; set position of USB/BLE logo, column | 126 WIN_LEFT .1 ; set position of USB/BLE logo, column |
110 btfsc battery_gauge_available ; "+" bootloader ? | 127 btfss battery_gauge_available ; "+" bootloader ? |
111 bra comm_mode_common_3 ; NO - show logo type 1 | 128 bra comm_mode_common_logo2 ; YES - show logo type 2 |
112 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_2 ; YES - show USB/BLE logo 2 | 129 ;bra comm_mode_common_logo1 ; NO - show logo type 1 |
113 bra comm_mode_common_4 ; - continue with common part | 130 |
114 | 131 comm_mode_common_logo1: |
115 comm_mode_common_3: | 132 TFT_WRITE_PROM_IMAGE_BY_ADDR comm_logo_1 ; show USB/BT logo |
116 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_1 ; show logo type 1 | 133 bra comm_mode_common_start ; continue with starting message |
117 ;bra comm_mode_common_4 ; continue with common part | 134 |
118 | 135 comm_mode_common_logo2: |
119 comm_mode_common_4: | 136 TFT_WRITE_PROM_IMAGE_BY_ADDR comm_logo_2 ; show BT logo / OSTC+ |
120 WIN_SMALL comm_status1_column,comm_status1_row ; print status message "starting..." | 137 ;bra comm_mode_common_start ; continue with starting message |
121 STRCPY_TEXT_PRINT tUsbStarting ; ... | 138 |
139 comm_mode_common_start: | |
140 WIN_SMALL comm_status1_column,comm_status1_row ; set position | |
141 FONT_COLOR_MEMO ; set standard color | |
142 STRCPY_TEXT_PRINT tUsbStarting ; print status message "starting..." | |
122 | 143 |
123 WIN_TINY .40,.240-.16 ; set output position to bottom line | 144 WIN_TINY .40,.240-.16 ; set output position to bottom line |
124 call TFT_show_serial_and_firmware ; show serial number and firmware version | 145 call TFT_print_serial_and_firmware ; show serial number and firmware version |
125 | 146 |
126 IFDEF _screendump | 147 IFDEF _screendump |
127 bcf screen_dump_avail ; disable screen dump function | 148 bcf screen_dump_avail ; disable screen dump function |
128 ENDIF | 149 ENDIF |
129 | 150 |
130 bcf switch_right ; clear potential left-over right button event | 151 bcf switch_right ; clear potential left-over right button event |
131 call enable_rs232 ; enable serial comm, also sets CPU to normal speed | 152 call enable_rs232 ; enable serial comm, also sets CPU to normal speed |
132 | 153 |
133 WIN_SMALL comm_status1_column+.80,comm_status1_row ; print (adding to status message) "done..." | 154 WIN_SMALL comm_status1_column+.80,comm_status1_row ; set position after starting message |
134 STRCPY_TEXT_PRINT tUsbStartDone ; ... | 155 FONT_COLOR_MEMO ; set standard color |
156 STRCPY_TEXT_PRINT tUsbStartDone ; print (adding to status message) "done..." | |
135 | 157 |
136 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet | 158 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet |
137 movwf comm_timeout_timer ; initialize timeout counter | 159 movwf comm_timeout_timer ; initialize timeout counter |
138 | 160 ;bra comm_mode_selection_loop ; continue with mode selection loop |
161 | |
162 | |
163 ;----------------------------------------------------------------------------- | |
164 ; Mode Selection Loop: Download Mode or Service Mode | |
165 ; | |
139 comm_mode_selection_loop: | 166 comm_mode_selection_loop: |
140 bcf trigger_full_second ; clear 'one second elapsed' flag | 167 bcf trigger_full_second ; clear 'one second elapsed' flag |
141 bcf LEDr ; switch off red LED / power down TR co-processor | 168 bcf LEDr ; switch off red LED / power down TR co-processor |
142 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? | 169 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero? |
143 bra comm_service_exit ; YES - timeout, exit comm mode | 170 bra comm_service_exit ; YES - timeout, exit comm mode |
149 movf lo,W ; NO - copy received byte to lo | 176 movf lo,W ; NO - copy received byte to lo |
150 xorlw 0xAA ; - service mode start byte received? | 177 xorlw 0xAA ; - service mode start byte received? |
151 bz comm_service_mode_check ; YES - check if correct key will be send | 178 bz comm_service_mode_check ; YES - check if correct key will be send |
152 movf lo,W ; NO - copy received byte to lo again | 179 movf lo,W ; NO - copy received byte to lo again |
153 xorlw 0xBB ; - download mode start byte received? | 180 xorlw 0xBB ; - download mode start byte received? |
154 bz comm_download_mode ; YES - enter command loop | 181 bz comm_download_mode ; YES - enter command loop |
155 ;bra comm_mode_selection_loop_2 ; NO - check for comm mode termination | 182 ;bra comm_mode_selection_loop_2 ; NO - check for comm mode termination |
156 comm_mode_selection_loop_2: | 183 comm_mode_selection_loop_2: |
157 btfsc ble_available ; BLE available? | 184 btfsc ble_available ; BT available? |
158 bra comm_mode_selection_loop_3 ; YES - skip USB check check (required for very old OSTC sport) | 185 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? | 186 btfss vusb_in ; NO - USB plugged in? |
160 bra comm_service_exit_nousb_delay ; NO - disconnected, check for vusb_in glitch | 187 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 | 188 ;bra comm_mode_selection_loop_3 ; YES - check for exit button or continue looping |
162 comm_mode_selection_loop_3: | 189 comm_mode_selection_loop_3: |
166 bra comm_mode_selection_loop ; YES - loop with clocking down timeout counter | 193 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 | 194 bra comm_mode_selection_loop_1 ; NO - loop without clocking down timeout counter |
168 | 195 |
169 | 196 |
170 ;----------------------------------------------------------------------------- | 197 ;----------------------------------------------------------------------------- |
171 ; Received start byte for service mode, await service key | 198 ; Check Service Mode Pass-Key and notify Service Mode on Success |
172 ; | 199 ; |
173 comm_service_mode_check: | 200 comm_service_mode_check: |
174 | |
175 SERIAL_LC_SEND 0x4B ; request peer to send service key | 201 SERIAL_LC_SEND 0x4B ; request peer to send service key |
176 | 202 |
177 ; receive a 3 byte service key transmitted in big-endian, echo each byte | 203 ; receive a 3 byte service key transmitted in big-endian, echo each byte |
178 | 204 |
179 clrf WREG ; clear WREG | 205 clrf WREG ; clear WREG |
195 | 221 |
196 ; check for correct service key | 222 ; check for correct service key |
197 tstfsz WREG ; received expected service key? | 223 tstfsz WREG ; received expected service key? |
198 bra comm_mode_selection_loop ; NO - back to mode selection loop | 224 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 | 225 WIN_SMALL comm_status2_column, comm_status2_row ; YES - print service mode enabled message |
226 FONT_COLOR_MEMO ; - set standard color | |
200 STRCPY_TEXT_PRINT tUsbServiceMode ; - ... | 227 STRCPY_TEXT_PRINT tUsbServiceMode ; - ... |
201 bsf comm_service_mode ; - enable service mode commands | 228 bsf comm_service_mode ; - enable service mode commands |
202 bra comm_command_loop ; - enter command loop | 229 bra comm_command_loop ; - enter command loop |
203 | 230 |
204 | 231 |
205 ;----------------------------------------------------------------------------- | 232 ;----------------------------------------------------------------------------- |
206 ; Received start byte for download mode | 233 ; Notify RX Timeout occurred |
234 ; | |
235 comm_command_timeout: | |
236 WIN_SMALL comm_status4_column, comm_status4_row ; select font and output position | |
237 FONT_COLOR_WARNING ; set warning color | |
238 STRCPY_PRINT "Data Rx Timeout" ; print failure message | |
239 FONT_COLOR_MEMO ; back to standard color | |
240 bra comm_drain_rx_queue ; continue with draining the RX queue | |
241 | |
242 | |
243 ;----------------------------------------------------------------------------- | |
244 ; Notify Error in Parameters | |
245 ; | |
246 comm_command_error: | |
247 WIN_SMALL comm_status4_column, comm_status4_row ; select font and output position | |
248 FONT_COLOR_WARNING ; set warning color | |
249 STRCPY_PRINT "Parameter Error" ; print failure message | |
250 FONT_COLOR_MEMO ; back to standard color | |
251 ;bra comm_drain_rx_queue ; continue with draining the RX queue | |
252 | |
253 | |
254 ;----------------------------------------------------------------------------- | |
255 ; Drain the RX Queue until next Timeout | |
256 ; | |
257 comm_drain_rx_queue: | |
258 bsf INTCON,GIE ; re-enable all interrupts | |
259 comm_drain_rx_queue_loop: | |
260 btfsc switch_right ; right button (abort) pressed? | |
261 bra comm_service_exit ; YES - exit comm mode | |
262 SERIAL_CC_RECEIVE WREG ; NO - (try to) receive one byte | |
263 btfss rs232_rx_timeout ; - got a byte? | |
264 bra comm_drain_rx_queue_loop ; YES - try to drain more bytes | |
265 bra comm_command_loop ; NO - re-enter command loop | |
266 | |
267 | |
268 ;----------------------------------------------------------------------------- | |
269 ; Debug Code - show Number of Bytes received | |
270 ; | |
271 IFDEF _comm_debug | |
272 comm_command_debug: | |
273 WIN_SMALL comm_status5_column, comm_status5_row ; select font and output position | |
274 FONT_COLOR_MEMO ; set standard color | |
275 STRCPY "last RX: " ; print label | |
276 output_9999 ; print number of bytes received (0-9999) | |
277 STRCAT_PRINT " Byte" ; finalize output | |
278 bra comm_command_loop ; re-enter command loop | |
279 ENDIF | |
280 | |
281 | |
282 ;----------------------------------------------------------------------------- | |
283 ; Notify Download Mode selected | |
207 ; | 284 ; |
208 comm_download_mode: | 285 comm_download_mode: |
209 SERIAL_LC_SEND 0xBB ; inform peer download mode will be started | 286 SERIAL_LC_SEND 0xBB ; inform peer download mode will be started |
210 | 287 |
211 WIN_SMALL comm_status2_column, comm_status2_row ; print download mode enabled message | 288 WIN_SMALL comm_status2_column, comm_status2_row ; set position |
212 STRCPY_TEXT_PRINT tUsbDownloadMode ; ... | 289 FONT_COLOR_MEMO ; set standard color |
290 STRCPY_TEXT_PRINT tUsbDownloadMode ; print download mode enabled message | |
213 bcf comm_service_mode ; disable service mode commands | 291 bcf comm_service_mode ; disable service mode commands |
214 bra comm_command_loop ; enter command loop | 292 ;bra comm_command_loop ; enter command loop |
215 | 293 |
216 | 294 |
217 ;----------------------------------------------------------------------------- | 295 ;----------------------------------------------------------------------------- |
218 ; Notify RX timeout occurred | 296 ; Command Loop: await, decode and execute Commands |
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 ; | 297 ; |
244 comm_command_loop: | 298 comm_command_loop: |
245 ; (re-)initialize | |
246 bsf INTCON,GIE ; re-enable all interrupts | 299 bsf INTCON,GIE ; re-enable all interrupts |
300 | |
301 ; restart command timeout | |
247 movlw timeout_service_mode ; get timeout value | 302 movlw timeout_service_mode ; get timeout value |
248 movwf comm_timeout_timer ; reload timeout timer | 303 movwf comm_timeout_timer ; reload timeout timer |
249 | 304 |
250 ; request peer to send a command | 305 ; request peer to send a command |
251 movlw 0x4D ; default request code is 0x4D for download mode active | 306 movlw 0x4D ; default request code is 0x4D for download mode active |
258 SERIAL_CC_RECEIVE lo ; (try to) receive a command byte | 313 SERIAL_CC_RECEIVE lo ; (try to) receive a command byte |
259 btfss rs232_rx_timeout ; timeout? | 314 btfss rs232_rx_timeout ; timeout? |
260 bra comm_command_decode ; NO - decode and execute the command | 315 bra comm_command_decode ; NO - decode and execute the command |
261 btfsc comm_service_mode ; YES - service mode enabled? | 316 btfsc comm_service_mode ; YES - service mode enabled? |
262 btg LEDr ; YES - blink in service mode | 317 btg LEDr ; YES - blink in service mode |
263 btfsc ble_available ; - BLE available? | 318 btfsc ble_available ; - BT available? |
264 bra comm_command_loop_wait_1 ; YES - skip USB check (required for very old OSTC sport) | 319 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? | 320 btfss vusb_in ; NO - USB still plugged in? |
266 bra comm_service_exit_nousb ; NO - disconnected -> exit comm mode | 321 bra comm_service_exit_nousb ; NO - disconnected -> exit comm mode |
322 ;bra comm_command_loop_wait_1 ; YES - proceed | |
323 | |
267 comm_command_loop_wait_1: | 324 comm_command_loop_wait_1: |
268 btfsc switch_right ; right button (abort) pressed? | 325 btfsc switch_right ; right button (abort) pressed? |
269 bra comm_service_exit ; YES - exit comm mode | 326 bra comm_service_exit ; YES - exit comm mode |
270 btfss trigger_full_second ; NO - did 1 second elapsed meanwhile? | 327 btfss trigger_full_second ; NO - did 1 second elapsed meanwhile? |
271 bra comm_command_loop_wait ; NO - loop | 328 bra comm_command_loop_wait ; NO - loop |
274 bcf trigger_full_second ; NO - clear 'one second elapsed' flag | 331 bcf trigger_full_second ; NO - clear 'one second elapsed' flag |
275 bra comm_command_loop_wait ; - loop | 332 bra comm_command_loop_wait ; - loop |
276 | 333 |
277 | 334 |
278 ;----------------------------------------------------------------------------- | 335 ;----------------------------------------------------------------------------- |
279 ; Macro for easier writing of command decoding rules | 336 ; Macro for easier writing of Command Decoding Rules |
280 ; | 337 ; |
281 command_decode macro command_id,command_function | 338 command_decode macro command_id,command_function |
282 movf lo,W ; copy received command to WREG | 339 movf lo,W ; copy received command to WREG |
283 xorlw command_id ; exclusive-or with command ID | 340 xorlw command_id ; exclusive-or with command ID |
284 btfsc STATUS,Z ; received command = command ID ? | 341 btfsc STATUS,Z ; received command = command ID ? |
285 goto command_function ; YES - execute command | 342 goto command_function ; YES - execute command |
286 endm | 343 endm |
287 | 344 |
288 ;----------------------------------------------------------------------------- | 345 |
289 ; Decode and execute a command | 346 ;----------------------------------------------------------------------------- |
347 ; Decode and execute a Command | |
290 ; | 348 ; |
291 comm_command_decode: | 349 comm_command_decode: |
292 bcf LEDr ; switch off red led | 350 bcf LEDr ; switch off red led |
293 | 351 |
294 ; decode and execute standard commands | 352 ; decode and execute standard commands |
313 bra comm_command_loop ; NO - ignore unrecognized command, back to command loop | 371 bra comm_command_loop ; NO - ignore unrecognized command, back to command loop |
314 | 372 |
315 ; decode and execute additional service mode commands | 373 ; decode and execute additional service mode commands |
316 command_decode 0x23,comm_reset_battery_gauge ; # reset the battery gauge registers | 374 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 | 375 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 | 376 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... | 377 command_decode 0x40,comm_erase_single_4kb ; @ erase a single 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... | 378 command_decode 0x42,comm_erase_range_4kb ; 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 | 379 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 | 380 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 | 381 command_decode 0x50,comm_firmware_update ; P initiate firmware update |
324 command_decode 0xC1,comm_cold_start ; start low-level bootloader | 382 command_decode 0xC1,comm_cold_start ; start low-level bootloader |
325 IFDEF testloop_avail | 383 IFDEF testloop_avail |
328 | 386 |
329 bra comm_command_loop ; ignore unrecognized command, back to command loop | 387 bra comm_command_loop ; ignore unrecognized command, back to command loop |
330 | 388 |
331 | 389 |
332 ;----------------------------------------------------------------------------- | 390 ;----------------------------------------------------------------------------- |
333 ; Exit comm mode | 391 ; Exit Comm Mode |
334 ; | 392 ; |
335 comm_service_exit: | 393 comm_service_exit: |
336 WIN_SMALL comm_status3_column, comm_status3_row ; print "Exited" message | 394 WIN_SMALL comm_status3_column, comm_status3_row ; print "Exited" message |
395 FONT_COLOR_MEMO ; set standard color | |
337 STRCPY_TEXT_PRINT tUsbExit ; ... | 396 STRCPY_TEXT_PRINT tUsbExit ; ... |
338 bra comm_service_exit_common ; acknowledge exit command and restart | 397 bra comm_service_exit_common ; acknowledge exit command and restart |
339 | 398 |
340 comm_service_exit_nousb_delay: | 399 comm_service_exit_nousb_delay: |
341 WAITMS d'200' ; wait 200 ms | 400 WAITMS d'200' ; wait 200 ms |
343 bra comm_mode_selection_loop_3 ; YES - was just a glitch, continue | 402 bra comm_mode_selection_loop_3 ; YES - was just a glitch, continue |
344 ;bra comm_service_exit_nousb ; NO - proceed exiting | 403 ;bra comm_service_exit_nousb ; NO - proceed exiting |
345 | 404 |
346 comm_service_exit_nousb: | 405 comm_service_exit_nousb: |
347 WIN_SMALL comm_status3_column, comm_status3_row ; print "Port closed" message | 406 WIN_SMALL comm_status3_column, comm_status3_row ; print "Port closed" message |
407 FONT_COLOR_MEMO ; set standard color | |
348 STRCPY_TEXT_PRINT tUsbClosed ; ... | 408 STRCPY_TEXT_PRINT tUsbClosed ; ... |
349 ;bra comm_service_exit_common ; proceed exiting | 409 ;bra comm_service_exit_common ; proceed exiting |
350 | 410 |
351 comm_service_exit_common: | 411 comm_service_exit_common: |
352 SERIAL_LC_SEND 0xFF ; acknowledge exit command | 412 SERIAL_LC_SEND 0xFF ; acknowledge exit command |
353 call wait_1s ; wait <= 1 second | 413 WAITS .1 ; wait 1 second to give the serial I/F time |
354 call wait_1s ; wait 1 second | 414 ; to send the 0xFF before it gets shut down |
355 call disable_rs232 ; shut down comm port | 415 call disable_rs232 ; shut down comm port |
356 bcf LEDr ; switch off red LED | 416 bcf LEDr ; switch off red LED |
417 WAITS .1 ; wait 1 second for BT module supply to drain | |
357 goto restart ; restart | 418 goto restart ; restart |
358 | 419 |
359 | 420 |
360 ;----------------------------------------------------------------------------- | 421 ;----------------------------------------------------------------------------- |
361 ; Set Real-Time-Clock | 422 ; Set Real-Time-Clock |
362 ; | 423 ; |
363 comm_set_time: | 424 comm_set_time: |
425 bcf INTCON,GIE ; disable all interrupts | |
364 SERIAL_LC_SEND 0x62 ; acknowledge command | 426 SERIAL_LC_SEND 0x62 ; acknowledge command |
365 | 427 SERIAL_RR_RECEIVE mpr,.6 ; (try to) receive 6 bytes: hour, minute, second, month, day, year |
366 ; receive 6 bytes coming in sequence: hour, minute, second, month, day, year | 428 bsf INTCON,GIE ; re-enable all interrupts |
367 SERIAL_RR_RECEIVE_RAM mpr,.6 | 429 |
368 | 430 btfsc rs232_rx_timeout ; got all 6 bytes? |
369 ; got all 6 bytes? | 431 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
370 btfsc rs232_rx_timeout ; timeout? | 432 |
371 bra comm_command_timeout ; YES - abort, back to command loop | 433 movff mpr+0,rtc_latched_hour ; map the received bytes onto the rtc_latched variables |
372 | 434 movff mpr+1,rtc_latched_mins ; ... |
373 ; map the received bytes onto the rtc_latched variables | 435 movff mpr+2,rtc_latched_secs ; ... |
374 movff mpr+0,rtc_latched_hour | 436 movff mpr+3,rtc_latched_month ; ... |
375 movff mpr+1,rtc_latched_mins | 437 movff mpr+4,rtc_latched_day ; ... |
376 movff mpr+2,rtc_latched_secs | 438 movff mpr+5,rtc_latched_year ; ... |
377 movff mpr+3,rtc_latched_month | |
378 movff mpr+4,rtc_latched_day | |
379 movff mpr+5,rtc_latched_year | |
380 | |
381 ; set the RTC | |
382 call rtc_set_rtc ; write time and date to RTC module | 439 call rtc_set_rtc ; write time and date to RTC module |
383 | 440 bra comm_command_loop ; done, back to command loop |
384 bra comm_command_loop ; done, back to command loop | 441 |
385 | 442 |
386 | 443 ;----------------------------------------------------------------------------- |
387 ;----------------------------------------------------------------------------- | 444 ; Write a 15 char Text to the OSTC Display |
388 ; Write a 15 char text to the OSTC display | |
389 ; | 445 ; |
390 comm_show_text: | 446 comm_show_text: |
391 ; set font and output position of the text to show | 447 ; set font and output position (needs to be done before SERIAL_RR_RECEIVE) |
392 WIN_SMALL comm_string_column, comm_string_row | 448 WIN_SMALL comm_string_column, comm_string_row |
393 | 449 FONT_COLOR_MEMO ; set standard color |
450 | |
451 bcf INTCON,GIE ; disable all interrupts | |
394 SERIAL_LC_SEND 0x6E ; acknowledge command | 452 SERIAL_LC_SEND 0x6E ; acknowledge command |
395 | 453 SERIAL_RR_RECEIVE buffer,.16 ; (try to) receive 16 chars into the string buffer |
396 SERIAL_RR_RECEIVE_RAM buffer,.16 ; (try to) receive 16 chars and write them to 'buffer' using FSR2 | 454 bsf INTCON,GIE ; re-enable all interrupts |
397 STRCAT_PRINT "" ; dump whatever was received to the screen | 455 |
398 | 456 movlw .15 ; set maximum text length |
399 bra comm_command_loop ; done, back to command loop | 457 call TFT_buffer_trim_length ; fill or trim the text to correct length |
400 | 458 PRINT ; print text to screen |
401 | 459 bra comm_command_loop ; done, back to command loop |
402 ;----------------------------------------------------------------------------- | 460 |
403 ; Reply Serial (2 bytes low:high), firmware (major.minor) and custom text | 461 |
462 ;----------------------------------------------------------------------------- | |
463 ; Send Serial (2 bytes low:high), Firmware (major.minor) and Custom Text | |
404 ; | 464 ; |
405 comm_identify: | 465 comm_identify: |
406 SERIAL_LC_SEND 0x69 ; acknowledge command | 466 SERIAL_LC_SEND 0x69 ; acknowledge command |
407 | 467 |
408 ;---- send OSTC serial number | 468 ; send OSTC serial number |
409 call eeprom_serial_number_read ; read OSTC serial number | 469 call eeprom_serial_number_read ; read OSTC serial number |
410 SERIAL_CC_SEND mpr+0 ; send serial number, low byte | 470 SERIAL_CC_SEND mpr+0 ; send serial number, low byte |
411 SERIAL_CC_SEND mpr+1 ; send serial number, high byte | 471 SERIAL_CC_SEND mpr+1 ; send serial number, high byte |
412 | 472 |
413 ;---- send firmware version | 473 ; send firmware version |
414 SERIAL_LC_SEND fw_version_major ; send firmware version, major | 474 SERIAL_LC_SEND fw_version_major ; send firmware version, major |
415 SERIAL_LC_SEND fw_version_minor ; send firmware version, minor | 475 SERIAL_LC_SEND fw_version_minor ; send firmware version, minor |
416 | 476 |
417 ;---- send custom text | 477 ; send custom text |
418 SERIAL_RR_SEND_RAM opt_name,opt_name_length | 478 SERIAL_RR_SEND opt_name,opt_name_length |
419 | 479 |
420 bra comm_command_loop ; done, back to command loop | 480 bra comm_command_loop ; done, back to command loop |
421 | 481 |
422 | 482 |
423 ;----------------------------------------------------------------------------- | 483 ;----------------------------------------------------------------------------- |
424 ; Reply hardware descriptor byte | 484 ; Send short Hardware Descriptor |
425 ; | 485 ; |
426 comm_hardware_descriptor: | 486 comm_hardware_descriptor: |
427 SERIAL_LC_SEND 0x6A ; acknowledge command | 487 SERIAL_LC_SEND 0x6A ; acknowledge command |
428 | 488 rcall comm_helper_hw_descriptor ; send hardware descriptor |
489 bra comm_command_loop ; done, back to command loop | |
490 | |
491 | |
492 ;----------------------------------------------------------------------------- | |
493 ; Helper Function for sending Hardware Descriptor | |
494 ; | |
495 comm_helper_hw_descriptor: | |
429 movf HW_descriptor,W ; get hardware descriptor | 496 movf HW_descriptor,W ; get hardware descriptor |
430 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | 497 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 | 498 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software |
432 SERIAL_CC_SEND WREG ; send modified hardware descriptor | 499 SERIAL_CC_SEND WREG ; send modified hardware descriptor |
433 | 500 return |
434 bra comm_command_loop ; done, back to command loop | 501 |
435 | 502 |
436 | 503 ;----------------------------------------------------------------------------- |
437 ;----------------------------------------------------------------------------- | 504 ; Send detailed Hardware Descriptor |
438 ; Reply detailed hardware descriptor | |
439 ; | 505 ; |
440 comm_feature_and_hardware: | 506 comm_feature_and_hardware: |
441 SERIAL_LC_SEND 0x60 ; acknowledge command | 507 SERIAL_LC_SEND 0x60 ; acknowledge command |
442 | 508 |
443 SERIAL_LC_SEND 0x00 ; send hardware high byte (fixed zero) | 509 SERIAL_LC_SEND 0x00 ; send hardware high byte (fixed zero) |
444 | 510 rcall comm_helper_hw_descriptor ; send hardware descriptor |
445 movf HW_descriptor,W ; get hardware descriptor | 511 SERIAL_LC_SEND 0x00 ; send feature high byte (fixed zero) |
446 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software | 512 SERIAL_LC_SEND 0x00 ; send feature low byte (fixed zero) |
447 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software | |
448 SERIAL_CC_SEND WREG ; send modified hardware low byte | |
449 | |
450 SERIAL_LC_SEND 0x00 ; send feature high byte (fixed zero) | |
451 SERIAL_LC_SEND 0x00 ; send feature low byte (fixed zero) | |
452 | |
453 SERIAL_LC_SEND 0x00 ; send model descriptor byte (fixed zero) | 513 SERIAL_LC_SEND 0x00 ; send model descriptor byte (fixed zero) |
454 | 514 |
455 bra comm_command_loop ; done, back to command loop | 515 bra comm_command_loop ; done, back to command loop |
456 | 516 |
457 | 517 |
458 ;----------------------------------------------------------------------------- | 518 ;----------------------------------------------------------------------------- |
459 | 519 ; Helper Function to retrieve a Header, hide the internal Profile Version, |
520 ; and to check if the Header is empty | |
521 ; | |
522 comm_helper_read_header: | |
523 ; copy header from FLASH into memory | |
524 call log_header_addr_by_index ; compute header start address from index in WREG | |
525 FLASH_RR_READ header_buffer,.256 ; copy from FLASH to header buffer | |
526 | |
527 ; hide internal profile version ID from the outside | |
528 movff header_buffer+index_profile_version,WREG ; get byte at the profile version position | |
529 infsnz WREG,W ; was the byte = 0xFF (i.e. empty header) ? | |
530 return ; YES - leave it as it is (WREG now 0) | |
531 decf WREG,W ; NO - restore the profile version | |
532 andlw b'00111111' ; - keep only the external part | |
533 movff WREG,header_buffer+index_profile_version ; - write back the cleaned byte | |
534 return ; - done (WREG now ext. profile version) | |
535 | |
536 | |
537 ;----------------------------------------------------------------------------- | |
538 ; Send Dive Headers in short or full Format | |
539 ; | |
460 comm_send_headers_short: | 540 comm_send_headers_short: |
461 SERIAL_LC_SEND 0x6D ; acknowledge command | 541 SERIAL_LC_SEND 0x6D ; acknowledge command |
462 | 542 bcf aux_flag ; send short headers |
463 ; send short header (16 bytes/dive) | 543 bra comm_send_headers_common ; continue with common part |
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 | |
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 | 544 |
501 comm_send_headers_full: | 545 comm_send_headers_full: |
502 SERIAL_LC_SEND 0x61 ; acknowledge command | 546 SERIAL_LC_SEND 0x61 ; acknowledge command |
503 | 547 bsf aux_flag ; send full headers |
504 ; send complete headers (256 bytes/dive) | 548 ;bra comm_send_headers_common ; continue with common part |
505 ; index 0: 0x200000 - 0x2000FF | 549 |
506 ; 1: 0x201000 - 0x2010FF | 550 comm_send_headers_common: |
507 ; 2: 0x202000 - 0x2020FF | 551 clrf ex ; start with dive having index 0 |
508 ; ... | 552 |
509 ; 255: 0x2FF000 - 0x2FF0FF | 553 comm_send_headers_loop: |
510 | 554 movf ex,W ; get index into WREG |
511 clrf ex ; start with dive having index 0 | 555 rcall comm_helper_read_header ; get header into header_buffer |
512 comm_send_headers_full_loop: | 556 |
513 movf ex,W ; get index into WREG | 557 btfss aux_flag ; shall send full headers? |
514 call log_header_addr_by_index ; compute header start address from index, result in mpr | 558 bra comm_send_headers_loop_short; NO - send short headers |
515 FLASH_RR_READ mpr,header_buffer,.256 ; get header from FLASH into memory | 559 ;bra comm_send_headers_loop_full ; YES - send full headers |
516 SERIAL_RR_SEND_RAM header_buffer,.256 ; send the header from memory to RS232 | 560 |
517 incfsz ex ; increment index, wrap-around. i.e. all dives done ? | 561 comm_send_headers_loop_full: |
518 bra comm_send_headers_full_loop ; NO - loop | 562 SERIAL_RR_SEND header_buffer,.256 ; send the full header |
519 bra comm_command_loop ; YES - done, back to command loop | 563 bra comm_send_headers_loop_com ; continue with common part |
520 | 564 |
521 | 565 comm_send_headers_loop_short: |
522 ;----------------------------------------------------------------------------- | 566 ; send the fractions of the short header (16 byte/dive) |
523 ; Send one full dive | 567 SERIAL_RR_SEND header_buffer+index_profile_byte_count,.13 |
568 SERIAL_RR_SEND header_buffer+index_total_dives, .2 | |
569 SERIAL_CC_SEND header_buffer+index_profile_version ; .1 | |
570 ;bra comm_send_headers_loop_com ; continue with common part | |
571 | |
572 comm_send_headers_loop_com: | |
573 incfsz ex ; increment index, wrap-around. i.e. all dives done ? | |
574 bra comm_send_headers_loop ; NO - loop | |
575 bra comm_command_loop ; YES - done, back to command loop | |
576 | |
577 | |
578 ;----------------------------------------------------------------------------- | |
579 ; Send one full Dive | |
524 ; | 580 ; |
525 comm_send_dive: | 581 comm_send_dive: |
526 SERIAL_LC_SEND 0x66 ; acknowledge command | 582 SERIAL_LC_SEND 0x66 ; acknowledge command |
527 | 583 |
528 SERIAL_CC_RECEIVE WREG ; (try to) receive the dive index (0-255) | 584 SERIAL_CC_RECEIVE WREG ; (try to) receive the dive index |
529 btfsc rs232_rx_timeout ; got dive index? | 585 btfsc rs232_rx_timeout ; got dive index? |
530 bra comm_command_timeout ; NO - abort, back to command loop | 586 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
531 | 587 |
532 call log_header_addr_by_index ; compute header start address from index, result in mpr | 588 rcall comm_helper_read_header ; read header into header_buffer |
533 FLASH_RR_READ mpr,header_buffer,.256; copy the complete header into the buffer | 589 bz comm_send_dive_exit ; abort if header contains no dive |
534 | 590 |
535 ; get pointers and length of profile data | 591 ; get the start and end address of the profile data |
536 MOVTT header_buffer+index_profile_start_address,ext_flash_address | 592 MOVTT header_buffer+index_profile_start_address,ext_flash_address |
537 MOVTT header_buffer+index_profile_end_address, ext_flash_end_pointer | 593 MOVTT header_buffer+index_profile_end_address, ext_flash_end_pointer |
538 MOVTT header_buffer+index_profile_byte_count, ext_flash_length_counter | 594 |
539 | 595 ; header start code sequence present? |
540 ; check if profile data are available | 596 bcf aux_flag ; default to no profile available |
541 movf ext_flash_address+0,W ; compare low byte of start and end pointer | 597 |
542 cpfseq ext_flash_end_pointer+0 ; equal? | 598 FLASH_CW_READ_0x20 ; get the 1st byte of profile data |
543 bra comm_send_dive1 ; NO - profile data available, continue | 599 xorlw 0xFA ; 1st byte = header start byte? |
544 | 600 bnz comm_send_dive_modify_header; NO - no profile data available |
545 movf ext_flash_address+1,W ; compare high byte of start and end pointer | 601 |
546 cpfseq ext_flash_end_pointer+1 ; equal? | 602 FLASH_CW_READ_0x20 ; get the 2nd byte of profile data |
547 bra comm_send_dive1 ; NO - profile data available, continue | 603 xorlw 0xFA ; 2nd byte = header start byte? |
548 | 604 bnz comm_send_dive_modify_header; NO - no profile data available |
549 movf ext_flash_address+2,W ; compare upper byte of start and end pointer | 605 |
550 cpfseq ext_flash_end_pointer+2 ; equal? | 606 EXT_FLASH_INC_ADDRESS_0x20 .2 ; skip the 3rd and 4th byte (dive number) |
551 bra comm_send_dive1 ; NO - profile data available, continue | 607 |
552 | 608 FLASH_CW_READ_0x20 ; get the 5th byte of profile data |
553 bra comm_command_loop ; start = end -> no profile data available, abort, back to command loop | 609 xorlw 0xFA ; 5th byte = header start byte? |
554 | 610 bnz comm_send_dive_modify_header; NO - no profile data available |
555 comm_send_dive1: | 611 |
556 ; send the header from the buffer | 612 FLASH_CW_READ_0x20 ; get the 6th byte of profile data |
557 SERIAL_RR_SEND_RAM header_buffer,.256 | 613 xorlw 0xFA ; 6th byte = header start byte? |
558 | 614 bnz comm_send_dive_modify_header; NO - no profile data available |
559 ; send the profile directly from the FLASH | 615 |
560 ext_flash_inc_address_0x20 .6 ; skip the first 6 bytes (short header) of the profile data | 616 bsf aux_flag ; memorize profile data available |
561 ext_flash_dec_length .3 ; adopt the length count (short by 3 bytes) | 617 bra comm_send_dive_header ; continue with sending header |
562 ext_flash_dec_length .1 ; decrement length count by 1 so that all bytes will be | 618 |
563 ; done when the counter has wrapped around to 0xFFFFFF | 619 comm_send_dive_modify_header: |
564 movlw 0x20 ; now the length count is allowed to be 0x1FFFFF at max | 620 ; set profile data start and end address to 0x000000 |
565 cpfslt ext_flash_length_counter+2 ; length count < 0x20(0000) ? | 621 CLRR header_buffer+index_profile_start_address,.6 |
566 bra comm_command_error ; NO - abort, back to command loop | 622 |
567 call ext_flash_read_block_start ; YES - read first byte from FLASH into WREG | 623 ; set hi = 0x00, lo = 0x08 |
568 bra comm_send_dive_loop_start ; - jump into transmit loop | 624 MOVLI 0x0008,mpr |
569 comm_send_dive_loop: | 625 |
570 call ext_flash_read_block_0x20 ; read next byte into WREG | 626 ; set byte count to 0x000008 |
571 comm_send_dive_loop_start: | 627 movff lo,header_buffer+index_profile_byte_count+0 ; = 0x08 |
572 SERIAL_CC_SEND WREG ; transmit byte | 628 movff hi,header_buffer+index_profile_byte_count+1 ; = 0x00 |
573 ext_flash_dec_length .1 ; decrement length counter | 629 movff hi,header_buffer+index_profile_byte_count+2 ; = 0x00 |
574 btfss ext_flash_length_counter+2,7; under-run? | 630 |
575 bra comm_send_dive_loop ; NO - continue loop | 631 comm_send_dive_header: |
576 call ext_flash_read_block_stop ; YES - end reading from FLASH | 632 SERIAL_RR_SEND header_buffer,.256 ; send the header from the buffer |
577 bra comm_command_loop ; - done, back to command loop | 633 |
634 btfss aux_flag ; profile data available? | |
635 bra comm_send_dive_empty_profile; NO - send empty profile | |
636 | |
637 comm_send_dive_profile: | |
638 FLASH_CW_READ_0x20 ; read one byte and increment address with rollover at 0x200000 | |
639 SERIAL_CC_SEND WREG ; transmit the byte | |
640 | |
641 ; 24 bit compare of current address with end address | |
642 movf ext_flash_end_pointer+0,W ; check low byte of addresses | |
643 cpfseq ext_flash_address+0 ; current address = end address ? | |
644 bra comm_send_dive_profile ; NO - more bytes to do, loop | |
645 | |
646 movf ext_flash_end_pointer+1,W ; check high byte of addresses | |
647 cpfseq ext_flash_address+1 ; current address = end address ? | |
648 bra comm_send_dive_profile ; NO - more bytes to do, loop | |
649 | |
650 movf ext_flash_end_pointer+2,W ; check upper byte of addresses | |
651 cpfseq ext_flash_address+2 ; current address = end address ? | |
652 bra comm_send_dive_profile ; NO - more bytes to do, loop | |
653 | |
654 comm_send_dive_exit: | |
655 bra comm_command_loop ; done, back to command loop | |
656 | |
657 comm_send_dive_empty_profile: | |
658 | |
659 ; send profile length | |
660 SERIAL_RR_SEND header_buffer+index_profile_byte_count,.3 | |
661 | |
662 SERIAL_LC_SEND 0xFD ; send end-of-profile sequence, byte 1 | |
663 SERIAL_LC_SEND 0xFD ; send end-of-profile sequence, byte 2 | |
664 | |
665 bra comm_command_loop ; done, back to command loop | |
578 | 666 |
579 | 667 |
580 ;----------------------------------------------------------------------------- | 668 ;----------------------------------------------------------------------------- |
581 ; Reset all Options to Factory Default | 669 ; Reset all Options to Factory Default |
582 ; | 670 ; |
585 call option_reset_all ; reset all options to factory default | 673 call option_reset_all ; reset all options to factory default |
586 bra comm_command_loop ; done, back to command loop | 674 bra comm_command_loop ; done, back to command loop |
587 | 675 |
588 | 676 |
589 ;----------------------------------------------------------------------------- | 677 ;----------------------------------------------------------------------------- |
590 ; Set Custom Text String (opt_name_length ASCII chars) | 678 ; Set Custom Text (opt_name_length ASCII chars) |
591 ; | 679 ; |
592 comm_set_custom_text: | 680 comm_set_custom_text: |
593 CLRR opt_name,opt_name_length ; clear old custom text | 681 CLRR opt_name,opt_name_length ; clear old custom text |
594 SERIAL_LC_SEND 0x63 ; acknowledge command | 682 |
595 | 683 bcf INTCON,GIE ; disable all interrupts |
596 ; receive new custom text (less than opt_name_length characters may be sent) | 684 SERIAL_LC_SEND 0x63 ; acknowledge command |
597 SERIAL_RR_RECEIVE_RAM opt_name,opt_name_length | 685 SERIAL_RR_RECEIVE opt_name,opt_name_length ; receive new custom text |
598 | 686 bsf INTCON,GIE ; re-enable all interrupts |
599 bra comm_command_loop ; done, back to command loop | 687 bsf option_changed ; flag that EEPROM needs to be updated |
688 | |
689 bra comm_command_loop ; done, back to command loop | |
600 | 690 |
601 | 691 |
602 ;----------------------------------------------------------------------------- | 692 ;----------------------------------------------------------------------------- |
603 ; Reset Battery Gauge | 693 ; Reset Battery Gauge |
604 ; | 694 ; |
610 | 700 |
611 ;----------------------------------------------------------------------------- | 701 ;----------------------------------------------------------------------------- |
612 ; Erase complete Logbook | 702 ; Erase complete Logbook |
613 ; | 703 ; |
614 comm_erase_complete_logbook: | 704 comm_erase_complete_logbook: |
615 ; SERIAL_LC_SEND 0x22 ; acknowledge command (not done) | 705 ; SERIAL_LC_SEND 0x22 ; acknowledge command (not done) |
616 call erase_complete_logbook ; erase complete logbook | 706 call erase_complete_logbook ; erase complete logbook |
617 bra comm_command_loop ; done, back to command loop | 707 bra comm_command_loop ; done, back to command loop |
618 | 708 |
619 | 709 |
620 ;----------------------------------------------------------------------------- | 710 ;----------------------------------------------------------------------------- |
621 ; Start Bootloader (aka perform cold start) | 711 ; Start Bootloader (aka perform cold start) |
622 ; | 712 ; |
623 comm_cold_start: | 713 comm_cold_start: |
624 ; SERIAL_LC_SEND 0xC1 ; acknowledge command (not done) | 714 ; SERIAL_LC_SEND 0xC1 ; acknowledge command (not done) |
625 ; call rs232_wait_tx ; wait for completion of transmit before hardware goes into reboot | 715 |
626 | 716 WIN_SMALL comm_status3_column, comm_status3_row ; set position |
627 WIN_SMALL comm_status3_column, comm_status3_row ; print "Low-level Bootloader" message | 717 FONT_COLOR_MEMO ; set standard color |
628 STRCPY_TEXT_PRINT tUsbLlBld ; ... | 718 STRCPY_TEXT_PRINT tUsbLlBld ; print "Low-level Bootloader" message |
629 | 719 |
630 WIN_TOP comm_warning_row ; set row for icon | 720 WIN_TOP comm_warning_row ; set row for icon |
631 WIN_LEFT comm_warning_column ; set column for icon | 721 WIN_LEFT comm_warning_column ; set column for icon |
632 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show a warning icon | 722 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show a warning icon |
633 | 723 |
634 bsf LEDr ; switch on red LED | 724 bsf LEDr ; switch on red LED |
635 | 725 |
636 call eeprom_deco_data_write ; update deco data in EEPROM | 726 call eeprom_deco_data_write ; update deco data in EEPROM |
637 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | 727 call eeprom_battery_gauge_write ; update battery gauge in EEPROM |
638 btfsc options_changed ; do the options need to be stored to EEPROM ? | 728 btfsc option_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 | 729 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
640 | 730 |
641 goto 0x1FF0C ; jump into the bootloader code | 731 ; WAITS .1 ; wait 1 second to give the serial I/F time |
642 | 732 ; ; to send the ackn before it gets shut down |
643 | 733 |
644 ;----------------------------------------------------------------------------- | 734 goto 0x1FF0C ; jump into the bootloader code for cold start |
645 ; Send Firmware to Bootloader (aka initiate firmware update) | 735 |
736 | |
737 ;----------------------------------------------------------------------------- | |
738 ; Send Firmware to Bootloader (aka initiate Firmware Update) | |
646 ; | 739 ; |
647 comm_firmware_update: | 740 comm_firmware_update: |
741 bcf INTCON,GIE ; disable all interrupts | |
648 SERIAL_LC_SEND 0x50 ; acknowledge command | 742 SERIAL_LC_SEND 0x50 ; acknowledge command |
649 | 743 SERIAL_RR_RECEIVE buffer,.5 ; (try to) receive 5 byte checksum |
650 SERIAL_RR_RECEIVE_RAM buffer,.5 ; (try to) receive 5 byte checksum | 744 bsf INTCON,GIE ; re-enable all interrupts |
745 | |
651 btfsc rs232_rx_timeout ; got all 5 bytes? | 746 btfsc rs232_rx_timeout ; got all 5 bytes? |
652 bra comm_send_firmware_abort ; NO - abort | 747 bra comm_send_firmware_abort ; NO - abort |
653 | 748 |
654 ; check the checksum | 749 ; check the checksum |
655 movlw 0x55 ; initialize checksum check-byte | 750 movlw 0x55 ; initialize checksum check-byte |
656 movwf hi ; store in hi | 751 movwf hi ; store in hi |
657 lfsr FSR2,buffer ; load base address of buffer | 752 INIT_BUFFER ; go back to start of the buffer |
658 movlw .5 ; 5 bytes to process | 753 movlw .5 ; 5 bytes to process |
659 movwf lo ; initialize loop counter | 754 movwf lo ; initialize loop counter |
660 comm_firmware_update_loop: | 755 comm_firmware_update_loop: |
661 movf POSTINC2,W ; get a checksum byte | 756 movf POSTINC2,W ; get a checksum byte |
662 xorwf hi,F ; xor checksum byte with check-byte | 757 xorwf hi,F ; xor checksum byte with check-byte |
666 tstfsz hi ; YES - check-byte zero? | 761 tstfsz hi ; YES - check-byte zero? |
667 bra comm_send_firmware_failed ; NO - checksum not valid | 762 bra comm_send_firmware_failed ; NO - checksum not valid |
668 | 763 |
669 ; checksum is valid | 764 ; checksum is valid |
670 SERIAL_LC_SEND 0x4C ; inform checksum is ok | 765 SERIAL_LC_SEND 0x4C ; inform checksum is ok |
671 call rs232_wait_tx ; wait for completion of transmit before hardware goes into reboot | 766 WAITS .1 ; wait 1 second to give the serial I/F time |
672 | 767 ; to send the 0x4C before it gets shut down |
768 ;bra comm_firmware_update_exec ; execute update | |
769 | |
770 global comm_firmware_update_exec | |
771 comm_firmware_update_exec: | |
772 call eeprom_memorize_fw_checksum ; memorize fw checksum in EEPROM | |
673 call eeprom_deco_data_write ; update deco data in EEPROM | 773 call eeprom_deco_data_write ; update deco data in EEPROM |
674 call eeprom_battery_gauge_write ; update battery gauge in EEPROM | 774 call eeprom_battery_gauge_write ; update battery gauge in EEPROM |
675 btfsc options_changed ; do the options need to be stored to EEPROM ? | 775 btfsc option_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 | 776 call option_check_and_store_all ; YES - check and store all option values in EEPROM |
677 | 777 goto 0x1FDF0 ; jump into the bootloader code for firmware update |
678 goto 0x1FDF0 ; jump into the bootloader code | 778 |
679 | 779 |
680 comm_send_firmware_failed: | 780 comm_send_firmware_failed: |
681 ; select font and output position | 781 ; select font and output position |
682 WIN_SMALL comm_string_column, comm_string_row | 782 WIN_SMALL comm_string_column, comm_string_row |
683 call TFT_warning_color ; select color | 783 FONT_COLOR_WARNING ; set warning color |
684 STRCPY_PRINT "Checksum failed" ; print failure message (fill to 15 chars) | 784 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 | 785 ;bra comm_send_firmware_abort ; abort |
687 | 786 |
688 comm_send_firmware_abort: | 787 comm_send_firmware_abort: |
689 SERIAL_LC_SEND 0xFF ; send abort message | 788 SERIAL_LC_SEND 0xFF ; send checksum failure message |
690 bra comm_command_loop ; done, back to command loop | 789 bra comm_command_loop ; done, back to command loop |
691 | 790 |
692 | 791 |
693 ;----------------------------------------------------------------------------- | 792 ;----------------------------------------------------------------------------- |
694 ; Erase a Memory Range given byte Start Address and Number of 4 kB Blocks | 793 ; Erase a single Block or a Range of Blocks |
695 ; | 794 ; |
696 comm_erase_range4kb: | 795 comm_erase_single_4kb: |
796 bcf INTCON,GIE ; disable all interrupts | |
797 bcf aux_flag ; do a single block only | |
798 ; SERIAL_LC_SEND 0x40 ; acknowledge command (not done) | |
799 bra comm_erase_get_start ; continue with getting start address | |
800 | |
801 comm_erase_range_4kb: | |
802 bcf INTCON,GIE ; disable all interrupts | |
803 bsf aux_flag ; do a range of blocks | |
697 SERIAL_LC_SEND 0x42 ; acknowledge command | 804 SERIAL_LC_SEND 0x42 ; acknowledge command |
698 bcf INTCON,GIE ; disable all interrupts | 805 ;bra comm_erase_get_start ; continue with getting start address |
806 | |
807 comm_erase_get_start: | |
699 rcall comm_get_start_address ; (try to) get the start address | 808 rcall comm_get_start_address ; (try to) get the start address |
700 btfsc rs232_rx_timeout ; got start address? | 809 btfsc rs232_rx_timeout ; got start address? |
701 bra comm_command_timeout ; NO - abort, back to command loop | 810 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
702 | 811 btfsc aux_flag ; YES - shall erase a range of blocks? |
703 ; (try to) receive the block count (1 byte) | 812 bra comm_erase_get_count ; YES - get the block count |
704 SERIAL_CC_RECEIVE ext_flash_length_counter | 813 movlw .1 ; NO - set 1 block to do |
814 movwf WREG ; - ... | |
815 bra comm_erase_common ; - start the erasing | |
816 | |
817 comm_erase_get_count: | |
818 SERIAL_CC_RECEIVE WREG ; (try to) receive the block count | |
705 btfsc rs232_rx_timeout ; got block count? | 819 btfsc rs232_rx_timeout ; got block count? |
706 bra comm_command_timeout ; NO - abort, back to command loop | 820 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
707 | 821 tstfsz WREG ; YES - block count = 0 ? |
708 ; erase blocks (number of blocks to do was received in ext_flash_length_counter:1) | 822 bra comm_erase_common ; NO - start the erasing |
709 comm_erase_range4kb_loop: | 823 bra comm_command_error ; YES - invalid, show error message and back to command loop |
710 call ext_flash_erase_4kB ; erase a 4 kB block | 824 |
711 ; increase start address by 0x1000 (4kB): | 825 comm_erase_common: |
712 ; nothing to do with low byte | 826 bsf INTCON,GIE ; re-enable all interrupts |
713 movlw 0x10 ; add 0x10... | 827 call ext_flash_erase_range ; erase #WREG 4kB blocks starting at ext_flash_address |
714 addwf ext_flash_address+1,F ; ... to high byte | 828 bra comm_command_loop ; done, back to command loop |
715 movlw 0x00 ; add 0x00... | 829 |
716 addwfc ext_flash_address+2,F ; ... plus carry bit to upper byte | 830 |
717 btfsc ext_flash_address+2,6 ; reached 0x400000 ? | 831 ;----------------------------------------------------------------------------- |
718 bra comm_command_loop ; YES - at end of address range, back to command loop | 832 ; Write a Stream of Bytes to the FLASH beginning at given Start Address, finish on Timeout |
719 decfsz ext_flash_length_counter,F ; NO - decrement number of blocks to do, all blocks done? | 833 ; |
720 bra comm_erase_range4kb_loop ; NO - loop | 834 comm_write_range_stream: |
721 bra comm_command_loop ; YES - done, back to command loop | 835 bcf INTCON,GIE ; disable all interrupts |
722 | 836 SERIAL_LC_SEND 0x30 ; acknowledge command |
723 | 837 |
724 ;----------------------------------------------------------------------------- | 838 rcall comm_get_start_address ; (try to) get the start address |
725 ; Erase one Memory Block of 4 kB Size | 839 btfsc rs232_rx_timeout ; got a complete start address? |
726 ; | 840 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
727 comm_erase_4kb: | 841 |
728 ; SERIAL_LC_SEND 0x40 ; acknowledge command (not done) | 842 IFDEF _comm_debug |
843 CLRI mpr ; clear mpr to be used as a 16 bit counter | |
844 ENDIF | |
845 | |
846 comm_write_range_stream_loop: | |
847 SERIAL_CC_RECEIVE WREG ; (try to) receive one byte | |
848 btfsc rs232_rx_timeout ; got a byte? | |
849 IFNDEF _comm_debug | |
850 bra comm_command_loop ; NO - timeout, done, back to command loop | |
851 ELSE | |
852 bra comm_command_debug ; NO - timeout, done, show number of bytes received | |
853 ENDIF | |
854 ; bsf NCTS ; YES - hold Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
855 call ext_flash_write_byte_0x40_nowait; - write byte to FLASH, increase address with rollover at 0x400000, does not wait on FLASH | |
856 ; bcf NCTS ; - release Bluetooth chip (requires PC/Android/iOS side to use flow control...) | |
857 IFDEF _comm_debug | |
858 INCI mpr ; increment counter | |
859 ENDIF | |
860 bra comm_write_range_stream_loop ; - loop | |
861 | |
862 | |
863 ;----------------------------------------------------------------------------- | |
864 ; Write a Block of 256 Bytes to the FLASH beginning at given Start Address (low byte needs to be zero) | |
865 ; | |
866 comm_write_range_block: | |
729 bcf INTCON,GIE ; disable all interrupts | 867 bcf INTCON,GIE ; disable all interrupts |
868 SERIAL_LC_SEND 0x31 ; acknowledge command | |
869 | |
730 rcall comm_get_start_address ; (try to) get the start address | 870 rcall comm_get_start_address ; (try to) get the start address |
731 btfsc rs232_rx_timeout ; got a complete start address? | 871 btfsc rs232_rx_timeout ; got a complete start address? |
732 bra comm_command_timeout ; NO - abort, back to command loop | 872 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
733 call ext_flash_erase_4kB ; YES - erase memory block | 873 |
734 bra comm_command_loop ; - done, back to command loop | 874 tstfsz ext_flash_address+0 ; low byte of start address = 0 ? |
735 | 875 bra comm_command_error ; NO - show error message and back to command loop |
736 | 876 |
737 ;----------------------------------------------------------------------------- | 877 SERIAL_RR_RECEIVE buffer,.256 ; (try to) receive 256 byte and buffer them in memory |
738 ; Write a stream of bytes to the FLASH beginning at given start address, end on timeout | 878 bsf INTCON,GIE ; re-enable all interrupts |
739 ; | 879 btfsc rs232_rx_timeout ; got all 256 bytes? |
740 comm_write_range_stream: | 880 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
741 SERIAL_LC_SEND 0x30 ; acknowledge command | 881 |
742 bcf INTCON,GIE ; disable all interrupts | 882 FLASH_RR_WRITE buffer,.256 ; copy from memory to FLASH |
743 rcall comm_get_start_address ; (try to) get the start address | 883 bra comm_command_loop ; done, back to command loop |
744 btfsc rs232_rx_timeout ; got a complete start address? | 884 |
745 bra comm_command_timeout ; NO - abort, back to command loop | 885 |
746 | 886 ;----------------------------------------------------------------------------- |
747 ; steam bytes to FLASH | 887 ; Read a Memory Range from FLASH given by Start Address and Byte Count |
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 ; | 888 ; |
783 comm_read_range: | 889 comm_read_range: |
890 bcf INTCON,GIE ; disable all interrupts | |
784 SERIAL_LC_SEND 0x20 ; acknowledge command | 891 SERIAL_LC_SEND 0x20 ; acknowledge command |
785 bcf INTCON,GIE ; disable all interrupts | |
786 | 892 |
787 ; receive start address | 893 ; receive start address |
788 rcall comm_get_start_address ; (try to) get the start address | 894 rcall comm_get_start_address ; (try to) get the start address |
789 btfsc rs232_rx_timeout ; got a complete start address? | 895 btfsc rs232_rx_timeout ; got a complete start address? |
790 bra comm_command_timeout ; NO - abort, back to command loop | 896 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
791 | 897 |
792 ; receive length | 898 ; receive byte count |
793 rcall comm_get_length ; (try to) get the length | 899 rcall comm_get_length ; (try to) get the byte count |
794 btfsc rs232_rx_timeout ; got a complete length? | 900 btfsc rs232_rx_timeout ; got a complete byte count? |
795 bra comm_command_timeout ; NO - abort, back to command loop | 901 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
902 | |
903 bsf INTCON,GIE ; re-enable all interrupts | |
904 | |
905 ; decrement byte counter by 1 so that all bytes will be done when the counter wraps around to 0xFFFFFF | |
906 EXT_FLASH_DEC_LENGTH | |
907 | |
908 ; check validity of the byte count | |
909 movlw 0x40 ; now the byte count is allowed to be 0x3FFFFF at max | |
910 cpfslt ext_flash_length_counter+2 ; length count < 0x40(0000) ? | |
911 bra comm_command_error ; NO - show error message and back to command loop | |
796 | 912 |
797 ; stream bytes from FLASH | 913 ; stream bytes from FLASH |
798 ext_flash_dec_length .1 ; decrement length count by 1 so that all bytes will be | 914 call ext_flash_read_block_start ; read first byte from FLASH into WREG |
799 ; done when the counter has wrapped around to 0xFFFFFF | 915 bra comm_read_range_loop_start ; jump into transmit loop |
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: | 916 comm_read_range_loop: |
807 call ext_flash_read_block_0x40 ; read next byte into WREG | 917 call ext_flash_read_block_0x40 ; read next byte into WREG |
808 comm_read_range_loop_start: | 918 comm_read_range_loop_start: |
809 SERIAL_CC_SEND WREG ; transmit byte | 919 SERIAL_CC_SEND WREG ; transmit byte |
810 ext_flash_dec_length .1 ; decrement length counter | 920 EXT_FLASH_DEC_LENGTH ; decrement byte counter |
811 btfss ext_flash_length_counter+2,7; under-run? | 921 btfss ext_flash_length_counter+2,7; under-run? |
812 bra comm_read_range_loop ; NO - continue loop | 922 bra comm_read_range_loop ; NO - continue loop |
813 call ext_flash_read_block_stop ; YES - end reading from FLASH | 923 call ext_flash_read_block_stop ; YES - end reading from FLASH |
814 bra comm_command_loop ; - done, back to command loop | 924 bra comm_command_loop ; - done, back to command loop |
815 | 925 |
816 | 926 |
817 ;----------------------------------------------------------------------------- | 927 ;----------------------------------------------------------------------------- |
818 ; Receive a 3 byte FLASH address (on serial: big-endian, in memory: little-endian) | 928 ; Receive a 3 byte FLASH address (on serial: big-endian, in memory: little-endian) |
819 ; | 929 ; |
820 comm_get_start_address: | 930 comm_get_start_address: |
821 SERIAL_RR_RECEIVE_RAM ext_flash_address,.3 ; receive 3 bytes | 931 SERIAL_RR_RECEIVE ext_flash_address,.3 ; (try to) receive 3 bytes |
822 btfsc rs232_rx_timeout ; timeout? | 932 btfsc rs232_rx_timeout ; timeout? |
823 return ; YES - abort, no usable address available | 933 return ; YES - abort, no usable address available |
824 | 934 |
825 ; remap address from network byte format (big endian) to host format (little-endian) | 935 ; remap address from network byte format (big endian) to host format (little-endian) |
826 movf ext_flash_address+0,W | 936 movf ext_flash_address+0,W |
827 movff ext_flash_address+2,ext_flash_address+0 | 937 movff ext_flash_address+2,ext_flash_address+0 |
828 movwf ext_flash_address+2 | 938 movwf ext_flash_address+2 |
829 | 939 |
830 return ; done, complete start address available | 940 return ; done, complete start address available |
831 | 941 |
832 | 942 |
833 ;----------------------------------------------------------------------------- | 943 ;----------------------------------------------------------------------------- |
834 ; Receive a 3 byte length (on serial: big-endian, in memory: little-endian) | 944 ; Receive a 3 byte length (on serial: big-endian, in memory: little-endian) |
835 ; | 945 ; |
836 comm_get_length: | 946 comm_get_length: |
837 SERIAL_RR_RECEIVE_RAM ext_flash_length_counter,.3 ; receive 3 bytes | 947 SERIAL_RR_RECEIVE ext_flash_length_counter,.3 ; receive 3 bytes |
838 btfsc rs232_rx_timeout ; timeout? | 948 btfsc rs232_rx_timeout ; timeout? |
839 return ; YES - abort, no usable address available | 949 return ; YES - abort, no usable address available |
840 | 950 |
841 ; remap address from network byte format (big endian) to host format (little-endian) | 951 ; remap address from network byte format (big endian) to host format (little-endian) |
842 movf ext_flash_length_counter+0,W | 952 movf ext_flash_length_counter+0,W |
843 movff ext_flash_length_counter+2,ext_flash_length_counter+0 | 953 movff ext_flash_length_counter+2,ext_flash_length_counter+0 |
844 movwf ext_flash_length_counter+2 | 954 movwf ext_flash_length_counter+2 |
845 | 955 |
846 return ; done, complete start address available | 956 return ; done, complete start address available |
847 | 957 |
848 | 958 |
849 ;----------------------------------------------------------------------------- | 959 ;----------------------------------------------------------------------------- |
850 ; Read an Option Value | 960 ; Read an Option Value |
851 ; | 961 ; |
852 comm_read_option: | 962 comm_read_option: |
853 SERIAL_LC_SEND 0x72 ; acknowledge command | 963 SERIAL_LC_SEND 0x72 ; acknowledge command |
854 SERIAL_CC_RECEIVE lo ; (try to) receive option index | 964 SERIAL_CC_RECEIVE lo ; (try to) receive option index |
855 btfsc rs232_rx_timeout ; received option index? | 965 btfsc rs232_rx_timeout ; received option index? |
856 bra comm_command_loop ; NO - abort, back to command loop | 966 bra comm_command_loop ; NO - show rx timeout message and back to command loop |
857 | 967 |
858 ; option index 0x00 - 0x0F: unused | 968 ; option index 0x00 - 0x0F: unused |
859 movlw 0x0F ; last option index of the unused range | 969 movlw 0x0F ; last option index of the unused range |
860 cpfsgt lo ; received option index > end of unused range ? | 970 cpfsgt lo ; received option index > end of unused range ? |
861 bra comm_command_error ; NO - abort, back to command loop | 971 bra comm_command_error ; NO - show error message and back to command loop |
862 | 972 |
863 ; option index 0x10 - 0x19: gases & diluents | 973 ; option index 0x10 - 0x19: gases & diluents |
864 movlw 0x19 ; last option index for gases / diluents | 974 movlw 0x19 ; last option index for gases / diluents |
865 cpfsgt lo ; received option index > end of gas/dil range ? | 975 cpfsgt lo ; received option index > end of gas/dil range ? |
866 bra comm_read_gas_dil ; NO - process gas/dil read | 976 bra comm_read_gas_dil ; NO - process gas/dil read |
873 ; option index = 0x49 - special handling button polarity | 983 ; option index = 0x49 - special handling button polarity |
874 movf lo,W ; copy option index to WREG | 984 movf lo,W ; copy option index to WREG |
875 iorlw 0x49 ; received option index for button polarity ? | 985 iorlw 0x49 ; received option index for button polarity ? |
876 bz comm_read_button_polarity ; YES - process button polarity read | 986 bz comm_read_button_polarity ; YES - process button polarity read |
877 | 987 |
878 ; option index 0x1F - 0xFF: options managed by option-table | 988 ; option index 0x1F - 0xF9: options managed by option table |
989 movlw 0xF9 ; last option index for options | |
990 cpfsgt lo ; received option index > end of options range? | |
991 bra comm_read_option_index ; YES - process option value read via index | |
992 | |
993 bra comm_command_error ; NO - illegal option index | |
994 | |
995 | |
996 ;----------------------------------------------------------------------------- | |
997 ; Write an Option Value | |
998 ; | |
999 comm_write_option: | |
1000 bcf INTCON,GIE ; disable all interrupts | |
1001 SERIAL_LC_SEND 0x77 ; acknowledge command | |
1002 SERIAL_CC_RECEIVE lo ; (try to) receive option index | |
1003 btfsc rs232_rx_timeout ; got a byte? | |
1004 bra comm_command_timeout ; NO - show rx timeout message and back to command loop | |
1005 | |
1006 ; option index 0x00 - 0x0F: unused | |
1007 movlw 0x0F ; last option index of the unused range | |
1008 cpfsgt lo ; received option index > end of unused range ? | |
1009 bra comm_write_unused ; NO - but need to consume the option value | |
1010 | |
1011 ; option index 0x10 - 0x19: gases & diluents | |
1012 movlw 0x19 ; last option index for gases / diluents | |
1013 cpfsgt lo ; received option index > end of gas/dil range ? | |
1014 bra comm_write_gas_dil ; NO - process gas/dil write | |
1015 | |
1016 ; option index 0x1A - 0x1E: setpoints | |
1017 movlw 0x1E ; last option index for setpoint | |
1018 cpfsgt lo ; received option index > end of setpoint range ? | |
1019 bra comm_write_sp ; NO - process setpoint write | |
1020 | |
1021 ; option index = 0x49 - special handling button polarity | |
1022 movf lo,W ; copy option index to WREG | |
1023 iorlw 0x49 ; received option index for button polarity ? | |
1024 bz comm_write_button_polarity ; YES - process button polarity write | |
1025 | |
1026 ; option index 0x1F - 0xF9: options managed by option table | |
1027 movlw 0xF9 ; last option index for options | |
1028 cpfsgt lo ; received option index > end of options range? | |
1029 bra comm_write_option_index ; YES - process option value write via index | |
1030 | |
1031 bra comm_write_unused ; NO - illegal option index | |
1032 | |
1033 | |
1034 ;----------------------------------------------------------------------------- | |
1035 ; Read an Option Value via its Serial Index | |
1036 ; | |
1037 comm_read_option_index: | |
879 call option_read_serial ; try to find the option and read its value | 1038 call option_read_serial ; try to find the option and read its value |
880 tstfsz WREG ; option found? | 1039 tstfsz WREG ; option found? |
881 bra comm_read_setting_fail ; NO - send dummy value | 1040 bra comm_read_setting_fail ; NO - send dummy value |
882 SERIAL_CC_SEND hi ; YES - send read value | 1041 SERIAL_CC_SEND hi ; YES - send read value |
883 bra comm_command_loop ; - done, back to command loop | 1042 bra comm_command_loop ; - done, back to command loop |
886 SERIAL_LC_SEND 0x00 ; send a dummy value | 1045 SERIAL_LC_SEND 0x00 ; send a dummy value |
887 bra comm_command_error ; back to command loop with failure message | 1046 bra comm_command_error ; back to command loop with failure message |
888 | 1047 |
889 | 1048 |
890 ;----------------------------------------------------------------------------- | 1049 ;----------------------------------------------------------------------------- |
891 ; Write an Option Value | 1050 ; Write an Option Value via its Serial Index |
892 ; | 1051 ; |
893 comm_write_option: | 1052 comm_write_option_index: |
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 | 1053 SERIAL_CC_RECEIVE hi ; (try to) receive option value |
921 btfsc rs232_rx_timeout ; got a byte? | 1054 btfsc rs232_rx_timeout ; got a byte? |
922 bra comm_command_timeout ; NO - abort | 1055 bra comm_command_timeout ; NO - abort |
923 call option_write_serial ; YES - try to find the option and write new value | 1056 call option_write_serial ; YES - try to find the option and write new value |
924 tstfsz WREG ; - option found and new value valid ? | 1057 tstfsz WREG ; - option found and new value valid ? |
929 SERIAL_CC_RECEIVE WREG ; consume unused option value | 1062 SERIAL_CC_RECEIVE WREG ; consume unused option value |
930 bra comm_command_error ; done, back to command loop | 1063 bra comm_command_error ; done, back to command loop |
931 | 1064 |
932 | 1065 |
933 ;----------------------------------------------------------------------------- | 1066 ;----------------------------------------------------------------------------- |
934 ; Read button polarity | 1067 ; Read Button Polarity |
935 ; | 1068 ; |
936 comm_read_button_polarity: | 1069 comm_read_button_polarity: |
937 SERIAL_CC_SEND button_polarity ; send current button polarity setting | 1070 SERIAL_CC_SEND button_polarity ; send current button polarity setting |
938 bra comm_command_loop ; done, back to command loop | 1071 bra comm_command_loop ; done, back to command loop |
939 | 1072 |
940 | 1073 |
941 ;----------------------------------------------------------------------------- | 1074 ;----------------------------------------------------------------------------- |
942 ; Write button polarity | 1075 ; Write Button Polarity |
943 ; | 1076 ; |
944 comm_write_button_polarity: | 1077 comm_write_button_polarity: |
945 SERIAL_CC_RECEIVE hi ; (try to) receive configuration value | 1078 SERIAL_CC_RECEIVE hi ; (try to) receive configuration value |
946 btfsc rs232_rx_timeout ; got configuration value? | 1079 btfsc rs232_rx_timeout ; got configuration value? |
947 bra comm_command_timeout ; NO - abort, back to command loop | 1080 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
948 movff hi,button_polarity ; YES - store button polarity in memory and EEPROM | 1081 movff hi,button_polarity ; YES - store button polarity in memory and EEPROM |
949 EEPROM_CC_WRITE button_polarity,eeprom_button_polarity | 1082 EEPROM_CC_WRITE button_polarity,eeprom_button_polarity |
950 bra comm_command_loop ; - done, back to command loop | 1083 bra comm_command_loop ; - done, back to command loop |
951 | 1084 |
952 | 1085 |
953 ;----------------------------------------------------------------------------- | 1086 ;----------------------------------------------------------------------------- |
954 ; Read a gas/diluent dataset | 1087 ; Read a Gas/Diluent Dataset |
955 ; | 1088 ; |
956 ; Memory map is as follows: | 1089 ; memory map is as follows: |
957 ; ------------------------- | 1090 ; ------------------------- |
958 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | 1091 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases |
959 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | 1092 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents |
960 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | 1093 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases |
961 ; opt_dil_He_ratio res 5 ; He ratios of diluents | 1094 ; opt_dil_He_ratio res 5 ; He ratios of diluents |
977 SERIAL_CC_SEND PLUSW0 ; send change depth | 1110 SERIAL_CC_SEND PLUSW0 ; send change depth |
978 bra comm_command_loop ; done, back to command loop | 1111 bra comm_command_loop ; done, back to command loop |
979 | 1112 |
980 | 1113 |
981 ; ---------------------------------------------------------------------------- | 1114 ; ---------------------------------------------------------------------------- |
982 ; Write a gas/diluent dataset | 1115 ; Write a Gas/Diluent Dataset |
983 ; | 1116 ; |
984 ; Memory map is as follows: | 1117 ; memory map is as follows: |
985 ; ------------------------- | 1118 ; ------------------------- |
986 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases | 1119 ; opt_gas_O2_ratio res 5 ; O2 ratios of OC/bailout gases |
987 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents | 1120 ; opt_dil_O2_ratio res 5 ; O2 ratios of diluents |
988 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases | 1121 ; opt_gas_He_ratio res 5 ; He ratios of OC/bailout gases |
989 ; opt_dil_He_ratio res 5 ; He ratios of diluents | 1122 ; opt_dil_He_ratio res 5 ; He ratios of diluents |
991 ; opt_dil_type res 5 ; dil type | 1124 ; opt_dil_type res 5 ; dil type |
992 ; opt_gas_change res 5 ; change depths for OC/Bailout gases | 1125 ; opt_gas_change res 5 ; change depths for OC/Bailout gases |
993 ; opt_dil_change res 5 ; change depths for diluents | 1126 ; opt_dil_change res 5 ; change depths for diluents |
994 ; | 1127 ; |
995 comm_write_gas_dil: | 1128 comm_write_gas_dil: |
996 SERIAL_RR_RECEIVE_RAM hi,.4 ; (try to) receive 4 option values | 1129 SERIAL_RR_RECEIVE hi,.4 ; (try to) receive 4 option values |
997 btfsc rs232_rx_timeout ; got all 4 bytes? | 1130 btfsc rs232_rx_timeout ; got all 4 bytes? |
998 bra comm_command_timeout ; NO - abort, back to command loop | 1131 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
999 | 1132 |
1000 ; check validity of O2 value | 1133 ; check validity of O2 value |
1001 movlw gaslist_min_o2-.1 ; get min value minus 1 | 1134 movlw gaslist_min_o2-.1 ; get min value minus 1 |
1002 cpfsgt hi ; received O2% >= min ? | 1135 cpfsgt hi ; received O2% >= min ? |
1003 bra comm_command_error ; NO - abort, back to command loop | 1136 bra comm_command_error ; NO - show error message and back to command loop |
1004 movlw gaslist_max_o2+.1 ; get max value plus 1 | 1137 movlw gaslist_max_o2+.1 ; get max value plus 1 |
1005 cpfslt hi ; received O2% <= max ? | 1138 cpfslt hi ; received O2% <= max ? |
1006 bra comm_command_error ; NO - abort, back to command loop | 1139 bra comm_command_error ; NO - show error message and back to command loop |
1007 | 1140 |
1008 ; check validity of He value | 1141 ; check validity of He value |
1009 movlw gaslist_max_He+.1 ; get max value plus 1 | 1142 movlw gaslist_max_He+.1 ; get max value plus 1 |
1010 cpfslt up ; received O2% <= max ? | 1143 cpfslt up ; received O2% <= max ? |
1011 bra comm_command_error ; NO - abort, back to command loop | 1144 bra comm_command_error ; NO - show error message and back to command loop |
1012 | 1145 |
1146 IFDEF _helium | |
1013 ; check O2% + He% <= 100% | 1147 ; check O2% + He% <= 100% |
1014 movlw .100 ; load 100% | 1148 movlw .100 ; load WREG with 100% |
1015 bsf STATUS,C ; set carry = clear borrow | 1149 bsf STATUS,C ; set carry = clear borrow |
1016 subfwb hi,W ; subtract O2% from 100% | 1150 subfwb hi,W ; subtract O2% from WREG |
1151 subfwb up,W ; subtract He% from WREG | |
1017 btfss STATUS,C ; result negative? | 1152 btfss STATUS,C ; result negative? |
1018 bra comm_command_error ; YES - abort, back to command loop | 1153 bra comm_command_error ; YES - show error message and back to command loop |
1019 subfwb up,W ; NO - subtract He% | 1154 ENDIF ; _helium |
1020 btfss STATUS,C ; - now negative? | |
1021 bra comm_command_error ; YES - abort, back to command loop | |
1022 | 1155 |
1023 ; check validity of type | 1156 ; check validity of type |
1024 movlw 0x14 ; last option index for gases | 1157 movlw 0x14 ; last option index for gases |
1025 cpfsgt lo ; received option index > end of gas range ? | 1158 cpfsgt lo ; received option index > end of gas range ? |
1026 bra comm_write_dil ; YES - check type for diluents | 1159 bra comm_write_check_dil ; YES - check type for diluents |
1027 ;bra comm_write_gas ; NO - check type for gases | 1160 ;bra comm_write_check_gas ; NO - check type for gases |
1028 | 1161 |
1029 comm_write_gas: | 1162 comm_write_check_gas: |
1030 ; check validity of type for a gas | 1163 ; check validity of type for a gas |
1031 movlw num_gas_types ; load number of gas types | 1164 movlw num_gas_types ; load number of gas types |
1032 bra comm_write_gas_dil_common ; continue with common part | 1165 bra comm_write_check_com ; continue with common part |
1033 | 1166 |
1034 comm_write_dil: | 1167 comm_write_check_dil: |
1035 ; check validity of type for a diluent | 1168 ; check validity of type for a diluent |
1036 movlw num_dil_types ; load number of diluent types | 1169 movlw num_dil_types ; load number of diluent types |
1037 ;bra comm_write_gas_dil_common ; continue with common part | 1170 ;bra comm_write_check_com ; continue with common part |
1038 | 1171 |
1039 comm_write_gas_dil_common: | 1172 comm_write_check_com: |
1040 cpfslt ex ; received type < max ? | 1173 cpfslt ex ; received type < max ? |
1041 bra comm_command_error ; NO - abort, back to command loop | 1174 bra comm_command_error ; NO - show error message and back to command loop |
1042 | 1175 |
1043 ; check validity of change depth | 1176 ; check validity of change depth |
1044 movlw gaslist_max_change_depth+.1 ; get max value plus 1 | 1177 movlw gaslist_max_change_depth+.1 ; get max value plus 1 |
1045 cpfslt ul ; received change depth <= max ? | 1178 cpfslt ul ; received change depth <= max ? |
1046 bra comm_command_error ; NO - abort, back to command loop | 1179 bra comm_command_error ; NO - show error message and back to command loop |
1047 | 1180 |
1048 ; all values ok, can finally be written | 1181 ; all values ok, can finally be written |
1049 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays | 1182 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays |
1050 movlw 0x10 ; compute gas index from option index... | 1183 movlw 0x10 ; compute gas index from option index... |
1051 subwf lo,W ; ...making WREG point to O2 ratio | 1184 subwf lo,W ; ...making WREG point to O2 ratio |
1185 | |
1052 movff hi,PLUSW0 ; set O2 ratio | 1186 movff hi,PLUSW0 ; set O2 ratio |
1053 addlw .10 ; increment WREG by 10 to point to He ratio | 1187 addlw .10 ; increment WREG by 10 to point to He ratio |
1054 movff up,PLUSW0 ; set He ratio | 1188 movff up,PLUSW0 ; set He ratio |
1055 addlw .10 ; increment WREG by 10 to point to gas/dil type | 1189 addlw .10 ; increment WREG by 10 to point to gas/dil type |
1056 movff ex,PLUSW0 ; set gas/dil type | 1190 movff ex,PLUSW0 ; set gas/dil type |
1057 addlw .10 ; increment WREG by 10 to point to change depth | 1191 addlw .10 ; increment WREG by 10 to point to change depth |
1058 movff ul,PLUSW0 ; set change depth | 1192 movff ul,PLUSW0 ; set change depth |
1059 | 1193 |
1060 bra comm_command_loop ; done, back to command loop | 1194 bsf option_changed ; flag that EEPROM needs to be updated |
1061 | 1195 bra comm_command_loop ; done, back to command loop |
1062 | 1196 |
1063 ;----------------------------------------------------------------------------- | 1197 |
1064 ; Read a setpoint dataset | 1198 ;----------------------------------------------------------------------------- |
1065 ; | 1199 ; Read a Setpoint Dataset |
1066 ; Memory map is as follows: | 1200 ; |
1201 ; memory map is as follows: | |
1067 ; ------------------------- | 1202 ; ------------------------- |
1068 ; opt_setpoint_cbar res 5 ; setpoints in cbar | 1203 ; opt_setpoint_cbar res 5 ; setpoints in cbar |
1069 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter | 1204 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter |
1070 ; | 1205 ; |
1071 comm_read_sp: | 1206 comm_read_sp: |
1077 SERIAL_CC_SEND PLUSW0 ; send change depth | 1212 SERIAL_CC_SEND PLUSW0 ; send change depth |
1078 bra comm_command_loop ; done, back to command loop | 1213 bra comm_command_loop ; done, back to command loop |
1079 | 1214 |
1080 | 1215 |
1081 ;----------------------------------------------------------------------------- | 1216 ;----------------------------------------------------------------------------- |
1082 ; Write a setpoint dataset | 1217 ; Write a Setpoint Dataset |
1083 ; | 1218 ; |
1084 ; Memory map is as follows: | 1219 ; memory map is as follows: |
1085 ; ------------------------- | 1220 ; ------------------------- |
1086 ; opt_setpoint_cbar res 5 ; setpoints in cbar | 1221 ; opt_setpoint_cbar res 5 ; setpoints in cbar |
1087 ; opt_setpoint_change res 5 ; change depths in meter | 1222 ; opt_setpoint_change res 5 ; change depths in meter |
1088 ; | 1223 ; |
1089 comm_write_sp: | 1224 comm_write_sp: |
1090 SERIAL_RR_RECEIVE_RAM hi,.2 ; (try to) receive 2 option values | 1225 SERIAL_RR_RECEIVE hi,.2 ; (try to) receive 2 option values |
1091 btfsc rs232_rx_timeout ; got both bytes? | 1226 btfsc rs232_rx_timeout ; got both bytes? |
1092 bra comm_command_timeout ; NO - abort, back to command loop | 1227 bra comm_command_timeout ; NO - show rx timeout message and back to command loop |
1093 | 1228 |
1094 ; check validity of setpoint value | 1229 ; check validity of setpoint value |
1095 movlw gaslist_sp_min-.1 ; get min value minus 1 | 1230 movlw gaslist_sp_min-.1 ; get min value minus 1 |
1096 cpfsgt hi ; received O2% >= min ? | 1231 cpfsgt hi ; received O2% >= min ? |
1097 bra comm_command_error ; NO - abort, back to command loop | 1232 bra comm_command_error ; NO - show error message and back to command loop |
1098 movlw gaslist_sp_max+.1 ; get max value plus 1 | 1233 movlw gaslist_sp_max+.1 ; get max value plus 1 |
1099 cpfslt hi ; received O2% <= max ? | 1234 cpfslt hi ; received O2% <= max ? |
1100 bra comm_command_error ; NO - abort, back to command loop | 1235 bra comm_command_error ; NO - show error message and back to command loop |
1101 | 1236 |
1102 ; check validity of change depth | 1237 ; check validity of change depth |
1103 movlw sp_max_change_depth+.1 ; get max value plus 1 | 1238 movlw gaslist_sp_max_depth+.1 ; get max value plus 1 |
1104 cpfslt up ; received change depth <= max ? | 1239 cpfslt up ; received change depth <= max ? |
1105 bra comm_command_error ; NO - abort, back to command loop | 1240 bra comm_command_error ; NO - show error message and back to command loop |
1106 | 1241 |
1107 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values | 1242 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values |
1108 movlw 0x1A ; compute SP index from option index... | 1243 movlw 0x1A ; compute SP index from option index... |
1109 subwf lo,W ; ...making WREG point to cbar value | 1244 subwf lo,W ; ...making WREG point to cbar value |
1245 | |
1246 bnz comm_write_sp_exec ; selected SP is 2...5 -> execute write | |
1247 tstfsz up ; SP1: change depth = 0 ? | |
1248 bra comm_command_error ; NO - show error message and back to command loop | |
1249 | |
1250 comm_write_sp_exec: | |
1110 movff hi,PLUSW0 ; set cbar value | 1251 movff hi,PLUSW0 ; set cbar value |
1111 addlw .5 ; increment WREG by 5 to point to change depth | 1252 addlw .5 ; increment WREG by 5 to point to change depth |
1112 movff up,PLUSW0 ; set change depth | 1253 movff up,PLUSW0 ; set change depth |
1113 | 1254 |
1255 bsf option_changed ; flag that EEPROM needs to be updated | |
1114 bra comm_command_loop ; done, back to command loop | 1256 bra comm_command_loop ; done, back to command loop |
1115 | 1257 |
1116 ;----------------------------------------------------------------------------- | 1258 ;----------------------------------------------------------------------------- |
1117 | 1259 |
1118 END | 1260 END |