Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
405 serge 1
 
2
;new_app_base    equ 0x60400000
3
;PROC_BASE       equ OS_BASE+0x0080000
4
5
 
6
{  .handle      dd ?
7
   .io_code     dd ?
8
   .input       dd ?
9
   .inp_size    dd ?
10
   .output      dd ?
11
   .out_size    dd ?
12
}
13
14
 
15
 
16
;public service_proc
17
;public version
18
19
 
20
21
 
22
DRV_EXIT         equ  -1
23
24
 
25
 
26
LCR_6BIT         equ  0x01
27
LCR_7BIT         equ  0x02
28
LCR_8BIT         equ  0x03
29
LCR_STOP_1       equ  0x00
30
LCR_STOP_2       equ  0x04
31
LCR_PARITY       equ  0x08
32
LCR_EVEN         equ  0x10
33
LCR_STICK        equ  0x20
34
LCR_BREAK        equ  0x40
35
LCR_DLAB         equ  0x80
36
37
 
38
LSR_OE           equ  0x02     ;overrun error
39
LSR_PE           equ  0x04     ;parity error
40
LSR_FE           equ  0x08     ;framing error
41
LSR_BI           equ  0x10     ;break interrupt
42
LSR_THRE         equ  0x20     ;transmitter holding empty
43
LSR_TEMT         equ  0x40     ;transmitter empty
44
LSR_FER          equ  0x80     ;FIFO error
45
46
 
47
FCR_CRB          equ  0x02     ;clear reciever FIFO
48
FCR_CXMIT        equ  0x04     ;clear transmitter FIFO
49
FCR_RDY          equ  0x08     ;set RXRDY and TXRDY pins
50
FCR_FIFO_1       equ  0x00     ;1  byte trigger
51
FCR_FIFO_4       equ  0x40     ;4  bytes trigger
52
FCR_FIFO_8       equ  0x80     ;8  bytes trigger
53
FCR_FIFO_14      equ  0xC0     ;14 bytes trigger
54
55
 
56
57
 
58
IER_THRI         equ  0x02     ;transmitter empty interrupt
59
IER_LSI          equ  0x04     ;line status interrupt
60
IER_MSI          equ  0x08     ;modem status interrupt
61
62
 
63
MCR_RTS          equ  0x02     ;0-> RTS=1, 1-> RTS=0
64
MCR_OUT_1        equ  0x04     ;0-> OUT1=1, 1-> OUT1=0
65
MCR_OUT_2        equ  0x08     ;0-> OUT2=1, 1-> OUT2=0
66
MCR_LOOP         equ  0x10     ;lopback mode
67
68
 
69
MSR_DDSR         equ  0x02     ;delta data set redy
70
MSR_TERI         equ  0x04     ;trailinh edge of ring
71
MSR_DDCD         equ  0x08     ;delta carrier detect
72
73
 
74
COM_IER          equ 0x3f9     ;interrupt enable
75
COM_IIR          equ 0x3fA     ;interrupt info
76
COM_LCR          equ 0x3FB     ;line control
77
COM_MCR          equ 0x3FC     ;modem control
78
COM_LSR          equ 0x3FD     ;line status
79
COM_MSR          equ 0x3FE     ;modem status
80
81
 
82
RATE_75          equ  1
83
RATE_110         equ  2
84
RATE_134         equ  3
85
RATE_150         equ  4
86
RATE_300         equ  5
87
RATE_600         equ  6
88
RATE_1200        equ  7
89
RATE_1800        equ  8
90
RATE_2000        equ  9
91
RATE_2400        equ 10
92
RATE_3600        equ 11
93
RATE_4800        equ 12
94
RATE_7200        equ 13
95
RATE_9600        equ 14
96
RATE_19200       equ 15
97
RATE_38400       equ 16
98
RATE_57600       equ 17
99
RATE_115200      equ 18
100
101
 
102
COM_2            equ  1
103
COM_3            equ  2
104
COM_4            equ  3
105
106
 
107
COM_2_IRQ        equ  3
108
TRANSMIT         equ  1
109
110
 
111
 
112
{
113
   .base         dd ?
114
   .lcr_reg      dd ?
115
   .mcr_reg      dd ?
116
   .rate         dd ?
117
   .mode         dd ?
118
   .state        dd ?
119
   .connection   dd ?
120
121
 
122
   .rcvr_wp      dd ?
123
   .rcvr_free    dd ?
124
   .rcvr_count   dd ?
125
126
 
127
   .xmit_wp      dd ?
128
   .xmit_free    dd ?
129
   .xmit_count   dd ?
130
   .xmit_buffer  rb 128
131
   .rcvr_buffer  rb 128
132
}
133
virtual at 0
134
  COMPORT COMPORT
