0
|
1
|
|
2 ; OSTC - diving computer code
|
|
3 ; Copyright (C) 2008 HeinrichsWeikamp GbR
|
|
4
|
|
5 ; This program is free software: you can redistribute it and/or modify
|
|
6 ; it under the terms of the GNU General Public License as published by
|
|
7 ; the Free Software Foundation, either version 3 of the License, or
|
|
8 ; (at your option) any later version.
|
|
9
|
|
10 ; This program is distributed in the hope that it will be useful,
|
|
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 ; GNU General Public License for more details.
|
|
14
|
|
15 ; You should have received a copy of the GNU General Public License
|
|
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
|
18
|
|
19 ; Interface, Downloader, MD2 Hash send routine
|
|
20 ; written by: Matthias Heinrichs, info@heinrichsweikamp.com
|
|
21 ; written: 10/30/05
|
|
22 ; last updated: 12/27/07
|
|
23 ; known bugs:
|
|
24 ; ToDo:
|
|
25
|
|
26 uart_store_tissues:
|
|
27 bcf uart_store_tissue_data ; Clear flag
|
|
28 bcf PIE1,RCIE ; No Interrupt for UART
|
21
|
29 bsf LED_blue
|
0
|
30 call simulator_save_tissue_data ; store and set flag for automatic restore
|
|
31 movlw 'k' ; send echo
|
|
32 movwf TXREG ; When done
|
|
33 call rs232_wait_tx ; wait for UART
|
21
|
34 bcf LED_blue
|
0
|
35 bsf PIE1,RCIE ; Interrupt for RS232
|
|
36 goto surfloop_loop ; return to surface loop
|
|
37
|
|
38 ; reset Decodata
|
|
39 reset_decodata:
|
|
40 bcf uart_reset_decodata ; clear flag
|
|
41 bcf PIE1,RCIE ; No Interrupt for UART
|
21
|
42 bsf LED_blue
|
0
|
43
|
|
44 call deco_main_clear_tissue ; Reset Decodata
|
|
45 movlb b'00000001' ; select ram bank 1
|
|
46 call deco_main_calc_desaturation_time ; calculate desaturation time
|
|
47 movlb b'00000001' ; select ram bank 1
|
|
48 call main_clear_CNS_fraction ; clear CNS
|
|
49 movlb b'00000001' ; select ram bank 1
|
|
50
|
|
51 movlw d'1'
|
|
52 movwf nofly_time+0 ; Clear nofly time
|
|
53 clrf nofly_time+1 ; Clear nofly time
|
|
54
|
|
55 movlw 'h' ; send echo
|
|
56 movwf TXREG ; When done
|
|
57 call rs232_wait_tx ; wait for UART
|
|
58
|
|
59 bsf oneminupdate ; set flag, so display will be updated at once
|
21
|
60 bcf LED_blue
|
0
|
61 bsf PIE1,RCIE ; Interrupt for RS232
|
|
62 goto surfloop_loop ; return to surface loop
|
|
63
|
|
64 ; send internal EEPROM BANK 0 via the UART
|
|
65 send_int_eeprom_b0:
|
|
66 bcf uart_send_int_eeprom ; clear flag
|
|
67 bcf PIE1,RCIE ; No Interrupt for UART
|
21
|
68 bsf LED_blue
|
|
69
|
0
|
70 clrf EEADRH ; Point to Bank0
|
|
71 rcall send_internal_eeprom1 ; sends complete 1st. page of internal EEPROM
|
|
72
|
21
|
73 bcf LED_blue
|
0
|
74 bsf PIE1,RCIE ; Interrupt for RS232
|
|
75 goto surfloop_loop ; return to surface loop
|
|
76
|
|
77 ; send internal EEPROM BANK 1 via the UART
|
|
78 send_int_eeprom_b1:
|
|
79 bcf uart_send_int_eeprom2 ; clear flag
|
|
80 bcf PIE1,RCIE ; No Interrupt for UART
|
21
|
81 bsf LED_blue
|
|
82
|
0
|
83
|
|
84 movlw d'1'
|
|
85 movwf EEADRH ; Point to Bank1
|
|
86 rcall send_internal_eeprom1 ; sends complete 2nd page of internal EEPROM
|
|
87 clrf EEADRH ; Point to Bank0
|
|
88
|
21
|
89 bcf LED_blue
|
0
|
90 bsf PIE1,RCIE ; Interrupt for RS232
|
|
91 goto surfloop_loop ; return to surface loop
|
|
92
|
|
93
|
|
94 ; Send firmware version and 16bytes MD2 hash via the UART
|
|
95 send_md2_hash:
|
|
96 bcf uart_send_hash ; clear flag
|
|
97 bcf PIE1,RCIE ; No Interrupt for UART
|
21
|
98 bsf LED_blue
|
0
|
99
|
|
100 call rs232_wait_tx ; wait for UART
|
|
101 movlw softwareversion_x ; Softwareversion
|
|
102 movwf TXREG
|
|
103 call rs232_wait_tx ; wait for UART
|
|
104 movlw softwareversion_y ; Softwareversion
|
|
105 movwf TXREG
|
|
106
|
|
107 lfsr FSR2, char_O_hash
|
|
108 movlw d'16'
|
|
109 movwf temp1
|
|
110 send_md2_hash2:
|
|
111 call rs232_wait_tx ; wait for UART
|
|
112 movff POSTINC2,TXREG ; copy hash byte to TXREG
|
|
113 decfsz temp1,F
|
|
114 bra send_md2_hash2 ; loop 16 times
|
|
115
|
21
|
116 bcf LED_blue
|
0
|
117 bsf PIE1,RCIE ; Interrupt for RS232
|
|
118 goto surfloop_loop ; return to surface loop
|
|
119
|
|
120
|
|
121 ; Sends first 256Byte from internal and first 32KB from external EEPROM using the UART module
|
|
122 menu_interface:
|
|
123 bcf dump_external_eeprom ; clear flag
|
|
124 bcf PIE1,RCIE ; No Interrupt for UART
|
21
|
125 bsf LED_blue
|
0
|
126 call PLED_ClearScreen
|
|
127 call PLED_topline_box
|
|
128 WIN_INVERT .1 ; Init new Wordprocessor
|
|
129 DISPLAYTEXT .15 ; "Interface"
|
|
130 WIN_INVERT .0 ; Init new Wordprocessor
|
|
131
|
|
132 movlw d'5'
|
|
133 movwf uart1_temp
|
|
134 menu_interface1:
|
|
135 movlw 0xAA ; Startbytes
|
|
136 movwf TXREG
|
|
137 call rs232_wait_tx ; wait for UART
|
|
138 decfsz uart1_temp
|
|
139 bra menu_interface1
|
|
140 movlw 0x55 ; finish preamble
|
|
141 movwf TXREG
|
|
142
|
|
143 DISPLAYTEXT .16 ; "Start"
|
|
144
|
|
145 call get_free_EEPROM_location ;
|
|
146 movlw d'1' ; increase
|
|
147 addwf eeprom_address+0,F
|
|
148 movlw d'0'
|
|
149 addwfc eeprom_address+1,F
|
|
150
|
|
151 DISPLAYTEXT .17 ; "Data"
|
|
152
|
|
153 rcall send_internal_eeprom1 ; sends complete 1st. page of internal EEPROM
|
|
154
|
|
155 call rs232_wait_tx ; wait for UART
|
|
156 movff batt_voltage+0,TXREG ; Battery
|
|
157
|
|
158 call rs232_wait_tx ; wait for UART
|
|
159 movff batt_voltage+1,TXREG ; Battery
|
|
160
|
|
161 call rs232_wait_tx ; wait for UART
|
|
162 movlw softwareversion_x ; Softwareversion
|
|
163 movwf TXREG
|
|
164
|
|
165 call rs232_wait_tx ; wait for UART
|
|
166 movlw softwareversion_y ; Softwareversion
|
|
167 movwf TXREG
|
|
168
|
|
169 DISPLAYTEXT .18 ; "Header"
|
|
170
|
|
171 clrf uart1_temp ; low address counter
|
|
172 clrf uart2_temp ; high address counter
|
|
173
|
|
174 menu_interface3:
|
|
175 bsf SSPCON2,SEN ; Start condition
|
|
176 call WaitMSSP
|
|
177
|
|
178 movlw b'10100110' ; Bit0=0: WRITE, Bit0=1: READ
|
|
179 movwf SSPBUF ; control byte
|
|
180 call WaitMSSP
|
|
181 btfsc SSPCON2,ACKSTAT
|
|
182 bra menu_interface3 ; No Ack, try again!
|
|
183
|
|
184 movff eeprom_address+1,SSPBUF ; High Address byte
|
|
185 call WaitMSSP
|
|
186 call I2C_WaitforACK
|
|
187 movff eeprom_address+0,SSPBUF ; Low Address byte
|
|
188 call WaitMSSP
|
|
189 call I2C_WaitforACK
|
|
190 bsf SSPCON2,RSEN ; Start condition
|
|
191 call WaitMSSP
|
|
192
|
|
193 movlw b'10100111' ; Bit0=0: WRITE, Bit0=1: READ
|
|
194 movwf SSPBUF ; control byte
|
|
195 call WaitMSSP
|
|
196 call I2C_WaitforACK
|
|
197
|
|
198 DISPLAYTEXT .19 ; "Profile"
|
|
199
|
|
200 menu_interface2:
|
|
201 call rs232_wait_tx ; wait for UART
|
|
202
|
|
203 bsf SSPCON2, RCEN ; Enable recieve mode
|
|
204 call WaitMSSP
|
|
205
|
|
206 movff SSPBUF, TXREG
|
|
207
|
|
208 movlw d'1'
|
|
209 addwf uart1_temp,F
|
|
210 movlw d'0'
|
|
211 addwfc uart2_temp,F
|
|
212
|
|
213 btfsc uart2_temp,7 ; 32KB done?
|
|
214 bra menu_interface4 ; Yes
|
|
215
|
|
216 bsf SSPCON2, ACKEN ; Ack
|
|
217 call WaitMSSP
|
|
218 bra menu_interface2 ; go on
|
|
219
|
|
220 menu_interface4:
|
|
221 bsf SSPCON2, PEN ; Stop
|
|
222 call WaitMSSP
|
|
223
|
|
224 DISPLAYTEXT .20 ; Done.
|
|
225
|
|
226 WAITMS d'250'
|
21
|
227 bcf LED_blue
|
0
|
228 bsf PIE1,RCIE ; Interrupt for RS232
|
|
229 goto surfloop ; back to surfacemode
|
|
230
|
|
231 send_internal_eeprom1:
|
|
232 clrf uart1_temp ; Send the total of 256bytes
|
|
233 clrf EEADR ; Send bytes 0-255 from internal EEPROM
|
|
234 send_internal_eeprom2:
|
|
235 call read_eeprom ; read byte
|
|
236 movff EEDATA,TXREG ; send byte
|
|
237 incf EEADR,F ; increase pointer
|
|
238 call rs232_wait_tx ; wait for UART
|
|
239 decfsz uart1_temp,F ; until limit reached
|
|
240 bra send_internal_eeprom2
|
|
241 return |