Rev 729 | Rev 731 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
714 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Paolo Gai <pj@gandalf.sssup.it> |
||
10 | * (see the web pages for full authors list) |
||
11 | * |
||
12 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
13 | * |
||
14 | * http://www.sssup.it |
||
15 | * http://retis.sssup.it |
||
16 | * http://shark.sssup.it |
||
17 | */ |
||
18 | |||
19 | /* |
||
20 | * Copyright (C) 2000 Michele Cirinei |
||
21 | * |
||
22 | * This program is free software; you can redistribute it and/or modify |
||
23 | * it under the terms of the GNU General Public License as published by |
||
24 | * the Free Software Foundation; either version 2 of the License, or |
||
25 | * (at your option) any later version. |
||
26 | * |
||
27 | * This program is distributed in the hope that it will be useful, |
||
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | * GNU General Public License for more details. |
||
31 | * |
||
32 | * You should have received a copy of the GNU General Public License |
||
33 | * along with this program; if not, write to the Free Software |
||
34 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
35 | */ |
||
36 | |||
37 | #include <kernel/kern.h> |
||
38 | #include <drivers/scomirq.h> |
||
39 | |||
40 | /**************************** |
||
41 | Variables |
||
42 | ****************************/ |
||
43 | static unsigned com_irq[] = {COM1_IRQ, COM2_IRQ, COM3_IRQ, COM4_IRQ}; |
||
44 | |||
45 | struct SCom_Access_Type SCom_Access; |
||
46 | |||
729 | giacomo | 47 | unsigned SCom_Error[4]; |
714 | giacomo | 48 | |
49 | struct TX_data_t{ |
||
50 | int ptr; |
||
51 | int len; |
||
52 | BYTE buf[100]; |
||
53 | }; |
||
54 | |||
729 | giacomo | 55 | static struct TX_data_t SCom_TX_data[4]; |
714 | giacomo | 56 | |
57 | /***************************** |
||
58 | * Functions |
||
59 | *****************************/ |
||
60 | |||
61 | void RBRF_handler(unsigned port); |
||
62 | |||
63 | void THRE_handler(unsigned port); |
||
64 | |||
65 | void LSR_handler(unsigned port); |
||
66 | |||
67 | void com_send_msg(unsigned port, BYTE len, BYTE *m); |
||
68 | |||
69 | void com_irq_sel(int no) |
||
70 | { |
||
71 | BYTE b; |
||
72 | unsigned i; |
||
73 | |||
74 | for(i=0;i<4;i++) |
||
75 | if (com_irq[i] == no) break; |
||
76 | |||
77 | b = DECODE(com_read(i, IIR)); |
||
78 | |||
79 | switch (b) |
||
721 | giacomo | 80 | { |
714 | giacomo | 81 | case LS_CHANGED: |
82 | LSR_handler(i); |
||
83 | break; |
||
84 | |||
85 | case RX_FULL: |
||
86 | RBRF_handler(i); |
||
87 | break; |
||
88 | |||
89 | case TX_EMPTY: |
||
90 | THRE_handler(i); |
||
91 | break; |
||
92 | } |
||
93 | } |
||
94 | |||
95 | void com_irq_enable(unsigned port, unsigned irq) |
||
96 | { |
||
97 | SYS_FLAGS f; |
||
721 | giacomo | 98 | |
714 | giacomo | 99 | f = kern_fsave(); |
100 | |||
101 | com_read(port, LSR); |
||
102 | com_read(port, IIR); |
||
103 | com_write(port, IER, com_read(port, IER) | irq); /* Enable irq */ |
||
104 | |||
105 | kern_frestore(f); |
||
106 | |||
107 | } |
||
108 | |||
109 | void com_irq_disable(unsigned port, unsigned irq) |
||
110 | { |
||
111 | |||
112 | SYS_FLAGS f; |
||
113 | |||
114 | f = kern_fsave(); |
||
115 | |||
116 | com_read(port, LSR); |
||
117 | com_read(port, IIR); |
||
118 | com_write(port, IER, com_read(port, IER) & ~irq); /* Disable irq */ |
||
119 | |||
120 | kern_frestore(f); |
||
121 | |||
122 | } |
||
123 | |||
716 | giacomo | 124 | void com_close_irq(unsigned port) |
714 | giacomo | 125 | { |
126 | SYS_FLAGS f; |
||
127 | |||
128 | f = kern_fsave(); |
||
129 | |||
130 | com_write(port, IER, 0); |
||
131 | com_read(port, LSR); |
||
132 | com_read(port, IIR); |
||
133 | |||
716 | giacomo | 134 | handler_remove(com_irq[port]); |
135 | |||
714 | giacomo | 136 | kern_frestore(f); |
137 | |||
138 | } |
||
139 | |||
716 | giacomo | 140 | void com_init_irq(unsigned port) |
714 | giacomo | 141 | { |
142 | SYS_FLAGS f; |
||
143 | |||
144 | f = kern_fsave(); |
||
145 | |||
729 | giacomo | 146 | SCom_Error[port] = 0; |
714 | giacomo | 147 | handler_set(com_irq[port], com_irq_sel, NIL, TRUE); |
148 | com_irq_disable(port, ALL_IRQ); /* Disable interrupts */ |
||
149 | |||
150 | kern_frestore(f); |
||
151 | |||
152 | } |
||
153 | |||
154 | void com_set_functions(void (*confirm)(unsigned port, BYTE msg_status),void (*indication)(unsigned port, BYTE data)) |
||
155 | { |
||
156 | SYS_FLAGS f; |
||
157 | |||
158 | f = kern_fsave(); |
||
159 | |||
160 | SCom_Access.confirm = confirm; |
||
161 | SCom_Access.request = com_send_msg; |
||
162 | SCom_Access.indication = indication; |
||
163 | |||
164 | kern_frestore(f); |
||
165 | |||
166 | } |
||
167 | |||
168 | void com_send_msg(unsigned port, BYTE len, BYTE *m) |
||
169 | { |
||
170 | SYS_FLAGS f; |
||
171 | |||
172 | f = kern_fsave(); |
||
173 | |||
174 | /* Transmit first byte of message */ |
||
729 | giacomo | 175 | SCom_TX_data[port].ptr = 0; |
176 | SCom_TX_data[port].len = len; |
||
714 | giacomo | 177 | if (len < 100) { |
729 | giacomo | 178 | memcpy(SCom_TX_data[port].buf, m, len); |
179 | com_write(port, THR, SCom_TX_data[port].buf[SCom_TX_data[port].ptr++]); |
||
721 | giacomo | 180 | com_irq_enable(port, THRE_IRQ); |
714 | giacomo | 181 | } |
182 | |||
183 | kern_frestore(f); |
||
184 | |||
185 | } |
||
186 | |||
716 | giacomo | 187 | __inline__ void com_irq_send(unsigned port, BYTE len, BYTE *m) { |
188 | |||
189 | com_send_msg(port, len, m); |
||
190 | |||
191 | } |
||
192 | |||
714 | giacomo | 193 | void THRE_handler (unsigned port) /* Transmit Data Register Ready for next byte */ |
730 | giacomo | 194 | { |
729 | giacomo | 195 | if (SCom_TX_data[port].ptr < SCom_TX_data[port].len) |
196 | com_write(port, THR, SCom_TX_data[port].buf[SCom_TX_data[port].ptr++]); |
||
714 | giacomo | 197 | else |
198 | { |
||
199 | com_irq_disable(port, THRE_IRQ); |
||
200 | while((com_read(port,LSR) & bit6) == 0); /* Wait until last byte sent */ |
||
201 | SCom_Access.confirm(port, COM_OK); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | void RBRF_handler (unsigned port) /* Receive Data Register Full */ |
||
206 | { |
||
727 | giacomo | 207 | SCom_Access.indication(port, com_read(port, RBR)); |
714 | giacomo | 208 | } |
209 | |||
210 | void LSR_handler (unsigned port) /* break = 8, frame = 4, parity = 2, RBR overrun = 1*/ |
||
211 | { |
||
729 | giacomo | 212 | SCom_Error[port] = (com_read(port, LSR) & (bit4|bit3|bit2|bit1) ) >> 1; |
714 | giacomo | 213 | com_irq_disable(port, ALL_IRQ); /* Disable all interrupts */ |
214 | SCom_Access.confirm(port, COM_ERROR); |
||
215 | } |
||
216 |