135
end virtual
136
137
 
138
139
 
140
141
 
142
           mov eax, COMPORT_SIZE
143
           call malloc
144
           test eax, eax
145
           jz .fail
146
147
 
148
           mov edi, eax
149
           mov ecx, COMPORT_SIZE/4
150
           xor eax, eax
151
           cld
152
           rep stosd
153
154
 
155
156
 
157
           stdcall reg_service, sz_uart_srv, uart_proc
158
           ret
159
.fail:
160
           xor eax, eax
161
           ret
162
163
 
164
io_code    equ  IOCTL.io_code
165
input      equ  IOCTL.input
166
inp_size   equ  IOCTL.inp_size
167
output     equ  IOCTL.output
168
out_size   equ  IOCTL.out_size
169
170
 
171
PORT_OPEN       equ 1
172
PORT_CLOSE      equ 2
173
PORT_RESET      equ 3
174
PORT_SETMODE    equ 4
175
PORT_GETMODE    equ 5
176
PORT_SETMCR     equ 6
177
PORT_GETMCR     equ 7
178
PORT_READ       equ 8
179
PORT_WRITE      equ 9
180
181
 
182
proc uart_proc stdcall, ioctl:dword
183
184
 
185
           mov eax, [ebx+io_code]
186
           cmp eax, PORT_WRITE
187
           ja .fail
188
189
 
190
           jne @F
191
192
 
193
           mov eax, [eax]
194
           mov [eax], dword UART_VERSION
195
           xor eax, eax
196
           ret
197
@@:
198
           cmp eax, PORT_OPEN
199
           jne @F
200
           call open_port
201
           ret
202
203
 
204
 
205
           mov ecx, [esi]
206
           mov edx, [com1]
207
           cmp [edx+COMPORT.connection], ecx
208
           je @F
209
           mov edx, [com2]
210
           cmp [edx+COMPORT.connection], ecx
211
           jne .fail
212
213
 
214
           call [uart_func+eax*4]  ;edx, esi, edi
215
           ret
216
217
 
218
           or eax, -1
219
           ret
220
221
 
222
223
 
224
restore   io_code
225
restore   input
226
restore   inp_size
227
restore   output
228
restore   out_size
229
230
 
231
 
232
           ret
233
234
 
235
;  edx= port
236
;  esi= input data
237
;  edi= output data
238
;
239
; retval
240
;  eax=0 success
241
;  eax <>0 error
242
243
 
244
close_port:
245
246
 
247
           mov [edx+COMPORT.connection], 0
248
           xor eax, eax
249
           ret
250
251
 
252
 
253
; clear FIFO
254
; clear pending interrupts
255
256
 
257
reset:
258
           mov eax, RATE_2400
259
           mov ebx, LCR_8BIT+LCR_STOP_1
260
           call set_mode
261
262
 
263
           mov edx, COM_IIR
264
           out dx, al
265
266
 
267
           mov edx, COM_LSR
268
           in al, dx
269
           test eax, LSR_DR
270
           jz @F
271
272
 
273
           in al, dx
274
           jmp .clear_RB
275
@@:
276
           mov eax,IER_RDAI+IER_THRI+IER_LSI
277
           mov edx, COM_IER
278
           out dx, al
279
280
 
281
           mov edx, COM_IIR
282
           in al, dx
283
           test al, IIR_INTR
284
           jnz .done
285
286
 
287
           and eax, 3
288
           jnz @F
289
290
 
291
           in al, dx
292
           jmp .clear_IIR
293
@@:
294
           cmp eax, 1
295
           je .clear_IIR
296
297
 
298
           jne @F
299
300
 
301
           in al, dx
302
           jmp .clear_IIR
303
@@:
304
           mov edx, COM_LSR
305
           in al, dx
306
           jmp .clear_IIR
307
308
 
309
           mov edi, rcvr_buff
310
           xor eax, eax
311
           mov ecx, 256/4
312
313
 
314
           mov [rcvr_wp], edi
315
           mov [rcvr_free], 128
316
;;           mov [rcvr_count], 16
317
318
 
319
           mov [xmit_wp], xmit_buff
320
           mov [xmit_free], 128
321
           mov [xmit_count], 16       ;FIFO free
