comparison src/comm.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents ca4556fb60b9
children cd58f7fc86db
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File comm.asm REFACTORED VERSION V2.99d 3 ; File comm.asm combined next generation V3.03.3
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 ;=============================================================================
26 26
27 extern restart 27 extern restart
28 extern option_reset_all 28 extern option_reset_all
29 extern option_check_all 29 extern option_check_all
30 extern gaslist_cleanup_list 30 extern gaslist_cleanup_list
31 extern get_first_gas_to_WREG
32 extern get_first_dil_to_WREG
33 extern option_save_all 31 extern option_save_all
34 extern vault_decodata_into_eeprom 32 extern vault_decodata_into_eeprom
35 extern menu_processor_bottom_line_comm 33
36 34
37 IFDEF _rx_functions 35 #DEFINE timeout_comm_pre_mode .240 ; timeout before communication is established
38 extern I2C_update_OSTC_rx 36 #DEFINE timeout_service_mode .120 ; timeout when communication is established
39 ENDIF 37
40 38 #DEFINE comm_title_row .0 ; positioning of title
41 39 #DEFINE comm_title_column_usb .40
42 #DEFINE timeout_comm_pre_mode .240 ; pre-loop
43 #DEFINE timeout_comm_mode .120 ; download mode
44 #DEFINE timeout_service_mode .120 ; service mode
45
46 #DEFINE comm_title_row .0
47 #DEFINE comm_title_column_usb .50
48 #DEFINE comm_title_column_ble .25 40 #DEFINE comm_title_column_ble .25
49 41
50 #DEFINE comm_string_row .30 42 #DEFINE comm_string_row .30 ; positioning of host-sent text messages
51 #DEFINE comm_string_column .40 43 #DEFINE comm_string_column .40
52 44
53 #DEFINE comm_status1_row .70 45 #DEFINE comm_status1_row .70 ; positioning of COMM mode status messages
54 #DEFINE comm_status1_column .10 46 #DEFINE comm_status1_column .10
55 #DEFINE comm_status2_row .100 47 #DEFINE comm_status2_row .100
56 #DEFINE comm_status2_column comm_status1_column 48 #DEFINE comm_status2_column comm_status1_column
57 #DEFINE comm_status3_row .130 49 #DEFINE comm_status3_row .130
58 #DEFINE comm_status3_column comm_status1_column 50 #DEFINE comm_status3_column comm_status1_column
59 #DEFINE comm_status4_row .160 51 #DEFINE comm_status4_row .160
60 #DEFINE comm_status4_column comm_status1_column 52 #DEFINE comm_status4_column comm_status1_column
61 53
62 54 #DEFINE comm_warning_row .160 ; positioning of COMM mode warning messages
63 #DEFINE comm_warning_row .160
64 #DEFINE comm_warning_column .65 55 #DEFINE comm_warning_column .65
65 56
57
66 comm CODE 58 comm CODE
67 59
68 ;============================================================================= 60 ;=============================================================================
69 61
70 ; test for comm 62 global comm_mode_usb
71 global comm_mode, comm_mode0 63 comm_mode_usb: ; entry point for comm mode via USB
72 comm_mode: 64 WAITMS d'1' ; wait 1 ms
73 WAITMS d'1' 65 btfss vusb_in ; USB still plugged in?
74 btfss vusb_in ; USB plugged in? 66 return ; NO - it was only a glitch, abort
75 return ; NO - it was only a glitch 67 WAITMS d'1' ; wait 1 ms
76 WAITMS d'1' 68 btfss vusb_in ; USB still plugged in?
77 btfss vusb_in ; USB plugged in? 69 return ; NO - it was only a glitch, abort
78 return ; NO - it was only a glitch 70 bsf aux_flag ; YES - remember to show USB title
79 comm_mode0: 71 bra comm_mode_common ; - continue with common part
80 call TFT_ClearScreen 72
81 WIN_COLOR color_greenish 73 global comm_mode_ble
82 btfsc ble_available ; BLE available 74 comm_mode_ble: ; entry point for comm mode via BLE
83 bra comm_mode0_ble 75 bcf aux_flag ; remember to show BLE title
84 WIN_SMALL comm_title_column_usb, comm_title_row 76 ;bra comm_mode_common ; continue with common part
85 STRCPY_TEXT_PRINT tUsbTitle ; USB mode 77
86 bra comm_mode0_common 78 comm_mode_common:
87 comm_mode0_ble: 79 clrf STKPTR ; clear return addresses stack
88 WIN_SMALL comm_title_column_ble, comm_title_row 80 call TFT_ClearScreen ; clear screen
89 STRCPY_TEXT_PRINT tBleTitle ; BLE mode 81 WIN_COLOR color_greenish ; set color
90 comm_mode0_common: 82 btfss aux_flag ; shall show USB title?
91 call TFT_standard_color 83 bra comm_mode_common_1 ; NO
92 WIN_TOP .10 84 WIN_SMALL comm_title_column_usb, comm_title_row ; YES - set USB title position
93 WIN_LEFT .1 85 STRCPY_TEXT_PRINT tUsbTitle ; - print USB title text
94 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_block 86 bra comm_mode_common_2
95 WIN_SMALL comm_status1_column,comm_status1_row 87 comm_mode_common_1:
96 STRCPY_TEXT_PRINT tUsbStarting ; starting... 88 WIN_SMALL comm_title_column_ble, comm_title_row ; set BLE title position
97 call menu_processor_bottom_line_comm ; serial and fw version 89 STRCPY_TEXT_PRINT tBleTitle ; print BLE title text
90 comm_mode_common_2:
91 call TFT_standard_color ; set standard color
92 WIN_TOP .10 ; positioning of USB/BLE logo, row
93 WIN_LEFT .1 ; positioning of USB/BLE logo, column
94 TFT_WRITE_PROM_IMAGE_BY_ADDR usb_ble_logo_block ; show USB/BLE logo, respective logo is stored in bootloader section dependent on OSTC type
95 WIN_SMALL comm_status1_column,comm_status1_row ; positioning of status message
96 STRCPY_TEXT_PRINT tUsbStarting ; print status message "starting..."
97 WIN_TINY .40,.240-.16 ; set output position to bottom line
98 call TFT_show_serial_and_firmware ; show serial number and firmware version
98 call option_save_all ; save all settings into EEPROM (comm mode may be entered after settings have been changed without leaving the menu in between) 99 call option_save_all ; save all settings into EEPROM (comm mode may be entered after settings have been changed without leaving the menu in between)
99 100
100 IFDEF _screendump 101 IFDEF _screendump
101 bcf enable_screen_dumps ; =1: ignore vin_usb, wait for "l" command (screen dump) 102 bcf screen_dump_avail ; disable screen dump function
102 ENDIF 103 ENDIF
103 104
104 bcf switch_right 105 bcf switch_right ; clear left-over right button event
105 bcf comm_service_enabled 106 bcf comm_service_enabled ; communication is not yet established
106 bsf menubit 107 bsf surfmode_menu ; flag that restart will be entered from surface menu / comm mode
107 bcf battery_removed_in_usb ; =1: the battery has been removed in USB (properly not used for anything useful) 108 movlw timeout_comm_pre_mode ; get timeout for phase without communication established yet
108 movlw timeout_comm_pre_mode 109 movwf comm_timeout_timer ; initialize timeout counter
109 movwf comm_timeout
110 WIN_SMALL comm_status1_column+.80,comm_status1_row 110 WIN_SMALL comm_status1_column+.80,comm_status1_row
111 STRCPY_TEXT_PRINT tUsbStartDone ; done... 111 STRCPY_TEXT_PRINT tUsbStartDone ; add to status message "done..."
112 call enable_rs232 ; also sets to speed_normal ... 112 call enable_rs232 ; enable serial comm, also sets CPU to normal speed
113 comm_mode1: 113 comm_mode1:
114 bcf onesecupdate 114 bcf trigger_full_second ; clear 'one second elapsed' flag
115 bcf LEDr 115 bcf LEDr ; switch off red LED / power down TR co-processor
116 dcfsnz comm_timeout,F 116 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero?
117 bra comm_service_exit ; timeout -> exit 117 bra comm_service_exit ; YES - timeout, exit comm mode
118 comm_mode2: 118 comm_mode2:
119 rcall comm_get_byte 119 rcall comm_get_byte ; read 1 byte from RX buffer
120 120 movlw 0xAA ; coding of service mode start byte: 0xAA
121 movlw 0xAA ; start byte=0xAA? 121 cpfseq RCREG1 ; received service mode start byte?
122 cpfseq RCREG1 122 bra comm_mode2a ; NO - probe for download mode
123 bra comm_mode2a 123 bra comm_mode2b ; YES - received start byte for service mode
124 bra comm_mode2b ; start byte for service mode found
125 comm_mode2a: 124 comm_mode2a:
126 movlw 0xBB ; start byte=0xBB? 125 movlw 0xBB ; coding of download mode start byte: 0xBB
127 cpfseq RCREG1 126 cpfseq RCREG1 ; received download mode start byte?
128 bra comm_mode2c 127 bra comm_mode2c ; NO
129 bra comm_download_mode ; start byte for download mode found 128 bra comm_download_mode ; YES - received start byte for download mode
130
131 comm_mode2c: 129 comm_mode2c:
132 btfss vusb_in ; USB plugged in? 130 btfss vusb_in ; USB plugged in?
133 bra comm_service_exit_nousb_delay ; disconnected -> exit 131 bra comm_service_exit_nousb_delay; NO - disconnected, exit comm mode
134 comm_mode4a: 132 comm_mode4a:
135 btfsc switch_right ; abort with right 133 btfsc switch_right ; right button pressed?
136 bra comm_service_exit 134 bra comm_service_exit ; YES - exit comm mode
137 135 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile?
138 btfsc onesecupdate 136 bra comm_mode1 ; YES - loop with clocking down timeout counter
139 bra comm_mode1 137 bra comm_mode2 ; NO - loop without clocking down timeout counter
140 138
141 bra comm_mode2 ; cycle 139 ; received start byte for service mode
142
143 comm_mode2b: 140 comm_mode2b:
144 ; Startbyte found 141 rcall comm_write_byte ; wait for completion of transmit
145 rcall comm_write_byte ; wait for UART 142 movlw 0x4B ; prepare answer
146 movlw 0x4B 143 movwf TXREG1 ; send answer
147 movwf TXREG1 ; send answer 144 ; check if correct service key is received
148 ; Now, check comm command 145 rcall comm_get_byte ; receive first byte
149 146 rcall comm_write_byte ; wait for completion of transmit
150 rcall comm_get_byte ; first byte 147 movff RCREG1,TXREG1 ; echo received byte
151 rcall comm_write_byte ; wait for UART 148 movlw UPPER comm_service_key ; load expected byte
152 movff RCREG1,TXREG1 ; Echo 149 cpfseq RCREG1 ; received expected byte?
153 movlw UPPER comm_service_key 150 bra comm_mode1 ; NO - restart
154 cpfseq RCREG1 151 rcall comm_get_byte ; receive second byte
155 bra comm_mode1 ; wrong -> restart 152 rcall comm_write_byte ; wait for completion of transmit
156 rcall comm_get_byte ; second byte 153 movff RCREG1,TXREG1 ; echo received byte
157 rcall comm_write_byte ; wait for UART 154 movlw HIGH (comm_service_key & 0xFFFF) ; load expected byte
158 movff RCREG1,TXREG1 ; echo 155 cpfseq RCREG1 ; received expected byte?
159 movlw HIGH (comm_service_key & 0xFFFF) 156 bra comm_mode1 ; NO - restart
160 cpfseq RCREG1 157 rcall comm_get_byte ; receive third byte
161 bra comm_mode1 ; wrong -> restart 158 rcall comm_write_byte ; wait for completion of transmit
162 rcall comm_get_byte ; third byte 159 movff RCREG1,TXREG1 ; echo received byte
163 rcall comm_write_byte ; wait for UART 160 movlw LOW comm_service_key ; load expected byte
164 movff RCREG1,TXREG1 ; echo 161 cpfseq RCREG1 ; received expected byte?
165 movlw LOW comm_service_key 162 bra comm_mode1 ; NO - restart
166 cpfseq RCREG1 163 ; YES to all - enable com service mode
167 bra comm_mode1 ; wrong -> restart
168
169 ; Enable comm service mode
170 WIN_SMALL comm_status2_column, comm_status2_row 164 WIN_SMALL comm_status2_column, comm_status2_row
171 STRCPY_TEXT_PRINT tUsbServiceMode ; service mode enabled 165 STRCPY_TEXT_PRINT tUsbServiceMode ; print service mode enabled message
172 bsf comm_service_enabled ; set flag... 166 bsf comm_service_enabled ; set flag for com service mode enabled
173 bra comm_download_mode0 ; ... but use common routine 167 bra comm_download_mode0 ; continue using common routine
174 168
175 comm_service_exit_nousb_delay: 169 comm_service_exit_nousb_delay:
176 WAITMS d'200' 170 WAITMS d'200' ; wait 200 ms
177 btfsc vusb_in ; USB plugged in? 171 btfsc vusb_in ; USB plugged in?
178 bra comm_mode4a ; YES - (still) connected, return 172 bra comm_mode4a ; YES - (still) connected, return
179 comm_service_exit_nousb: ; NO - disconnected -> exit 173 comm_service_exit_nousb: ; NO - disconnected
180 WIN_SMALL comm_status3_column, comm_status3_row 174 WIN_SMALL comm_status3_column, comm_status3_row
181 STRCPY_TEXT_PRINT tUsbClosed ; port closed 175 STRCPY_TEXT_PRINT tUsbClosed ; print port closed message
182 bra comm_service_exit_common 176 bra comm_service_exit_common ; exit to restart
183 177
184 comm_service_exit: 178 comm_service_exit:
185 WIN_SMALL comm_status3_column, comm_status3_row 179 WIN_SMALL comm_status3_column, comm_status3_row
186 STRCPY_TEXT_PRINT tUsbExit ; exited 180 STRCPY_TEXT_PRINT tUsbExit ; print exited message
187 comm_service_exit_common: 181 comm_service_exit_common:
188 rcall comm_write_byte ; wait for UART 182 rcall comm_write_byte ; wait for completion of transmit
189 movlw 0xFF ; reply FF 183 movlw 0xFF ; prepare reply "FF"
190 movwf TXREG1 ; send answer 184 movwf TXREG1 ; send reply
191 185 call wait_1s ; wait <= 1 second
192 call wait_1s ; wait 1 second 186 call wait_1s ; wait 1 second
193 call wait_1s ; wait 1 second 187 call disable_rs232 ; shut down comm port
194 188 goto restart ; restart
195 call disable_rs232 189
196 goto restart 190
197 191 ;-----------------------------------------------------------------------------
198 ;----------------------------------------------------------------------------- 192 ; Start Bootloader
199 193 ;
200 comm_service_ll_bootloader: 194 comm_service_ll_bootloader:
201 bsf LEDr 195 bsf LEDr ; switch on red LED
202 WIN_SMALL comm_status3_column, comm_status3_row 196 WIN_SMALL comm_status3_column, comm_status3_row
203 STRCPY_TEXT_PRINT tUsbLlBld ; low level bootloader started 197 STRCPY_TEXT_PRINT tUsbLlBld ; print low level bootloader started message
204 WIN_TOP comm_warning_row 198 WIN_TOP comm_warning_row ; set row for icon
205 WIN_LEFT comm_warning_column 199 WIN_LEFT comm_warning_column ; set column for icon
206 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show warning icon 200 TFT_WRITE_PROM_IMAGE_BY_LABEL dive_warning2_block ; show the warning icon
207 goto 0x1FF0C 201 goto 0x1FF0C ; jump into the bootloader code
208 202
209 ;----------------------------------------------------------------------------- 203
210 ; send firmware to bootloader 204 ;-----------------------------------------------------------------------------
205 ; Send Firmware to Bootloader
211 ; 206 ;
212 comm_send_firmware: 207 comm_send_firmware:
213 movlw 0x50 ; send echo 208 movlw 0x50 ; prepare reply
214 movwf TXREG1 209 movwf TXREG1 ; send reply
215 rcall comm_write_byte ; wait for UART 210 rcall comm_write_byte ; wait for completion of transmit
216 211 lfsr FSR2,buffer ; load base address of buffer
217 ; Read 5 bytes into buffer. 212 movlw .5 ; read 5 bytes into buffer
218 lfsr FSR2,buffer 213 movwf lo ; initialize loop counter
219 movlw .5 ; counter 214 movlw 0x55 ; initialize checksum byte
220 movwf lo 215 movwf hi ; store in hi
221 movlw 0x55 ; 5'ft byte checksum
222 movwf hi
223
224 comm_send_firmware_loop: 216 comm_send_firmware_loop:
225 rcall comm_get_byte 217 rcall comm_get_byte ; receive one byte
226 btfsc rs232_receive_overflow ; got byte? 218 btfsc rs232_rx_timeout ; got a byte?
227 bra comm_send_firmware_abort ; NO - abort 219 bra comm_send_firmware_abort ; NO - abort
228 movf RCREG1,W 220 movf RCREG1,W ; YES - copy received byte to WREG
229 movwf POSTINC2 ; store checksum byte 221 movwf POSTINC2 ; - copy received byte to buffer
230 xorwf hi,F ; also xor into checksum 222 xorwf hi,F ; - xor received byte into checksum
231 rlncf hi,F ; and rotate it 223 rlncf hi,F ; - rotate checksum byte
232 decfsz lo,F 224 decfsz lo,F ; - decrement loop counter, done?
233 bra comm_send_firmware_loop 225 bra comm_send_firmware_loop ; NO - loop
234 226 movf hi,W ; YES - copy checksum to WREG, zero flag set?
235 ; check that 5ft byte checksum's checksum 227 bnz comm_send_firmware_failed ; NO - checksum test failed
236 movf hi,W 228 movlw 0x4C ; YES - checksum ok, prepare reply
237 bnz comm_send_firmware_failed 229 movwf TXREG1 ; - send reply
238 230 rcall comm_write_byte ; - wait for completion of transmit
239 movlw 0x4C ; send OK 231 call vault_decodata_into_eeprom ; - store last deco data (and time/date) to EEPROM
240 movwf TXREG1 232 goto 0x1FDF0 ; - jump into the bootloader code
241 rcall comm_write_byte ; wait for UART
242
243 ; Passed: goto second stage verification.
244 ; NOTE: Bootloader is Bank0. With buffer at address 0x200.
245 call vault_decodata_into_eeprom ; store last deco data (and time/date) into EEPROM
246 goto 0x1FDF0 ; and pray...
247 233
248 comm_send_firmware_failed: 234 comm_send_firmware_failed:
249 WIN_SMALL comm_string_column, comm_string_row 235 WIN_SMALL comm_string_column, comm_string_row
250 call TFT_warnings_color 236 call TFT_warning_color ; set warning color
251 STRCPY_PRINT "Checksum failed" 237 STRCPY_PRINT "Checksum failed" ; print failure message
252
253 comm_send_firmware_abort: 238 comm_send_firmware_abort:
254 239 movlw 0xFF ; prepare reply for ABORTED
255 movlw 0xFF ; send ABORTED byte 240 movwf TXREG1 ; send reply
256 movwf TXREG1
257 bra comm_download_mode0 ; done 241 bra comm_download_mode0 ; done
258 242
259 ;----------------------------------------------------------------------------- 243
260 ; Reset to Dive 1 in logbook 244 ;-----------------------------------------------------------------------------
261 245 ; Reset to Dive 1 in Logbook
246 ;
262 comm_reset_logbook_pointers: 247 comm_reset_logbook_pointers:
263 call eeprom_reset_logbook_pointers ; clear logbook pointers in EEPROM... 248 call eeprom_reset_logbook_pointers ; clear logbook pointers in EEPROM
264 call ext_flash_erase_logbook ; ... and complete logbook (!) 249 call ext_flash_erase_logbook ; clear complete logbook(!)
265 bra comm_download_mode0 ; done 250 bra comm_download_mode0 ; done
266 251
267 ;----------------------------------------------------------------------------- 252 ;-----------------------------------------------------------------------------
268 comm_reset_battery_gauge: ; resets battery gauge registers 253 ; Reset Battery Gauge
269 call reset_battery_pointer ; resets battery pointer 0x07-0x0C and battery_gauge:5 254 ;
255 comm_reset_battery_gauge: ; reset battery gauge registers
256 call reset_battery_pointer ; reset battery pointer 0x07-0x0C and battery gauge
270 bra comm_download_mode0 ; done 257 bra comm_download_mode0 ; done
271 258
272 ;----------------------------------------------------------------------------- 259 ;-----------------------------------------------------------------------------
273 ; erases range in 4 kB steps 260 ; Erase a Memory Range given byte Start Address and Number of 4 kB Blocks
274 261 ;
275 comm_erase_range4kb: 262 comm_erase_range4kb:
276 movlw 0x42 ; send echo 263 movlw 0x42 ; prepare reply
277 movwf TXREG1 264 movwf TXREG1 ; send reply
278 rcall comm_write_byte ; wait for UART 265 rcall comm_write_byte ; wait for completion of transmit
279 bcf INTCON,GIE ; all interrupts off! 266 bcf INTCON,GIE ; disable all interrupts
280 rcall comm_get_flash_address ; get three bytes address or return 267 rcall comm_get_flash_address ; get three bytes start address or return
281 btfsc rs232_receive_overflow ; got data? 268 btfsc rs232_rx_timeout ; got start address?
269 bra comm_download_mode0 ; NO - done
270 rcall comm_get_byte ; YES - get number of blocks
271 btfsc rs232_rx_timeout ; - got number?
272 bra comm_download_mode0 ; NO - done
273 movff RCREG1,lo ; YES - copy number of blocks to lo
274 comm_erase_range4kb_loop:
275 call ext_flash_erase4kB ; - erase a memory block
276 movlw 0x10 ; - increase start address by 4096 (0x1000)
277 addwf ext_flash_address+1,F ; - ...
278 movlw .0 ; - ...
279 addwfc ext_flash_address+2,F ; - ...
280 decfsz lo,F ; - decrement block counter, all blocks done?
281 bra comm_erase_range4kb_loop ; NO - loop
282 bra comm_download_mode0 ; YES - done
283
284 ;-----------------------------------------------------------------------------
285 ; Erase one Memory Block of 4 kB Size
286 ;
287 comm_erase_4kb:
288 bcf INTCON,GIE ; disable all interrupts
289 rcall comm_get_flash_address ; get three bytes start address or return
290 btfsc rs232_rx_timeout ; got start address?
291 bra comm_download_mode0 ; NO - done
292 call ext_flash_erase4kB ; YES - erase memory block
293 bra comm_download_mode0 ; - done
294
295 ;-----------------------------------------------------------------------------
296 ; Write a Stream of Data Bytes to Memory
297 ;
298 comm_write_range:
299 movlw 0x30 ; prepare reply
300 movwf TXREG1 ; send reply
301 rcall comm_write_byte ; wait for completion of transmit
302 bcf INTCON,GIE ; disable all interrupts
303 rcall comm_get_flash_address ; get three bytes starts address or return
304 btfsc rs232_rx_timeout ; got start address?
305 bra comm_download_mode0 ; NO - done
306 comm_write_range_loop:
307 rcall comm_get_byte ; YES - get data byte to write to memory
308 btfsc rs232_rx_timeout ; got byte?
309 bra comm_download_mode0 ; NO - done
310 movf RCREG1,W ; YES - copy received data byte to WREG
311 ; bsf NCTS ; - hold Bluetooth chip (requires PC/Android/iOS side to use flow control...)
312 call ext_flash_byte_write_comms ; - write data byte to flash memory
313 ; bcf NCTS ; - release Bluetooth chip (requires PC/Android/iOS side to use flow control...)
314 call incf_ext_flash_address_p1 ; - increase address
315 bra comm_write_range_loop ; - loop
316
317
318 ;-----------------------------------------------------------------------------
319 ; Read a Memory Section given by Start Address and Length
320 ;
321 comm_send_range:
322 movlw 0x20 ; prepare reply
323 movwf TXREG1 ; send reply
324 rcall comm_write_byte ; wait for completion of transmit
325 bcf INTCON,GIE ; disable all interrupts
326 rcall comm_get_flash_address ; get three bytes start address or return
327 btfsc rs232_rx_timeout ; got start address?
282 bra comm_download_mode0 ; NO - done 328 bra comm_download_mode0 ; NO - done
283 rcall comm_get_byte 329 rcall comm_get_byte ; get length, 3rd byte
284 btfsc rs232_receive_overflow ; got byte? 330 btfsc rs232_rx_timeout ; got byte?
285 bra comm_download_mode0 ; NO - done 331 bra comm_download_mode0 ; NO - done
286 movff RCREG1,lo 332 movff RCREG1,up ; store length, 3rd byte
287 ; Got 4 bytes: 3 bytes address and 1 byte (lo) amount of 4kB blocks 333 rcall comm_get_byte ; get length, 2nd byte
288 comm_erase_range4kb_loop: 334 btfsc rs232_rx_timeout ; got byte?
289 call ext_flash_erase4kB ; erase block
290 movlw 0x10
291 addwf ext_flash_address+1,F
292 movlw .0
293 addwfc ext_flash_address+2,F ; increase address by .4096, or 0x1000
294 decfsz lo,F
295 bra comm_erase_range4kb_loop ; loop until lo=zero
296 bra comm_download_mode0 ; done (sends the 4C OK too)
297
298 ;-----------------------------------------------------------------------------
299
300 comm_erase_4kb: ; get 3 bytes start address
301 bcf INTCON,GIE ; all interrupts off
302
303 rcall comm_get_flash_address ; get three bytes address or return
304 btfsc rs232_receive_overflow ; got data?
305 bra comm_download_mode0 ; NO - done 335 bra comm_download_mode0 ; NO - done
306 336 movff RCREG1,hi ; store length, 2nd byte
307 call ext_flash_erase4kB ; erase one block 337 rcall comm_get_byte ; get length, 1st byte
308 bra comm_download_mode0 ; done 338 btfsc rs232_rx_timeout ; got byte?
309
310 ;-----------------------------------------------------------------------------
311
312 comm_write_range: ; get 3 bytes start address
313 movlw 0x30 ; send echo
314 movwf TXREG1
315 rcall comm_write_byte ; wait for UART
316
317 bcf INTCON,GIE ; all interrupts off
318
319 rcall comm_get_flash_address ; get three bytes address or return
320 btfsc rs232_receive_overflow ; got data?
321 bra comm_download_mode0 ; NO - done 339 bra comm_download_mode0 ; NO - done
322 340 movff RCREG1,lo ; store length, 1st byte
323 comm_write_range_loop:
324 rcall comm_get_byte
325 btfsc rs232_receive_overflow ; got byte?
326 bra comm_download_mode0 ; NO - done (and send OK byte too)
327 movf RCREG1,W
328 ; bsf NCTS ; hold Bluetooth chip (requires PC/Android/iOS side to use flow control...)
329 call ext_flash_byte_write_comms ; write one byte
330 ; bcf NCTS ; release Bluetooth chip (requires PC/Android/iOS side to use flow control...)
331 call incf_ext_flash_address_p1 ; increase address+1
332 bra comm_write_range_loop
333
334 ;-----------------------------------------------------------------------------
335
336 comm_send_range: ; get 3 bytes start address and 3 bytes amount
337 movlw 0x20 ; send echo
338 movwf TXREG1
339 rcall comm_write_byte ; wait for UART
340 bcf INTCON,GIE ; all interrupts off
341 rcall comm_get_flash_address ; get three bytes address or return
342 btfsc rs232_receive_overflow ; got data?
343 bra comm_download_mode0 ; NO - done
344 rcall comm_get_byte
345 btfsc rs232_receive_overflow ; got byte?
346 bra comm_download_mode0 ; NO - done
347 movff RCREG1,up
348 rcall comm_get_byte
349 btfsc rs232_receive_overflow ; got byte?
350 bra comm_download_mode0 ; NO - done
351 movff RCREG1,hi
352 rcall comm_get_byte
353 btfsc rs232_receive_overflow ; got byte?
354 bra comm_download_mode0 ; NO - done
355 movff RCREG1,lo
356 ; if lo==0, we must precondition hi because there are too many bytes sent 341 ; if lo==0, we must precondition hi because there are too many bytes sent
357 movf lo,W 342 movf lo,W
358 bnz $+4 343 bnz $+4
359 decf hi,F 344 decf hi,F
360 movlw 0x40 345 movlw 0x40
361 cpfslt up ; up > 0x3F? 346 cpfslt up ; up > 0x3F ?
362 bra comm_download_mode0 ; YES - abort 347 bra comm_download_mode0 ; YES - abort
363 ; 6 bytes received, send data 348 ; 6 bytes received, send data
364 ; needs ext_flash_address:3 start address and up:hi:lo amount 349 ; needs ext_flash_address:3 start address and up:hi:lo amount
365 call ext_flash_read_block_start 350 call ext_flash_read_block_start
366 movwf TXREG1 351 movwf TXREG1
367 bra comm_send_range24 ; counter 24 bit 352 bra comm_send_range24 ; counter 24 bit
368 comm_send_range24_loop: 353 comm_send_range24_loop:
369 call ext_flash_read_block ; read one byte 354 call ext_flash_read_block ; read one byte
370 movwf TXREG1 ; start new transmit 355 movwf TXREG1 ; start new transmit
371 comm_send_range24: 356 comm_send_range24:
372 rcall comm_write_byte ; wait for UART 357 rcall comm_write_byte ; wait for completion of transmit
373 decfsz lo,F 358 decfsz lo,F
374 bra comm_send_range24_loop 359 bra comm_send_range24_loop
375 decf hi,F 360 decf hi,F
376 movlw 0xFF 361 movlw 0xFF
377 cpfseq hi 362 cpfseq hi
385 370
386 ;----------------------------------------------------------------------------- 371 ;-----------------------------------------------------------------------------
387 372
388 comm_get_flash_address: 373 comm_get_flash_address:
389 rcall comm_get_byte 374 rcall comm_get_byte
390 btfsc rs232_receive_overflow ; got byte? 375 btfsc rs232_rx_timeout ; got byte?
391 return ; NO - return 376 return ; NO - return
392 movff RCREG1,ext_flash_address+2 377 movff RCREG1,ext_flash_address+2
393 rcall comm_get_byte 378 rcall comm_get_byte
394 btfsc rs232_receive_overflow ; got byte? 379 btfsc rs232_rx_timeout ; got byte?
395 return ; NO - return 380 return ; NO - return
396 movff RCREG1,ext_flash_address+1 381 movff RCREG1,ext_flash_address+1
397 rcall comm_get_byte 382 rcall comm_get_byte
398 btfsc rs232_receive_overflow ; got byte? 383 btfsc rs232_rx_timeout ; got byte?
399 return ; NO - return 384 return ; NO - return
400 movff RCREG1,ext_flash_address+0 385 movff RCREG1,ext_flash_address+0
401 return 386 return
402 387
403 ;----------------------------------------------------------------------------- 388 ;-----------------------------------------------------------------------------
405 comm_download_mode: 390 comm_download_mode:
406 ; Enable comm download mode 391 ; Enable comm download mode
407 WIN_SMALL comm_status2_column, comm_status2_row 392 WIN_SMALL comm_status2_column, comm_status2_row
408 STRCPY_TEXT_PRINT tUsbDownloadMode ; download mode enabled 393 STRCPY_TEXT_PRINT tUsbDownloadMode ; download mode enabled
409 bsf INTCON,GIE ; all interrupts on 394 bsf INTCON,GIE ; all interrupts on
410 rcall comm_write_byte ; wait for UART 395 rcall comm_write_byte ; wait for completion of transmit
411 movlw 0xBB ; command echo 396 movlw 0xBB ; command echo
412 movwf TXREG1 ; send answer 397 movwf TXREG1 ; send answer
413 comm_download_mode0: 398 comm_download_mode0:
414 bsf INTCON,GIE ; all interrupts on 399 bsf INTCON,GIE ; all interrupts on
415 rcall comm_write_byte ; wait for UART 400 rcall comm_write_byte ; wait for completion of transmit
416 movlw 0x4C ; 4C in service mode 401 movlw 0x4C ; default reply is 4C for service mode
417 btfss comm_service_enabled 402 btfss comm_service_enabled ; com service enabled?
418 movlw 0x4D ; 4D in download mode 403 movlw 0x4D ; NO - change to reply 4D for download mode
419 movwf TXREG1 ; send answer 404 movwf TXREG1 ; send answer
420 movlw timeout_service_mode 405 movlw timeout_service_mode ; get timeout value
421 movwf comm_timeout ; timeout 406 movwf comm_timeout_timer ; load into timeout counter
422 bcf switch_right 407 bcf switch_right ; clear left-over button event
423 comm_download_mode1: 408 comm_download_mode1:
424 bcf onesecupdate 409 bcf trigger_full_second ; clear 'one second elapsed' flag
425 dcfsnz comm_timeout,F 410 dcfsnz comm_timeout_timer,F ; decrement timeout, reached zero?
426 bra comm_service_exit ; timeout -> exit 411 bra comm_service_exit ; YES - exit
427 comm_download_mode2: 412 comm_download_mode2:
428 rcall comm_get_byte ; check for a byte 413 rcall comm_get_byte ; No - check for a byte
429 btfsc comm_service_enabled 414 btfsc comm_service_enabled ; com service mode enabled?
430 btg LEDr ; blink in service mode 415 btg LEDr ; YES - blink in service mode
431 btfss vusb_in ; USB plugged in? 416 btfss vusb_in ; USB plugged in?
432 bra comm_service_exit_nousb ; NO - disconnected -> exit 417 bra comm_service_exit_nousb ; NO - disconnected -> exit
433 btfsc switch_right ; abort with right button 418 btfsc switch_right ; YES - shall abort?
434 bra comm_service_exit 419 bra comm_service_exit ; YES
435 btfsc onesecupdate 420 btfsc trigger_full_second ; NO - did 1 second elapsed meanwhile?
436 bra comm_download_mode1 421 bra comm_download_mode1 ; YES - check for timeout
437 btfsc rs232_receive_overflow 422 btfsc rs232_rx_timeout ; NO - got a byte?
438 bra comm_download_mode2 ; wait for command byte 423 bra comm_download_mode2 ; NO - loop waiting for command byte
439 424 ; YES - command received
440 ; command received
441 bcf LEDr 425 bcf LEDr
442 movlw 0xFF 426 movlw 0xFF
443 cpfseq RCREG1 427 cpfseq RCREG1
444 bra $+4 428 bra $+4
445 bra comm_service_exit ; exit 429 bra comm_service_exit ; exit
477 goto comm_send_string ; send a 15 byte string to the screen 461 goto comm_send_string ; send a 15 byte string to the screen
478 movlw "m" 462 movlw "m"
479 cpfseq RCREG1 463 cpfseq RCREG1
480 bra $+4 464 bra $+4
481 goto comm_send_compact_headers ; send all 256 compact headers 465 goto comm_send_compact_headers ; send all 256 compact headers
482
483 IFDEF _screendump 466 IFDEF _screendump
484 movlw "l" 467 movlw "l"
485 cpfseq RCREG1 468 cpfseq RCREG1
486 bra $+4 469 bra $+4
487 call TFT_dump_screen ; dump the screen contents 470 call TFT_dump_screen ; dump the screen contents
488 ENDIF 471 ENDIF
489
490 movlw "r" 472 movlw "r"
491 cpfseq RCREG1 473 cpfseq RCREG1
492 bra $+4 474 bra $+4
493 bra comm_read_setting ; read a setting (and send via USB) 475 bra comm_read_setting ; read a setting (and send via USB)
494 movlw "w" 476 movlw "w"
533 bra comm_send_firmware ; send firmware to bootloader 515 bra comm_send_firmware ; send firmware to bootloader
534 ; movlw "t" 516 ; movlw "t"
535 ; cpfseq RCREG1 517 ; cpfseq RCREG1
536 ; bra $+4 518 ; bra $+4
537 ; goto testloop ; start raw-data test loop 519 ; goto testloop ; start raw-data test loop
538 IFDEF _rx_function
539 movlw 0x70
540 cpfseq RCREG1
541 bra $+4
542 bra comm_update_ostc_rx ; send firmware from external memory 3D0800h -> 3DFFFFh to OSTC RX circuity
543 ENDIF
544 movlw 0xC1 520 movlw 0xC1
545 cpfseq RCREG1 521 cpfseq RCREG1
546 bra $+4 522 bra $+4
547 bra comm_service_ll_bootloader ; start low-level bootloader 523 bra comm_service_ll_bootloader ; start low-level bootloader
548 bra comm_download_mode0 ; loop with timeout reset 524 bra comm_download_mode0 ; loop with timeout reset
578 bra comm_download_mode0 ; done, loop with timeout reset 554 bra comm_download_mode0 ; done, loop with timeout reset
579 555
580 comm_send_compact_headers4: 556 comm_send_compact_headers4:
581 movlw .13 557 movlw .13
582 movwf lo ; counter 558 movwf lo ; counter
583 rcall comm_write_byte ; wait for UART 559 rcall comm_write_byte ; wait for completion of transmit
584 call ext_flash_read_block_start ; 1st byte 560 call ext_flash_read_block_start ; 1st byte
585 movwf TXREG1 561 movwf TXREG1
586 bra comm_send_compact_headers3 ; counter 24 bit 562 bra comm_send_compact_headers3 ; counter 24 bit
587 comm_send_compact_headers_loop: 563 comm_send_compact_headers_loop:
588 call ext_flash_read_block ; read one byte 564 call ext_flash_read_block ; read one byte
589 movwf TXREG1 ; start new transmit 565 movwf TXREG1 ; start new transmit
590 comm_send_compact_headers3: 566 comm_send_compact_headers3:
591 rcall comm_write_byte ; wait for UART 567 rcall comm_write_byte ; wait for completion of transmit
592 decfsz lo,F 568 decfsz lo,F
593 bra comm_send_compact_headers_loop 569 bra comm_send_compact_headers_loop
594 call ext_flash_read_block_stop 570 call ext_flash_read_block_stop
595 571
596 ; Offset to total dive counter 572 ; Offset to total dive counter
597 movlw .80 573 movlw .80
598 movwf ext_flash_address+0 574 movwf ext_flash_address+0
599 call ext_flash_read_block_start ; 1st byte 575 call ext_flash_read_block_start ; 1st byte
600 movwf TXREG1 576 movwf TXREG1
601 rcall comm_write_byte ; wait for UART 577 rcall comm_write_byte ; wait for completion of transmit
602 call ext_flash_read_block ; 2nd byte 578 call ext_flash_read_block ; 2nd byte
603 movwf TXREG1 579 movwf TXREG1
604 call ext_flash_read_block_stop 580 call ext_flash_read_block_stop
605 rcall comm_write_byte ; wait for UART 581 rcall comm_write_byte ; wait for completion of transmit
606 582
607 ; Offset to Logbook-Profile version 583 ; Offset to Logbook-Profile version
608 movlw .8 584 movlw .8
609 movwf ext_flash_address+0 585 movwf ext_flash_address+0
610 call ext_flash_byte_read ; get byte 586 call ext_flash_byte_read ; get byte
611 movwf TXREG1 587 movwf TXREG1
612 rcall comm_write_byte ; wait for UART 588 rcall comm_write_byte ; wait for completion of transmit
613 bra comm_send_compact_headers2 ; continue 589 bra comm_send_compact_headers2 ; continue
614 590
615 591
616 ;----------------------------------------------------------------------------- 592 ;-----------------------------------------------------------------------------
617 593
639 cpfseq ext_flash_address+2 ; all 256 dive send? 615 cpfseq ext_flash_address+2 ; all 256 dive send?
640 bra comm_send_headers4 ; NO - continue 616 bra comm_send_headers4 ; NO - continue
641 bra comm_download_mode0 ; done, loop with timeout reset 617 bra comm_download_mode0 ; done, loop with timeout reset
642 comm_send_headers4: 618 comm_send_headers4:
643 clrf lo ; counter 619 clrf lo ; counter
644 rcall comm_write_byte ; wait for UART 620 rcall comm_write_byte ; wait for completion of transmit
645 call ext_flash_read_block_start ; 1st byte 621 call ext_flash_read_block_start ; 1st byte
646 movwf TXREG1 622 movwf TXREG1
647 bra comm_send_headers3 ; counter 24 bit 623 bra comm_send_headers3 ; counter 24 bit
648 comm_send_headers_loop: 624 comm_send_headers_loop:
649 call ext_flash_read_block ; read one byte 625 call ext_flash_read_block ; read one byte
650 movwf TXREG1 ; start new transmit 626 movwf TXREG1 ; start new transmit
651 comm_send_headers3: 627 comm_send_headers3:
652 rcall comm_write_byte ; wait for UART 628 rcall comm_write_byte ; wait for completion of transmit
653 decfsz lo,F 629 decfsz lo,F
654 bra comm_send_headers_loop 630 bra comm_send_headers_loop
655 call ext_flash_read_block_stop 631 call ext_flash_read_block_stop
656 bra comm_send_headers2 ; continue 632 bra comm_send_headers2 ; continue
657 633
667 643
668 comm_set_time: 644 comm_set_time:
669 movlw "b" ; send echo 645 movlw "b" ; send echo
670 movwf TXREG1 646 movwf TXREG1
671 647
672 rcall comm_write_byte ; wait for UART 648 rcall comm_write_byte ; wait for completion of transmit
673 rcall comm_get_byte 649 rcall comm_get_byte
674 btfsc rs232_receive_overflow ; got byte? 650 btfsc rs232_rx_timeout ; got byte?
675 bra comm_download_mode0 ; NO - abort 651 bra comm_download_mode0 ; NO - abort
676 movff RCREG1, hours 652 movff RCREG1, rtc_latched_hour
677 movlw d'24'
678 cpfslt hours
679 clrf hours
680 rcall comm_get_byte 653 rcall comm_get_byte
681 btfsc rs232_receive_overflow ; got byte? 654 btfsc rs232_rx_timeout ; got byte?
682 bra comm_download_mode0 ; NO - abort 655 bra comm_download_mode0 ; NO - abort
683 movff RCREG1, mins 656 movff RCREG1, rtc_latched_mins
684 movlw d'60'
685 cpfslt mins
686 clrf mins
687 rcall comm_get_byte 657 rcall comm_get_byte
688 btfsc rs232_receive_overflow ; got byte? 658 btfsc rs232_rx_timeout ; got byte?
689 bra comm_download_mode0 ; NO - abort 659 bra comm_download_mode0 ; NO - abort
690 movff RCREG1, secs 660 movff RCREG1, rtc_latched_secs
691 movlw d'60'
692 cpfslt secs
693 clrf secs
694 rcall comm_get_byte 661 rcall comm_get_byte
695 btfsc rs232_receive_overflow ; got byte? 662 btfsc rs232_rx_timeout ; got byte?
696 bra comm_download_mode0 ; NO - abort 663 bra comm_download_mode0 ; NO - abort
697 movff RCREG1, month 664 movff RCREG1, rtc_latched_month
698 movlw d'13'
699 cpfslt month
700 movwf month
701 rcall comm_get_byte 665 rcall comm_get_byte
702 btfsc rs232_receive_overflow ; got byte? 666 btfsc rs232_rx_timeout ; got byte?
703 bra comm_download_mode0 ; NO - abort 667 bra comm_download_mode0 ; NO - abort
704 call comm_check_day ; check day 668 movff RCREG1, rtc_latched_day
705 rcall comm_get_byte 669 rcall comm_get_byte
706 btfsc rs232_receive_overflow ; got byte? 670 btfsc rs232_rx_timeout ; got byte?
707 bra comm_download_mode0 ; NO - abort 671 bra comm_download_mode0 ; NO - abort
708 movff RCREG1, year 672 movff RCREG1, rtc_latched_year
709 movlw d'100' 673 call rtc_set_rtc ; write time and date to RTC module
710 cpfslt year
711 clrf year
712 ; all ok, set RTCC
713 call rtc_set_rtc ; writes mins,sec,hours,day,month and year to RTC module
714 bra comm_download_mode0 ; done, back to loop with timeout reset 674 bra comm_download_mode0 ; done, back to loop with timeout reset
715 675
716 ;----------------------------------------------------------------------------- 676 ;-----------------------------------------------------------------------------
717 ; Set custom text string (opt_name_length ASCII chars) 677 ; Set custom text string (opt_name_length ASCII chars)
718 ; 678 ;
719 679
720 comm_set_custom_text: 680 comm_set_custom_text:
721 movlw "c" ; send echo 681 movlw "c" ; send echo
722 movwf TXREG1 682 movwf TXREG1
723 rcall comm_write_byte ; wait for UART 683 rcall comm_write_byte ; wait for completion of transmit
724 lfsr FSR2,opt_name 684 lfsr FSR2,opt_name
725 movlw opt_name_length 685 movlw opt_name_length
726 movwf lo ; counter 686 movwf lo ; counter
727 comm_set_ctext_loop: 687 comm_set_ctext_loop:
728 rcall comm_get_byte 688 rcall comm_get_byte
729 btfsc rs232_receive_overflow ; got byte? 689 btfsc rs232_rx_timeout ; got byte?
730 bra comm_set_ctext_loop_done ; NO - abort 690 bra comm_set_ctext_loop_done ; NO - abort
731 movff RCREG1,POSTINC2 ; store character 691 movff RCREG1,POSTINC2 ; store character
732 decfsz lo,F 692 decfsz lo,F
733 bra comm_set_ctext_loop 693 bra comm_set_ctext_loop
734 comm_set_ctext_loop_done: 694 comm_set_ctext_loop_done:
746 ; 706 ;
747 707
748 comm_identify: 708 comm_identify:
749 movlw "i" ; send echo 709 movlw "i" ; send echo
750 movwf TXREG1 710 movwf TXREG1
751 rcall comm_write_byte ; wait for UART 711 rcall comm_write_byte ; wait for completion of transmit
752 712
753 ;---- Read serial from internal EEPROM address 0000 713 ;---- Read serial from internal EEPROM address 0000
754 clrf EEADRH 714 clrf EEADRH
755 clrf EEADR ; get serial number LOW 715 clrf EEADR ; get serial number LOW
756 call read_eeprom ; read byte 716 call read_eeprom ; read byte
759 call read_eeprom ; read byte 719 call read_eeprom ; read byte
760 movff EEDATA,hi 720 movff EEDATA,hi
761 721
762 ;---- Emit serial number 722 ;---- Emit serial number
763 movff lo,TXREG1 723 movff lo,TXREG1
764 rcall comm_write_byte 724 rcall comm_write_byte ; wait for completion of transmit
765 movff hi,TXREG1 725 movff hi,TXREG1
766 rcall comm_write_byte 726 rcall comm_write_byte ; wait for completion of transmit
767 727
768 ;---- Emit firmware hi.lo 728 ;---- Emit firmware hi.lo
769 movlw softwareversion_x 729 movlw softwareversion_x
770 movwf TXREG1 730 movwf TXREG1
771 rcall comm_write_byte 731 rcall comm_write_byte ; wait for completion of transmit
772 movlw softwareversion_y 732 movlw softwareversion_y
773 movwf TXREG1 733 movwf TXREG1
774 rcall comm_write_byte 734 rcall comm_write_byte ; wait for completion of transmit
775 735
776 ;---- Emit custom text 736 ;---- Emit custom text
777 movlw opt_name_length 737 movlw opt_name_length
778 movwf hi 738 movwf hi
779 lfsr FSR2,opt_name 739 lfsr FSR2,opt_name
780 740
781 common_identify_loop: 741 common_identify_loop:
782 movff POSTINC2,TXREG1 742 movff POSTINC2,TXREG1
783 rcall comm_write_byte 743 rcall comm_write_byte ; wait for completion of transmit
784 decfsz hi,F 744 decfsz hi,F
785 bra common_identify_loop 745 bra common_identify_loop
786 746
787 bra comm_download_mode0 ; done 747 bra comm_download_mode0 ; done
788 748
789 ;----------------------------------------------------------------------------- 749 ;-----------------------------------------------------------------------------
790 750
791 comm_get_byte: 751 comm_get_byte:
792 goto rs232_get_byte ; ... and return 752 goto rs232_get_byte ; ... and return
793 753
794 comm_write_byte: 754 comm_write_byte: ; wait for completion of transmit
795 goto rs232_wait_tx ; ... and return 755 goto rs232_wait_tx ; ... and return
756
796 757
797 ;----------------------------------------------------------------------------- 758 ;-----------------------------------------------------------------------------
798 ; Reply hardware descriptor byte 759 ; Reply hardware descriptor byte
799 ; 760 ;
800
801 comm_hardware_descriptor: 761 comm_hardware_descriptor:
802 movlw "j" ; send echo 762 movlw "j" ; prepare echo
803 movwf TXREG1 763 movwf TXREG1 ; send echo
804 rcall comm_write_byte ; wait for UART 764 rcall comm_write_byte ; wait for completion of transmit
805 movff hardware_flag1,TXREG1 765
766 movf HW_descriptor,W ; get hardware descriptor
767 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software
768 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software
769 movwf TXREG1 ; send hardware descriptor
770
806 bra comm_download_mode0 ; done 771 bra comm_download_mode0 ; done
807 772
808 comm_feature_and_hardware: 773 comm_feature_and_hardware:
809 movlw 0x60 ; send echo 774 movlw 0x60 ; send echo
810 movwf TXREG1 775 movwf TXREG1
811 rcall comm_write_byte ; wait for UART 776 rcall comm_write_byte ; wait for completion of transmit
777
812 movlw 0x00 ; hardware high byte 778 movlw 0x00 ; hardware high byte
813 movwf TXREG1 779 movwf TXREG1
814 rcall comm_write_byte ; wait for UART 780 rcall comm_write_byte ; wait for completion of transmit
815 movff hardware_flag1,TXREG1 781
816 rcall comm_write_byte ; wait for UART 782 movf HW_descriptor,W ; get hardware descriptor
783 bcf WREG,6 ; clear bit 6 for reason of compatibility with 3rd party software
784 bcf WREG,7 ; clear bit 7 for reason of compatibility with 3rd party software
785 movwf TXREG1 ; send hardware descriptor
786 rcall comm_write_byte ; wait for completion of transmit
787
817 movlw 0x00 ; feature high Byte 788 movlw 0x00 ; feature high Byte
818 movwf TXREG1 789 movwf TXREG1
819 rcall comm_write_byte ; wait for UART 790 rcall comm_write_byte ; wait for completion of transmit
791
820 movlw 0x00 ; feature low Byte 792 movlw 0x00 ; feature low Byte
821 movwf TXREG1 793 movwf TXREG1
822 rcall comm_write_byte ; wait for UART 794 rcall comm_write_byte ; wait for completion of transmit
795
823 movlw 0x00 ; model descriptor byte 796 movlw 0x00 ; model descriptor byte
824 movwf TXREG1 797 movwf TXREG1
798
825 bra comm_download_mode0 ; done 799 bra comm_download_mode0 ; done
826
827 ;-----------------------------------------------------------------------------
828
829 IFDEF _rx_function
830
831 comm_update_ostc_rx:
832 movlw 0x70 ; send echo
833 movwf TXREG1
834 rcall comm_write_byte ; wait for UART
835 ; btfss ostc_rx_present ; rx model?
836 ; bra comm_download_mode0 ; NO - abort
837
838 ; Setup ext_flash_address:3
839 movlw LOW 0x3D0800
840 movwf ext_flash_address+0
841 movlw HIGH (0x3D0800 & 0xFFFF) ; <- & 0xFFFF to suppress warning message...
842 movwf ext_flash_address+1
843 movlw UPPER 0x3D0800
844 movwf ext_flash_address+2
845
846 bsf active_reset_ostc_rx
847 WAITMS .5
848 bcf active_reset_ostc_rx
849 WAITMS .100
850 bcf INTCON,GIE ; halt all interrupts
851
852 movlw LOW .992
853 movwf uart1_temp
854 movlw HIGH .992
855 movwf uart2_temp
856 incf uart2_temp,F ; ++1
857 WAITMS .1
858
859 call ext_flash_read_block_start
860 movwf up ; first byte to write
861
862 comm_update_ostc_rx_loop: ; (run 992 times)
863 WIN_SMALL comm_status4_column, comm_status4_row
864 movff uart1_temp,xA+0
865 movf uart2_temp,W
866 tstfsz uart2_temp
867 decf uart2_temp,W ; --1 for display
868 movwf xA+1
869 movlw .64
870 movwf xB+0
871 clrf xB+1
872 call mult16x16 ; xA * xB = xC
873 movff xC+0,lo
874 movff xC+1,hi
875 bsf leftbind
876 output_16
877 bcf leftbind
878 STRCAT_PRINT " Bytes left "
879
880 call I2C_update_OSTC_rx ; send firmware from external memory 3D0800h -> 3DFFFFh to OSTC RX circuity
881
882 tstfsz WREG ; returns with WREG=0 if everything was ok
883 bra comm_update_ostc_rx_loop_error ; error -> abort
884
885 decfsz uart1_temp,F
886 bra comm_update_ostc_rx_loop
887 decfsz uart2_temp,F
888 bra comm_update_ostc_rx_loop
889
890 comm_update_ostc_rx_loop_done:
891 call ext_flash_read_block_stop
892 bsf INTCON,GIE
893 WIN_SMALL comm_status4_column, comm_status4_row
894 STRCPY_PRINT " "
895 bra comm_download_mode0 ; done
896
897 comm_update_ostc_rx_loop_error:
898 bsf INTCON,GIE
899 WIN_SMALL comm_status4_column, comm_status4_row
900 STRCPY_PRINT "ERROR. Retry! "
901 call wait_1s ; do not use for time critical routines, can be between 0 and 1 sec!
902 call wait_1s ; do not use for time critical routines, can be between 0 and 1 sec!
903 call wait_1s ; do not use for time critical routines, can be between 0 and 1 sec!
904 bra comm_update_ostc_rx_loop_done
905
906 ENDIF
907 800
908 ;----------------------------------------------------------------------------- 801 ;-----------------------------------------------------------------------------
909 802
910 comm_send_dive: 803 comm_send_dive:
911 movlw "f"; 0x66 ; send echo 804 movlw "f"; 0x66 ; send echo
912 movwf TXREG1 805 movwf TXREG1
913 806
914 rcall comm_get_byte 807 rcall comm_get_byte
915 btfsc rs232_receive_overflow ; got byte? 808 btfsc rs232_rx_timeout ; got byte?
916 bra comm_download_mode0 ; NO - abort! 809 bra comm_download_mode0 ; NO - abort!
917 movff RCREG1,lo ; store dive number (0-255) 810 movff RCREG1,lo ; store dive number (0-255)
918 ; First, send the header (again) 811 ; First, send the header (again)
919 ; set ext_flash_address:3 to TOC entry of this dive 812 ; set ext_flash_address:3 to TOC entry of this dive
920 ; 1st: 200000h-200FFFh -> lo=0 813 ; 1st: 200000h-200FFFh -> lo=0
963 bra comm_download_mode0 ; done, loop with timeout reset 856 bra comm_download_mode0 ; done, loop with timeout reset
964 857
965 comm_send_dive1: 858 comm_send_dive1:
966 ; Send header 859 ; Send header
967 clrf hi ; counter 860 clrf hi ; counter
968 rcall comm_write_byte ; wait for UART 861 rcall comm_write_byte ; wait for completion of transmit
969 call ext_flash_read_block_start ; 1st byte 862 call ext_flash_read_block_start ; 1st byte
970 movwf TXREG1 863 movwf TXREG1
971 bra comm_send_dive_header 864 bra comm_send_dive_header
972 comm_send_dive_header2: 865 comm_send_dive_header2:
973 call ext_flash_read_block ; read one byte 866 call ext_flash_read_block ; read one byte
974 movwf TXREG1 ; start new transmit 867 movwf TXREG1 ; start new transmit
975 comm_send_dive_header: 868 comm_send_dive_header:
976 rcall comm_write_byte ; wait for UART 869 rcall comm_write_byte ; wait for completion of transmit
977 decfsz hi,F 870 decfsz hi,F
978 bra comm_send_dive_header2 871 bra comm_send_dive_header2
979 call ext_flash_read_block_stop 872 call ext_flash_read_block_stop
980 873
981 ; Set address for profile 874 ; Set address for profile
988 881
989 ; Set address for short header/compact header, Byte 0 882 ; Set address for short header/compact header, Byte 0
990 883
991 comm_send_dive_profile: 884 comm_send_dive_profile:
992 call ext_flash_byte_read_plus_0x20 ; read one byte into ext_flash_rw, takes care of banking at 0x200000 885 call ext_flash_byte_read_plus_0x20 ; read one byte into ext_flash_rw, takes care of banking at 0x200000
993 rcall comm_write_byte ; wait for UART 886 rcall comm_write_byte ; wait for completion of transmit
994 movff ext_flash_rw,TXREG1 ; send a byte 887 movff ext_flash_rw,TXREG1 ; send a byte
995 888
996 ; 24bit compare with end address 889 ; 24bit compare with end address
997 movff ext_flash_end_pointer+0,WREG 890 movff ext_flash_end_pointer+0,WREG
998 cpfseq ext_flash_address+0 891 cpfseq ext_flash_address+0
1002 bra comm_send_dive_profile 895 bra comm_send_dive_profile
1003 movff ext_flash_end_pointer+2,WREG 896 movff ext_flash_end_pointer+2,WREG
1004 cpfseq ext_flash_address+2 897 cpfseq ext_flash_address+2
1005 bra comm_send_dive_profile 898 bra comm_send_dive_profile
1006 899
1007 rcall comm_write_byte ; wait for UART 900 rcall comm_write_byte ; wait for completion of transmit
1008 bra comm_download_mode0 ; done, loop with timeout reset 901 bra comm_download_mode0 ; done, loop with timeout reset
1009 902
1010 ;----------------------------------------------------------------------------- 903 ;-----------------------------------------------------------------------------
1011 904
1012 comm_read_setting: 905 comm_read_setting:
1013 movlw "r" 906 movlw "r"
1014 movwf TXREG1 907 movwf TXREG1
1015 rcall comm_get_byte 908 rcall comm_get_byte
1016 btfsc rs232_receive_overflow ; got byte? 909 btfsc rs232_rx_timeout ; got byte?
1017 bra comm_read_abort ; NO - abort! 910 bra comm_read_abort ; NO - abort
1018 rcall comm_write_byte ; wait for UART 911 rcall comm_write_byte ; wait for completion of transmit
1019 movlw 0x0F 912 movlw 0x0F
1020 cpfsgt RCREG1 ; 0x00-0x0F: unused 913 cpfsgt RCREG1 ; 0x00-0x0F: unused
1021 bra comm_read_abort ; abort! 914 bra comm_read_abort ; abort!
1022 subwf RCREG1,W ; subtract unused commands 915 subwf RCREG1,W ; subtract unused commands
1023 916
1073 dcfsnz WREG 966 dcfsnz WREG
1074 movff opt_dive_mode, TXREG1 ; RCREG1=0x20 967 movff opt_dive_mode, TXREG1 ; RCREG1=0x20
1075 dcfsnz WREG 968 dcfsnz WREG
1076 movff char_I_deco_model, TXREG1 ; RCREG1=0x21 969 movff char_I_deco_model, TXREG1 ; RCREG1=0x21
1077 dcfsnz WREG 970 dcfsnz WREG
1078 movff char_I_ppO2_max, TXREG1 ; RCREG1=0x22 971 movff char_I_ppO2_max_work, TXREG1 ; RCREG1=0x22
1079 dcfsnz WREG 972 dcfsnz WREG
1080 movff char_I_ppO2_min, TXREG1 ; RCREG1=0x23 973 movff char_I_ppO2_min, TXREG1 ; RCREG1=0x23
1081 dcfsnz WREG 974 dcfsnz WREG
1082 movff char_I_extra_time, TXREG1 ; RCREG1=0x24 975 movff char_I_extra_time, TXREG1 ; RCREG1=0x24
1083 dcfsnz WREG 976 dcfsnz WREG
1125 dcfsnz WREG 1018 dcfsnz WREG
1126 movff opt_cR_button_left, TXREG1 ; RCREG1=0x3A 1019 movff opt_cR_button_left, TXREG1 ; RCREG1=0x3A
1127 dcfsnz WREG 1020 dcfsnz WREG
1128 movff opt_cR_button_right, TXREG1 ; RCREG1=0x3B 1021 movff opt_cR_button_right, TXREG1 ; RCREG1=0x3B
1129 dcfsnz WREG 1022 dcfsnz WREG
1130 movff char_I_bottom_usage, TXREG1 ; RCREG1=0x3C 1023 movff char_I_SAC_work, TXREG1 ; RCREG1=0x3C
1131 dcfsnz WREG 1024 dcfsnz WREG
1132 movff char_I_deco_usage, TXREG1 ; RCREG1=0x3D 1025 movff char_I_SAC_deco, TXREG1 ; RCREG1=0x3D
1133 dcfsnz WREG 1026 dcfsnz WREG
1134 movff opt_modwarning, TXREG1 ; RCREG1=0x3E 1027 movff opt_modwarning, TXREG1 ; RCREG1=0x3E
1135 dcfsnz WREG 1028 dcfsnz WREG
1136 movff opt_vsitextv2, TXREG1 ; RCREG1=0x3F 1029 movff opt_vsitextv2, TXREG1 ; RCREG1=0x3F
1137 dcfsnz WREG 1030 dcfsnz WREG
1138 movff opt_vsigraph, TXREG1 ; RCREG1=0x40 1031 movff opt_vsigraph, TXREG1 ; RCREG1=0x40
1139 dcfsnz WREG 1032 dcfsnz WREG
1140 movff opt_showppo2, TXREG1 ; RCREG1=0x41 1033 movff opt_showppo2, TXREG1 ; RCREG1=0x41, always show ppO2
1141 dcfsnz WREG 1034 dcfsnz WREG
1142 movff opt_temperature_adjust, TXREG1 ; RCREG1=0x42 1035 movff opt_temperature_adjust, TXREG1 ; RCREG1=0x42
1143 dcfsnz WREG 1036 dcfsnz WREG
1144 movff opt_safety_stop_length, TXREG1 ; RCREG1=0x43 1037 movff opt_safety_stop_length, TXREG1 ; RCREG1=0x43
1145 dcfsnz WREG 1038 dcfsnz WREG
1161 dcfsnz WREG 1054 dcfsnz WREG
1162 movff char_I_ppO2_max_deco, TXREG1 ; RCREG1=0x4C 1055 movff char_I_ppO2_max_deco, TXREG1 ; RCREG1=0x4C
1163 dcfsnz WREG 1056 dcfsnz WREG
1164 movff char_I_ppO2_min_loop, TXREG1 ; RCREG1=0x4D 1057 movff char_I_ppO2_min_loop, TXREG1 ; RCREG1=0x4D
1165 dcfsnz WREG 1058 dcfsnz WREG
1166 movff char_I_tank_size+0, TXREG1 ; RCREG1=0x4E 1059 movff char_I_gas_avail_size+0, TXREG1 ; RCREG1=0x4E
1167 dcfsnz WREG 1060 dcfsnz WREG
1168 movff char_I_tank_size+1, TXREG1 ; RCREG1=0x4F 1061 movff char_I_gas_avail_size+1, TXREG1 ; RCREG1=0x4F
1169 dcfsnz WREG 1062 dcfsnz WREG
1170 movff char_I_tank_size+2, TXREG1 ; RCREG1=0x50 1063 movff char_I_gas_avail_size+2, TXREG1 ; RCREG1=0x50
1171 dcfsnz WREG 1064 dcfsnz WREG
1172 movff char_I_tank_size+3, TXREG1 ; RCREG1=0x51 1065 movff char_I_gas_avail_size+3, TXREG1 ; RCREG1=0x51
1173 dcfsnz WREG 1066 dcfsnz WREG
1174 movff char_I_tank_size+4, TXREG1 ; RCREG1=0x52 1067 movff char_I_gas_avail_size+4, TXREG1 ; RCREG1=0x52
1175 dcfsnz WREG 1068 dcfsnz WREG
1176 movff char_I_tank_pres_fill+0, TXREG1 ; RCREG1=0x53 1069 movff char_I_gas_avail_pres+0, TXREG1 ; RCREG1=0x53
1177 dcfsnz WREG 1070 dcfsnz WREG
1178 movff char_I_tank_pres_fill+1, TXREG1 ; RCREG1=0x54 1071 movff char_I_gas_avail_pres+1, TXREG1 ; RCREG1=0x54
1179 dcfsnz WREG 1072 dcfsnz WREG
1180 movff char_I_tank_pres_fill+2, TXREG1 ; RCREG1=0x55 1073 movff char_I_gas_avail_pres+2, TXREG1 ; RCREG1=0x55
1181 dcfsnz WREG 1074 dcfsnz WREG
1182 movff char_I_tank_pres_fill+3, TXREG1 ; RCREG1=0x56 1075 movff char_I_gas_avail_pres+3, TXREG1 ; RCREG1=0x56
1183 dcfsnz WREG 1076 dcfsnz WREG
1184 movff char_I_tank_pres_fill+4, TXREG1 ; RCREG1=0x57 1077 movff char_I_gas_avail_pres+4, TXREG1 ; RCREG1=0x57
1185 dcfsnz WREG 1078 dcfsnz WREG
1186 movff char_I_cc_max_frac_o2, TXREG1 ; RCREG1=0x58 1079 movff char_I_CC_max_frac_O2, TXREG1 ; RCREG1=0x58
1187 dcfsnz WREG 1080 dcfsnz WREG
1188 movff opt_sim_setpoint_number, TXREG1 ; RCREG1=0x59 1081 movff opt_sim_setpoint_number, TXREG1 ; RCREG1=0x59
1189 dcfsnz WREG 1082 dcfsnz WREG
1190 movff opt_calc_asc_gasvolume, TXREG1 ; RCREG1=0x5A 1083 movff opt_calc_asc_gasvolume, TXREG1 ; RCREG1=0x5A
1191 dcfsnz WREG 1084 dcfsnz WREG
1237 dcfsnz WREG 1130 dcfsnz WREG
1238 movff opt_transmitter_id_10+0, TXREG1 ; RCREG1=0x72 1131 movff opt_transmitter_id_10+0, TXREG1 ; RCREG1=0x72
1239 dcfsnz WREG 1132 dcfsnz WREG
1240 movff opt_transmitter_id_10+1, TXREG1 ; RCREG1=0x73 1133 movff opt_transmitter_id_10+1, TXREG1 ; RCREG1=0x73
1241 dcfsnz WREG 1134 dcfsnz WREG
1242 movff char_I_tank_size+5, TXREG1 ; RCREG1=0x74 1135 movff char_I_gas_avail_size+5, TXREG1 ; RCREG1=0x74
1243 dcfsnz WREG 1136 dcfsnz WREG
1244 movff char_I_tank_size+6, TXREG1 ; RCREG1=0x75 1137 movff char_I_gas_avail_size+6, TXREG1 ; RCREG1=0x75
1245 dcfsnz WREG 1138 dcfsnz WREG
1246 movff char_I_tank_size+7, TXREG1 ; RCREG1=0x76 1139 movff char_I_gas_avail_size+7, TXREG1 ; RCREG1=0x76
1247 dcfsnz WREG 1140 dcfsnz WREG
1248 movff char_I_tank_size+8, TXREG1 ; RCREG1=0x77 1141 movff char_I_gas_avail_size+8, TXREG1 ; RCREG1=0x77
1249 dcfsnz WREG 1142 dcfsnz WREG
1250 movff char_I_tank_size+9, TXREG1 ; RCREG1=0x78 1143 movff char_I_gas_avail_size+9, TXREG1 ; RCREG1=0x78
1251 dcfsnz WREG 1144 dcfsnz WREG
1252 movff char_I_tank_pres_fill+5, TXREG1 ; RCREG1=0x79 1145 movff char_I_gas_avail_pres+5, TXREG1 ; RCREG1=0x79
1253 dcfsnz WREG 1146 dcfsnz WREG
1254 movff char_I_tank_pres_fill+6, TXREG1 ; RCREG1=0x7A 1147 movff char_I_gas_avail_pres+6, TXREG1 ; RCREG1=0x7A
1255 dcfsnz WREG 1148 dcfsnz WREG
1256 movff char_I_tank_pres_fill+7, TXREG1 ; RCREG1=0x7B 1149 movff char_I_gas_avail_pres+7, TXREG1 ; RCREG1=0x7B
1257 dcfsnz WREG 1150 dcfsnz WREG
1258 movff char_I_tank_pres_fill+8, TXREG1 ; RCREG1=0x7C 1151 movff char_I_gas_avail_pres+8, TXREG1 ; RCREG1=0x7C
1259 dcfsnz WREG 1152 dcfsnz WREG
1260 movff char_I_tank_pres_fill+9, TXREG1 ; RCREG1=0x7D 1153 movff char_I_gas_avail_pres+9, TXREG1 ; RCREG1=0x7D
1261 dcfsnz WREG 1154 dcfsnz WREG
1262 movff opt_TR_mode, TXREG1 ; RCREG1=0x7E 1155 movff opt_TR_mode, TXREG1 ; RCREG1=0x7E
1263 dcfsnz WREG 1156 dcfsnz WREG
1264 movff opt_TR_1st_pres, TXREG1 ; RCREG1=0x7F 1157 movff opt_TR_1st_pres, TXREG1 ; RCREG1=0x7F
1265 dcfsnz WREG 1158 dcfsnz WREG
1272 movff opt_ZfactorUse, TXREG1 ; RCREG1=0x83 1165 movff opt_ZfactorUse, TXREG1 ; RCREG1=0x83
1273 dcfsnz WREG 1166 dcfsnz WREG
1274 movff opt_ZfactorTemp, TXREG1 ; RCREG1=0x84 1167 movff opt_ZfactorTemp, TXREG1 ; RCREG1=0x84
1275 dcfsnz WREG 1168 dcfsnz WREG
1276 movff opt_2ndDepthDisp, TXREG1 ; RCREG1=0x85 1169 movff opt_2ndDepthDisp, TXREG1 ; RCREG1=0x85
1170 dcfsnz WREG
1171 movff opt_max_depth, TXREG1 ; RCREG1=0x86
1172 dcfsnz WREG
1173 movff char_I_descent_speed, TXREG1 ; RCREG1=0x87
1174 dcfsnz WREG
1175 movff opt_store_apnoe_dive, TXREG1 ; RCREG1=0x88
1176 dcfsnz WREG
1177 movff opt_tissue_graphics, TXREG1 ; RCREG1=0x89
1178 dcfsnz WREG
1179 movff opt_layout, TXREG1 ; RCREG1=0x90
1180 dcfsnz WREG
1181 movff opt_extended_stops, TXREG1 ; RCREG1=0x91
1277 1182
1278 comm_read_abort: 1183 comm_read_abort:
1279 comm_read_done: 1184 comm_read_done:
1280 bra comm_download_mode0 ; done, loop with timeout reset 1185 bra comm_download_mode0 ; done, loop with timeout reset
1281 1186
1294 1199
1295 comm_read_gas_dil: 1200 comm_read_gas_dil:
1296 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays 1201 lfsr FSR0,opt_gas_O2_ratio ; load base address of gas data arrays
1297 movf up,W ; load index (0-9) of gas/dil into WREG, addressing O2 ratio 1202 movf up,W ; load index (0-9) of gas/dil into WREG, addressing O2 ratio
1298 movff PLUSW0, TXREG1 ; transmit O2 ratio 1203 movff PLUSW0, TXREG1 ; transmit O2 ratio
1299 rcall comm_write_byte ; wait for UART 1204 rcall comm_write_byte ; wait for completion of transmit
1300 addlw .10 ; increment index by 10, addressing He ratio now 1205 addlw .10 ; increment index by 10, addressing He ratio now
1301 movff PLUSW0, TXREG1 ; transmit He ratio 1206 movff PLUSW0, TXREG1 ; transmit He ratio
1302 rcall comm_write_byte ; wait for UART 1207 rcall comm_write_byte ; wait for completion of transmit
1303 addlw .10 ; increment index by 10, addressing gas/dil type now 1208 addlw .10 ; increment index by 10, addressing gas/dil type now
1304 movff PLUSW0, TXREG1 ; transmit gas/dil type 1209 movff PLUSW0, TXREG1 ; transmit gas/dil type
1305 rcall comm_write_byte ; wait for UART 1210 rcall comm_write_byte ; wait for completion of transmit
1306 addlw .10 ; increment index by 10, addressing change depth now 1211 addlw .10 ; increment index by 10, addressing change depth now
1307 movff PLUSW0,TXREG1 ; transmit change depth 1212 movff PLUSW0,TXREG1 ; transmit change depth
1308 bra comm_read_done ; done, wait for UART and loop with timeout reset 1213 bra comm_read_done ; done, wait for UART and loop with timeout reset
1309 1214
1310 1215
1311 ; Memory map is as follows: 1216 ; Memory map is as follows:
1312 ; ------------------------- 1217 ; -------------------------
1313 ; char_I_setpoint_cbar res 5 ; setpoints in cbar 1218 ; opt_setpoint_cbar res 5 ; setpoints in cbar
1314 ; char_I_setpoint_change res 5 ; change depth for the setpoints in meter 1219 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter
1315 1220
1316 comm_read_sp: 1221 comm_read_sp:
1317 lfsr FSR0,char_I_setpoint_cbar ; load base address of setpoint cbar values 1222 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values
1318 movf up,W ; load index (0-4) of setpoint into WREG, addressing cbar value 1223 movf up,W ; load index (0-4) of setpoint into WREG, addressing cbar value
1319 movff PLUSW0, TXREG1 ; transmit setpoint cbar value 1224 movff PLUSW0, TXREG1 ; transmit setpoint cbar value
1320 rcall comm_write_byte ; wait for UART 1225 rcall comm_write_byte ; wait for completion of transmit
1321 addlw .5 ; increment index by 5, addressing change depth now 1226 addlw .5 ; increment index by 5, addressing change depth now
1322 movff PLUSW0, TXREG1 ; transmit change depth 1227 movff PLUSW0, TXREG1 ; transmit change depth
1323 bra comm_read_done ; done, wait for UART and loop with timeout reset 1228 bra comm_read_done ; done, wait for UART and loop with timeout reset
1324 1229
1325 ;----------------------------------------------------------------------------- 1230 ;-----------------------------------------------------------------------------
1326 1231
1327 comm_write_setting: 1232 comm_write_setting:
1328 movlw "w" 1233 movlw "w"
1329 movwf TXREG1 1234 movwf TXREG1
1330 rcall comm_get_byte ; "Byte 2" 1235 rcall comm_get_byte ; "Byte 2"
1331 btfsc rs232_receive_overflow ; got byte? 1236 btfsc rs232_rx_timeout ; got a byte?
1332 bra comm_write_abort ; NO - abort! 1237 bra comm_write_abort ; NO - abort
1333 movff RCREG1,lo ; copy 1238 movff RCREG1,lo ; copy
1334 rcall comm_get_byte ; "Byte 3" 1239 rcall comm_get_byte ; "Byte 3"
1335 rcall comm_write_byte ; wait for UART 1240 rcall comm_write_byte ; wait for completion of transmit
1336 movlw 0x0F 1241 movlw 0x0F
1337 cpfsgt lo ; 0x00-0x0F: unused 1242 cpfsgt lo ; 0x00-0x0F: unused
1338 bra comm_write_abort ; abort! 1243 bra comm_write_abort ; abort!
1339 subwf lo,W ; subtract unused commands 1244 subwf lo,W ; subtract unused commands
1340 1245
1390 dcfsnz WREG 1295 dcfsnz WREG
1391 movff RCREG1, opt_dive_mode ; RCREG1=0x20 1296 movff RCREG1, opt_dive_mode ; RCREG1=0x20
1392 dcfsnz WREG 1297 dcfsnz WREG
1393 movff RCREG1, char_I_deco_model ; RCREG1=0x21 1298 movff RCREG1, char_I_deco_model ; RCREG1=0x21
1394 dcfsnz WREG 1299 dcfsnz WREG
1395 movff RCREG1, char_I_ppO2_max ; RCREG1=0x22 1300 movff RCREG1, char_I_ppO2_max_work ; RCREG1=0x22
1396 dcfsnz WREG 1301 dcfsnz WREG
1397 movff RCREG1, char_I_ppO2_min ; RCREG1=0x23 1302 movff RCREG1, char_I_ppO2_min ; RCREG1=0x23
1398 dcfsnz WREG 1303 dcfsnz WREG
1399 movff RCREG1, char_I_extra_time ; RCREG1=0x24 1304 movff RCREG1, char_I_extra_time ; RCREG1=0x24
1400 dcfsnz WREG 1305 dcfsnz WREG
1442 dcfsnz WREG 1347 dcfsnz WREG
1443 movff RCREG1, opt_cR_button_left ; RCREG1=0x3A 1348 movff RCREG1, opt_cR_button_left ; RCREG1=0x3A
1444 dcfsnz WREG 1349 dcfsnz WREG
1445 movff RCREG1, opt_cR_button_right ; RCREG1=0x3B 1350 movff RCREG1, opt_cR_button_right ; RCREG1=0x3B
1446 dcfsnz WREG 1351 dcfsnz WREG
1447 movff RCREG1, char_I_bottom_usage ; RCREG1=0x3C 1352 movff RCREG1, char_I_SAC_work ; RCREG1=0x3C
1448 dcfsnz WREG 1353 dcfsnz WREG
1449 movff RCREG1, char_I_deco_usage ; RCREG1=0x3D 1354 movff RCREG1, char_I_SAC_deco ; RCREG1=0x3D
1450 dcfsnz WREG 1355 dcfsnz WREG
1451 movff RCREG1, opt_modwarning ; RCREG1=0x3E 1356 movff RCREG1, opt_modwarning ; RCREG1=0x3E
1452 dcfsnz WREG 1357 dcfsnz WREG
1453 movff RCREG1, opt_vsitextv2 ; RCREG1=0x3F 1358 movff RCREG1, opt_vsitextv2 ; RCREG1=0x3F
1454 dcfsnz WREG 1359 dcfsnz WREG
1455 movff RCREG1, opt_vsigraph ; RCREG1=0x40 1360 movff RCREG1, opt_vsigraph ; RCREG1=0x40
1456 dcfsnz WREG 1361 dcfsnz WREG
1457 movff RCREG1, opt_showppo2 ; RCREG1=0x41 1362 movff RCREG1, opt_showppo2 ; RCREG1=0x41, always show ppO2
1458 dcfsnz WREG 1363 dcfsnz WREG
1459 movff RCREG1, opt_temperature_adjust ; RCREG1=0x42 1364 movff RCREG1, opt_temperature_adjust ; RCREG1=0x42
1460 dcfsnz WREG 1365 dcfsnz WREG
1461 movff RCREG1, opt_safety_stop_length ; RCREG1=0x43 1366 movff RCREG1, opt_safety_stop_length ; RCREG1=0x43
1462 dcfsnz WREG 1367 dcfsnz WREG
1478 dcfsnz WREG 1383 dcfsnz WREG
1479 movff RCREG1, char_I_ppO2_max_deco ; RCREG1=0x4C 1384 movff RCREG1, char_I_ppO2_max_deco ; RCREG1=0x4C
1480 dcfsnz WREG 1385 dcfsnz WREG
1481 movff RCREG1, char_I_ppO2_min_loop ; RCREG1=0x4D 1386 movff RCREG1, char_I_ppO2_min_loop ; RCREG1=0x4D
1482 dcfsnz WREG 1387 dcfsnz WREG
1483 movff RCREG1, char_I_tank_size+0 ; RCREG1=0x4E 1388 movff RCREG1, char_I_gas_avail_size+0 ; RCREG1=0x4E
1484 dcfsnz WREG 1389 dcfsnz WREG
1485 movff RCREG1, char_I_tank_size+1 ; RCREG1=0x4F 1390 movff RCREG1, char_I_gas_avail_size+1 ; RCREG1=0x4F
1486 dcfsnz WREG 1391 dcfsnz WREG
1487 movff RCREG1, char_I_tank_size+2 ; RCREG1=0x50 1392 movff RCREG1, char_I_gas_avail_size+2 ; RCREG1=0x50
1488 dcfsnz WREG 1393 dcfsnz WREG
1489 movff RCREG1, char_I_tank_size+3 ; RCREG1=0x51 1394 movff RCREG1, char_I_gas_avail_size+3 ; RCREG1=0x51
1490 dcfsnz WREG 1395 dcfsnz WREG
1491 movff RCREG1, char_I_tank_size+4 ; RCREG1=0x52 1396 movff RCREG1, char_I_gas_avail_size+4 ; RCREG1=0x52
1492 dcfsnz WREG 1397 dcfsnz WREG
1493 movff RCREG1, char_I_tank_pres_fill+0 ; RCREG1=0x53 1398 movff RCREG1, char_I_gas_avail_pres+0 ; RCREG1=0x53
1494 dcfsnz WREG 1399 dcfsnz WREG
1495 movff RCREG1, char_I_tank_pres_fill+1 ; RCREG1=0x54 1400 movff RCREG1, char_I_gas_avail_pres+1 ; RCREG1=0x54
1496 dcfsnz WREG 1401 dcfsnz WREG
1497 movff RCREG1, char_I_tank_pres_fill+2 ; RCREG1=0x55 1402 movff RCREG1, char_I_gas_avail_pres+2 ; RCREG1=0x55
1498 dcfsnz WREG 1403 dcfsnz WREG
1499 movff RCREG1, char_I_tank_pres_fill+3 ; RCREG1=0x56 1404 movff RCREG1, char_I_gas_avail_pres+3 ; RCREG1=0x56
1500 dcfsnz WREG 1405 dcfsnz WREG
1501 movff RCREG1, char_I_tank_pres_fill+4 ; RCREG1=0x57 1406 movff RCREG1, char_I_gas_avail_pres+4 ; RCREG1=0x57
1502 dcfsnz WREG 1407 dcfsnz WREG
1503 movff RCREG1, char_I_cc_max_frac_o2 ; RCREG1=0x58 1408 movff RCREG1, char_I_CC_max_frac_O2 ; RCREG1=0x58
1504 dcfsnz WREG 1409 dcfsnz WREG
1505 movff RCREG1, opt_sim_setpoint_number ; RCREG1=0x59 1410 movff RCREG1, opt_sim_setpoint_number ; RCREG1=0x59
1506 dcfsnz WREG 1411 dcfsnz WREG
1507 movff RCREG1, opt_calc_asc_gasvolume ; RCREG1=0x5A 1412 movff RCREG1, opt_calc_asc_gasvolume ; RCREG1=0x5A
1508 dcfsnz WREG 1413 dcfsnz WREG
1554 dcfsnz WREG 1459 dcfsnz WREG
1555 movff RCREG1, opt_transmitter_id_10+0 ; RCREG1=0x72 1460 movff RCREG1, opt_transmitter_id_10+0 ; RCREG1=0x72
1556 dcfsnz WREG 1461 dcfsnz WREG
1557 movff RCREG1, opt_transmitter_id_10+1 ; RCREG1=0x73 1462 movff RCREG1, opt_transmitter_id_10+1 ; RCREG1=0x73
1558 dcfsnz WREG 1463 dcfsnz WREG
1559 movff RCREG1, char_I_tank_size+5 ; RCREG1=0x74 1464 movff RCREG1, char_I_gas_avail_size+5 ; RCREG1=0x74
1560 dcfsnz WREG 1465 dcfsnz WREG
1561 movff RCREG1, char_I_tank_size+6 ; RCREG1=0x75 1466 movff RCREG1, char_I_gas_avail_size+6 ; RCREG1=0x75
1562 dcfsnz WREG 1467 dcfsnz WREG
1563 movff RCREG1, char_I_tank_size+7 ; RCREG1=0x76 1468 movff RCREG1, char_I_gas_avail_size+7 ; RCREG1=0x76
1564 dcfsnz WREG 1469 dcfsnz WREG
1565 movff RCREG1, char_I_tank_size+8 ; RCREG1=0x77 1470 movff RCREG1, char_I_gas_avail_size+8 ; RCREG1=0x77
1566 dcfsnz WREG 1471 dcfsnz WREG
1567 movff RCREG1, char_I_tank_size+9 ; RCREG1=0x78 1472 movff RCREG1, char_I_gas_avail_size+9 ; RCREG1=0x78
1568 dcfsnz WREG 1473 dcfsnz WREG
1569 movff RCREG1, char_I_tank_pres_fill+5 ; RCREG1=0x79 1474 movff RCREG1, char_I_gas_avail_pres+5 ; RCREG1=0x79
1570 dcfsnz WREG 1475 dcfsnz WREG
1571 movff RCREG1, char_I_tank_pres_fill+6 ; RCREG1=0x7A 1476 movff RCREG1, char_I_gas_avail_pres+6 ; RCREG1=0x7A
1572 dcfsnz WREG 1477 dcfsnz WREG
1573 movff RCREG1, char_I_tank_pres_fill+7 ; RCREG1=0x7B 1478 movff RCREG1, char_I_gas_avail_pres+7 ; RCREG1=0x7B
1574 dcfsnz WREG 1479 dcfsnz WREG
1575 movff RCREG1, char_I_tank_pres_fill+8 ; RCREG1=0x7C 1480 movff RCREG1, char_I_gas_avail_pres+8 ; RCREG1=0x7C
1576 dcfsnz WREG 1481 dcfsnz WREG
1577 movff RCREG1, char_I_tank_pres_fill+9 ; RCREG1=0x7D 1482 movff RCREG1, char_I_gas_avail_pres+9 ; RCREG1=0x7D
1578 dcfsnz WREG 1483 dcfsnz WREG
1579 movff RCREG1, opt_TR_mode ; RCREG1=0x7E 1484 movff RCREG1, opt_TR_mode ; RCREG1=0x7E
1580 dcfsnz WREG 1485 dcfsnz WREG
1581 movff RCREG1, opt_TR_1st_pres ; RCREG1=0x7F 1486 movff RCREG1, opt_TR_1st_pres ; RCREG1=0x7F
1582 dcfsnz WREG 1487 dcfsnz WREG
1589 movff RCREG1, opt_ZfactorUse ; RCREG1=0x83 1494 movff RCREG1, opt_ZfactorUse ; RCREG1=0x83
1590 dcfsnz WREG 1495 dcfsnz WREG
1591 movff RCREG1, opt_ZfactorTemp ; RCREG1=0x84 1496 movff RCREG1, opt_ZfactorTemp ; RCREG1=0x84
1592 dcfsnz WREG 1497 dcfsnz WREG
1593 movff RCREG1, opt_2ndDepthDisp ; RCREG1=0x85 1498 movff RCREG1, opt_2ndDepthDisp ; RCREG1=0x85
1499 dcfsnz WREG
1500 movff RCREG1, opt_max_depth ; RCREG1=0x86
1501 dcfsnz WREG
1502 movff RCREG1, char_I_descent_speed ; RCREG1=0x87
1503 dcfsnz WREG
1504 movff RCREG1, opt_store_apnoe_dive ; RCREG1=0x88
1505 dcfsnz WREG
1506 movff RCREG1, opt_tissue_graphics ; RCREG1=0x89
1507 dcfsnz WREG
1508 movff RCREG1, opt_layout ; RCREG1=0x90
1509 dcfsnz WREG
1510 movff RCREG1, opt_extended_stops ; RCREG1=0x91
1511
1594 1512
1595 comm_write_abort: 1513 comm_write_abort:
1596 comm_write_done: 1514 comm_write_done:
1597 ; check options, gases and diluents 1515 ; check options, gases and diluents
1598 call option_check_all ; check all options (and reset if not within their min/max boundaries) 1516 call option_check_all ; check all options (and reset if not within their min/max boundaries)
1599 bsf FLAG_diluent_setup ; =1: setting up diluents
1600 call gaslist_cleanup_list ; take care that only one gas can be first and first has 0m change depth
1601 bcf FLAG_diluent_setup ; =1: Setting up diluents
1602 call gaslist_cleanup_list ; take care that only one gas can be first and first has 0m change depth
1603 call get_first_gas_to_WREG ; make sure at least one gas is "First"
1604 call get_first_dil_to_WREG ; make sure at least one diluent is "First"
1605 goto comm_download_mode0 ; done, loop with timeout reset 1517 goto comm_download_mode0 ; done, loop with timeout reset
1606 1518
1607 ;----------------------------------------------------------------------------- 1519 ;-----------------------------------------------------------------------------
1608 1520
1609 ; Memory map is as follows: 1521 ; Memory map is as follows:
1633 bra comm_write_done ; done, loop with timeout reset 1545 bra comm_write_done ; done, loop with timeout reset
1634 1546
1635 1547
1636 ; Memory map is as follows: 1548 ; Memory map is as follows:
1637 ; ------------------------- 1549 ; -------------------------
1638 ; char_I_setpoint_cbar res 5 ; setpoints in cbar 1550 ; opt_setpoint_cbar res 5 ; setpoints in cbar
1639 ; char_I_setpoint_change res 5 ; change depth for the setpoints in meter 1551 ; opt_setpoint_change res 5 ; change depth for the setpoints in meter
1640 1552
1641 comm_write_sp: 1553 comm_write_sp:
1642 lfsr FSR0,char_I_setpoint_cbar ; load base address of setpoint cbar values 1554 lfsr FSR0,opt_setpoint_cbar ; load base address of setpoint cbar values
1643 movf up,W ; load index (0-4) of setpoint into WREG, addressing cbar value 1555 movf up,W ; load index (0-4) of setpoint into WREG, addressing cbar value
1644 movff RCREG1,PLUSW0 ; receive setpoint cbar value 1556 movff RCREG1,PLUSW0 ; receive setpoint cbar value
1645 rcall comm_get_byte ; wait for UART 1557 rcall comm_get_byte ; wait for UART
1646 addlw .5 ; increment index by 5, addressing change depth now 1558 addlw .5 ; increment index by 5, addressing change depth now
1647 movff RCREG1,PLUSW0 ; receive change depth 1559 movff RCREG1,PLUSW0 ; receive change depth
1650 ;----------------------------------------------------------------------------- 1562 ;-----------------------------------------------------------------------------
1651 1563
1652 comm_send_string: 1564 comm_send_string:
1653 movlw "n" ; send echo 1565 movlw "n" ; send echo
1654 movwf TXREG1 1566 movwf TXREG1
1655 call comm_write_byte ; wait for UART 1567 call comm_write_byte ; wait for completion of transmit
1656 WIN_SMALL comm_string_column, comm_string_row 1568 WIN_SMALL comm_string_column, comm_string_row
1657 movlw .16 1569 movlw .16
1658 movwf lo ; counter 1570 movwf lo ; counter
1659 comm_send_string_loop: 1571 comm_send_string_loop:
1660 call comm_get_byte 1572 call comm_get_byte
1661 btfsc rs232_receive_overflow ; got byte? 1573 btfsc rs232_rx_timeout ; got a byte?
1662 bra comm_send_string_abort ; NO - abort! 1574 bra comm_send_string_abort ; NO - abort
1663 movff RCREG1,POSTINC2 ; store character 1575 movff RCREG1,POSTINC2 ; store character
1664 decfsz lo,F 1576 decfsz lo,F
1665 bra comm_send_string_loop 1577 bra comm_send_string_loop
1666 comm_send_string_abort: 1578 comm_send_string_abort:
1667 STRCAT_PRINT "" ; show the text 1579 STRCAT_PRINT "" ; show the text
1668 goto comm_download_mode0 ; done, loop with timeout reset 1580 goto comm_download_mode0 ; done, loop with timeout reset
1669 1581
1670 ;----------------------------------------------------------------------------- 1582 ;-----------------------------------------------------------------------------
1671
1672 comm_check_day:
1673 movff RCREG1,day
1674 movff month,lo ; new month
1675 dcfsnz lo,F
1676 movlw .31
1677 dcfsnz lo,F
1678 movlw .28
1679 dcfsnz lo,F
1680 movlw .31
1681 dcfsnz lo,F
1682 movlw .30
1683 dcfsnz lo,F
1684 movlw .31
1685 dcfsnz lo,F
1686 movlw .30
1687 dcfsnz lo,F
1688 movlw .31
1689 dcfsnz lo,F
1690 movlw .31
1691 dcfsnz lo,F
1692 movlw .30
1693 dcfsnz lo,F
1694 movlw .31
1695 dcfsnz lo,F
1696 movlw .30
1697 dcfsnz lo,F
1698 movlw .31
1699 cpfsgt day ; day ok?
1700 return ; YES
1701 movlw .1 ; NO - set to 1st
1702 movwf day
1703 return
1704 1583
1705 comm_write_button_polarity: 1584 comm_write_button_polarity:
1706 ; store RCREG1 into EEPROM .897 1585 ; store RCREG1 into EEPROM .897
1707 movlw LOW .897 1586 movlw LOW .897
1708 movwf EEADR 1587 movwf EEADR