]> cloudbase.mooo.com Git - avrcpm.git/blame - avr/virt_ports.asm
* New config option: SRAM_FILL
[avrcpm.git] / avr / virt_ports.asm
CommitLineData
64219415
FZ
1; Virtual Ports for the BIOS Interaction
2;
98979541 3; Copyright (C) 2010-2013 Leo C.
64219415
FZ
4;
5; This file is part of avrcpm.
6;
7; avrcpm is free software: you can redistribute it and/or modify it
8; under the terms of the GNU General Public License as published by
9; the Free Software Foundation, either version 3 of the License, or
10; (at your option) any later version.
11;
12; avrcpm is distributed in the hope that it will be useful,
13; but WITHOUT ANY WARRANTY; without even the implied warranty of
14; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15; GNU General Public License for more details.
16;
17; You should have received a copy of the GNU General Public License
18; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.
19;
20; $Id$
29ce189c
L
21;
22
23
24;
25; Port Direction Function
26;hex dez
27;-------------------------------------------------------------------------
28;00 0 in - Con status.
29; Returns 0xFF if the UART has a byte, 0 otherwise.
30;01 1 in/out - Console input, aka UDR. / Console Output
31;02 2 out - Console Output (deprecated)
32;03 3 in - "UART" status: bit 0 = rx, bit 1 = tx
33;04 4 in - "UART" data register, no wait
34;
d8fa6a36
L
35;------------------------ Virtual I2C interface --------------------------
36;05 5 out - Control Port: 1 = Start read operation
37; 2 = Start write operation
38;05 5 in - Status of last Transfer: 0 = ok, else fail
39;06 6 in/out - Number of bytes to transfer, including Slave address
40;07,08 7,8 in/out - Read/Write address low/high
41;
42;------------------------ Disk I/O ---------------------------------------
29ce189c
L
43;0D,0E 13,14 in/out - Set address of Bios Controll Block
44;0F 15 in/out - Disk select
45;10,11 16,17 in/out - Track select
46;12,13 18,19 in/out - Sector select
47;14,15 20,21 in/out - Write addr
48;
49;16 22 out - Trigger disk i/o operations
50; Bit 7 = 1: Read sector
51; Bit 6 = 1: Write sector
52; Bit 5 = 1: BIOS WBOOT
53; Bit 4 = 1: BIOS Home
54; Only one of bits 4..7 may be set.
55; If Write function (bit 6=1):
56; Bits 0..2: 0 - write to allocated
57; 1 - write to directory
58; 2 - write unallocated
59; 3 - write to directory
60;
61;16 22 in - Result of last read/write operation.
62; 0x00 = ok, 0xff = error (--> Bad Sector)
63;
d8fa6a36 64;
98979541
L
65;------------------------ ADC Interface ----------------------------------
66;17-19 23,25 in - ADC Channels 6,7 and 8 (Temp-Sensor)
67; ADC 6,7 only Devices in 32 pin Case (TQFP/MLF)
68; 8 Bit only
69; Fixed ADC clock (FCPU/128, 156KHz at 20MHz CPU)
70; Vref = VCC
71;20,21 in - ADC: Measure VCC
d8fa6a36
L
72;
73;------------------------ Wall Clock and Timers --------------------------
5482d75f 74;40 64-71 in/out - Timer/Clock control.
fb050095
L
75;41-46
76;
d8fa6a36
L
77;47-4D clock - BCD format: ss, mm, hh, DD, MM, YYl, YYh
78;
98979541
L
79;4F debug - start/stop trace, print stack, ...
80;
d8fa6a36
L
81;------------------------ Ports ------------------------------------------
82;80-87 in/out - Port-Expander PCF8574 (max. 8 Chips)
83;88-8F in/out - Port-Expander PCF8574A (not implemented yet!)
29ce189c
L
84
85
64219415 86; ---------------------------------------------- Start of Code Segment
98979541 87
29ce189c
L
88 .cseg
89vport_tbl:
90 .db 00,1 ;Port 0, length 1
91 .dw conStatus ; in
92 .dw dbgOut ; out
93 .db 01,1
94 .dw uartgetc
95 .dw uartputc
96 .db 02,1 ;Port 2 (old console output)
97 .dw uartgetc ; filler
98 .dw uartputc ; deprecated
99 .db 03,1
100 .dw uartstat
101 .dw vport_out_dummy
102 .db 04,1
103 .dw uartin
104 .dw uartout
105
fb050095 106 .db 13,9 ; Port 13-21, (length 9)
5482d75f
L
107 .dw dsk_param_get
108 .dw dsk_param_set
29ce189c
L
109 .db 22,1
110 .dw dskErrorRet
111 .dw dskDoIt
112
113 .db TIMERPORT,7
fb050095
L
114 .dw utimeget
115 .dw utimeput
116
d8fa6a36 117 .db CLOCKPORT,7 ;Clock format (bcd): ss, mm, hh, DD, MM, YYl, YYh
29ce189c
L
118 .dw clockget
119 .dw clockput
80e1fa71
L
120
121 .db DEBUGPORT,1
122 .dw dbg_stat
123 .dw dbg_ctrl
d8fa6a36 124
825ecc9d 125#if I2C_SUPPORT
d8fa6a36
L
126 .db I2CCTRL,1
127 .dw vi2c_stat_get
128 .dw vi2c_ctrl
129
130 .db I2CBLEN,3 ;
131 .dw vi2c_param_get
132 .dw vi2c_param_set
133
134 .db PORT,8
135 .dw pcf8574_in
136 .dw pcf8574_out
137#endif
98979541
L
138#if ADC_SUPPORT
139 .db ADC80,3 ;2 Channels ADC80 ADC81 + Temp Sensor
140 .dw adc_read8
141 .dw vport_out_dummy
d8fa6a36 142
98979541
L
143 .db 0x20,2 ;
144 .dw adc_readvcc
145 .dw vport_out_dummy
146#endif
29ce189c
L
147 .db 0,0 ; Stop mark
148
149;---------------------------------------------------------------------
150
151;Called with port in temp2 and value in temp.
152portWrite:
153 set
154 rjmp vprw_start
155
156;Called with port in temp2. Should return value in temp.
157portRead:
158 clt
159
160vprw_start:
e7a0f403
L
161 push yh
162 push yl
29ce189c
L
163.if PORT_DEBUG > 1
164 tst temp2
165 brne dvp_1 ;don't debug console status
166 brts dvp_1
167 rjmp conStatus
168dvp_1:
169 printnewline
170 brts dvp_11
171 printstring "Port In: "
172 rjmp dvp_12
173dvp_11:
174 printstring "Port Out: "
175dvp_12:
176 push temp
177 mov temp,temp2
178 rcall printhex
179 pop temp
180.endif
181 ldiw z,vport_tbl*2
182
183vprw_loop:
184 lpm _tmp0,z+
825ecc9d
L
185 lpm _tmp1,z+ ;length
186 cp _tmp1,_0
29ce189c
L
187 breq vprw_exit ;no more ports
188
189 mov temp3,temp2
190 sub temp3,_tmp0 ;base port
191 brcs vprw_next ;port # too high
825ecc9d 192 cp temp3,_tmp1 ;may be in range
29ce189c
L
193 brcs vprw_found ;
194vprw_next: ;port # not in range, test next block.
195 adiw z,4
196 rjmp vprw_loop
197vprw_found:
d8fa6a36
L
198 brtc PC+2 ;read or write?
199 adiw z,2 ;skip read function pointer
29ce189c 200 lpm _tmp0,z+
825ecc9d
L
201 lpm zh,z
202 mov zl,_tmp0
29ce189c
L
203
204.if PORT_DEBUG > 1
205 push temp2
206 push temp
207 printstring ", exec: "
208 movw temp,z
209 rcall printhexw
210 printstring ", rel port: "
211 mov temp,temp3
212 rcall printhex
213 pop temp
214 pop temp2
215 printstring ", val: "
216 brts dvp_2
217 icall
218 rcall printhex
219 printstring " "
e7a0f403
L
220 pop yl
221 pop yh
29ce189c
L
222 ret
223dvp_2:
224 rcall printhex
225 printstring " "
e7a0f403
L
226 ; relative port # in temp3
227 icall
228 pop yl
229 pop yh
230 ret
29ce189c 231.else
e7a0f403
L
232 icall
233 pop yl
234 pop yh
235 ret
29ce189c
L
236.endif
237
238vprw_exit:
239 ; trap for nonexistent port?
240.if PORT_DEBUG > 1
241 printstring ", not found!"
242.endif
29ce189c 243 ldi temp,0xff
e7a0f403
L
244 pop yl
245 pop yh
29ce189c 246 ret
825ecc9d
L
247
248vport_out_dummy:
249 ret
29ce189c 250
64219415
FZ
251uartstat:
252 clr temp
253 lds temp2,rxcount
254 cpse temp2,_0
255 sbr temp,0x01
256 lds temp2,txcount
257 cpi temp2,TXBUFSIZE
258 breq uartst_1
259 sbr temp,0x02
260uartst_1:
261 ret
262
29ce189c
L
263uartin:
264 clr temp
265 lds temp2,rxcount
266 cpse temp2,_0
08716d4f 267 ljmp uartgetc
29ce189c
L
268 ret
269
64219415
FZ
270uartout:
271 lds temp2,txcount
272 cpi temp2,TXBUFSIZE
273 breq uartout_1
08716d4f 274 ljmp uartputc
64219415
FZ
275uartout_1:
276 ret
277
29ce189c 278
64219415
FZ
279conStatus:
280 lds temp,rxcount
281 cpse temp,_0
282 ldi temp,0xff
283 ret
284
64219415
FZ
285
286dbgOut:
287 printnewline
288 printstring "Debug: "
08716d4f 289 lcall printhex
64219415
FZ
290 ret
291
80e1fa71
L
292dbg_stat:
293 ldi temp,0
294 ret
295
296dbg_ctrl:
297 bmov intstat,i_trace, temp,0
98979541
L
298.if SRAM_FILL
299 sbrc temp,1
300 lcall stackusage_print
301.endif
80e1fa71
L
302 ret
303
304
305
64219415 306;---------------------------------------------------------------------
29ce189c
L
307; vim:set ts=8 noet nowrap
308