322
323
 
324
           rep stosd
325
           ret
326
327
 
328
;  eax= rate constant
329
;  ebx= mode bits
330
331
 
332
set_mode:
333
           cmp eax, RATE_115200
334
           ja .fail
335
336
 
337
           jae .fail
338
339
 
340
           mov [mode], ebx
341
342
 
343
344
 
345
           in al, dx
346
           or al, 0x80
347
           out dx, al
348
349
 
350
           mov al, cl
351
           out dx, al
352
353
 
354
           mov al, ch
355
           out dx, al
356
357
 
358
           mov eax, ebx
359
           out dx, al
360
.fail:
361
           ret
362
363
 
364
;  eax= rate constant
365
366
 
367
set_rate:
368
           cmp eax, RATE_115200
369
           ja .fail
370
371
 
372
           mov bx, [divisor+eax*2]
373
374
 
375
           in al, dx
376
           or al, 0x80
377
           out dx, al
378
379
 
380
           mov al, bl
381
           out dx, al
382
383
 
384
           mov al, bh
385
           out dx, al
386
387
 
388
           mov eax, [lcr_reg]
389
           out dx, al
390
.fail:
391
           ret
392
393
 
394
transmit:
395
           push esi
396
           mov edx, COM_THR
397
398
 
399
400
 
401
           cli
402
403
 
404
           mov ecx, [xmit_free]
405
406
 
407
           je .exit
408
@@:
409
           and esi, 127
410
           mov al, [xmit_buff+esi]
411
           inc esi
412
413
 
414
           inc ecx
415
           dec [xmit_count]
416
           jz .done
417
418
 
419
           jne @B
420
.done:
421
           add esi, xmit_buff
422
           mov [xmit_rp], esi
423
           mov [xmit_free], ecx
424
           mov [com_state], TRANSMIT
425
.exit:
426
           popfd
427
           pop esi
428
           ret
429
430
 
431
 
432
; ebx= count
433
434
 
435
comm_send:
436
           mov edi, [xmit_wp]
437
           mov esi, eax
438
.write:
439
           test ebx, ebx
440
           jz .done
441
.wait:
442
           cmp [xmit_free], 0
443
           jne .fill
444
445
 
446
           je .wait
447
448
 
449
           jmp .write
450
.fill:
451
           mov ecx, xmit_buff+128
452
           sub ecx, edi
453
           cmp ecx, [xmit_free]
454
           jb @F
455
456
 
457
@@:
458
           cmp ecx, ebx
459
           jb @F
460
           mov ecx, ebx
461
@@:
462
           sub [xmit_free], ecx
463
           sub ebx, ecx
464
465
 
466
           rep movsb
467
468
 
469
           jb .write
470
           sub edi, 128
471
           jmp .write
472
473
 
474
           cmp [com_state], TRANSMIT
475
           je @F
476
           call transmit
477
@@:
478
           ret
479
480
 
481
com_isr:
482
483
 
484
           mov dx, COM_IIR
485
           in  al, dx
486
487
 
488
           jnz .done
489
490
 
491
           and eax, 3
492
493
 
494
           jmp .get_info
495
.done:
496
           ret
497
498
 
499
isr_line:
500
           mov edx, COM_LSR
501
           in al, dx
502
           ret
503
504
 
505
isr_recieve:
506
           mov edx, COM_THR
507
           in al, dx
508
           ret
509
510
 
511
isr_modem:
512
            mov edx, COM_MSR
513
            in al, dx
514
            ret
515
516
 
517
 
518
 
519
uart_func   dd 0            ;get version
520
            dd 0            ;open port
521
            dd close_port
522
523
 
524
 
525
            dd transmit
526
            dd isr_recieve
527
            dd isr_line
528
529
 
530
 
531
            dw  192,   96,   64,  58,  48,  32
532
            dw   24,   16,   12,   6,   3,   2, 1
533
534
 
535
 
536
 
537
538
 
539
540
 
541
 
542
543
 
544
com2        dd ?
545
546
 
547
rcvr_wp     dd ?
548
rcvr_free   dd ?
549
rcvr_count  dd ?
550
551
 
552
xmit_wp     dd ?
553
xmit_free   dd ?
554
xmit_count  dd ?
555
556
 
557
mcr_reg     dd ?
558
rate        dd ?
559
mode        dd ?
560
com_state   dd ?
561
562
 
563
564
 
565
rcvr_buff   rb 128
566
xmit_buff   rb 128
567