8c5b4a9ebe72fb6974e8716a666f43e6c957c500
[rtems-devel.git] / rtems-patches / rtems-csb336-20051008.patch
1 Index: rtems/c/src/lib/libbsp/arm/csb336/times
2 ===================================================================
3 --- rtems/c/src/lib/libbsp/arm/csb336/times     (revision 42)
4 +++ rtems/c/src/lib/libbsp/arm/csb336/times     (working copy)
5 @@ -18,155 +18,155 @@
6  
7                                               
8  == ====================================================================  ===
9 - 1 rtems_semaphore_create                                                16
10 - 1 rtems_semaphore_delete                                                17
11 - 1 rtems_semaphore_obtain: available                                     2
12 - 1 rtems_semaphore_obtain: not available -- NO_WAIT                      2
13 - 1 rtems_semaphore_release: no waiting tasks                             5
14 + 1 rtems_semaphore_create                                                15
15 + 1 rtems_semaphore_delete                                                15
16 + 1 rtems_semaphore_obtain: available                                     0
17 + 1 rtems_semaphore_obtain: not available -- NO_WAIT                      0
18 + 1 rtems_semaphore_release: no waiting tasks                             0
19  
20 - 2 rtems_semaphore_obtain: not available -- caller blocks                20
21 + 2 rtems_semaphore_obtain: not available -- caller blocks                12
22  
23 - 3 rtems_semaphore_release: task readied -- preempts caller              16
24 + 3 rtems_semaphore_release: task readied -- preempts caller              11
25  
26 - 4 rtems_task_restart: blocked task -- preempts caller                   48
27 - 4 rtems_task_restart: ready task -- preempts caller                     36
28 - 4 rtems_semaphore_release: task readied -- returns to caller            9
29 - 4 rtems_task_create                                                     33
30 - 4 rtems_task_start                                                      12
31 - 4 rtems_task_restart: suspended task -- returns to caller               14
32 - 4 rtems_task_delete: suspended task                                     31
33 - 4 rtems_task_restart: ready task -- returns to caller                   14
34 - 4 rtems_task_restart: blocked task -- returns to caller                 19
35 - 4 rtems_task_delete: blocked task                                       32
36 + 4 rtems_task_restart: blocked task -- preempts caller                   38
37 + 4 rtems_task_restart: ready task -- preempts caller                     29
38 + 4 rtems_semaphore_release: task readied -- returns to caller            5
39 + 4 rtems_task_create                                                     24
40 + 4 rtems_task_start                                                      8
41 + 4 rtems_task_restart: suspended task -- returns to caller               9
42 + 4 rtems_task_delete: suspended task                                     20
43 + 4 rtems_task_restart: ready task -- returns to caller                   10
44 + 4 rtems_task_restart: blocked task -- returns to caller                 11
45 + 4 rtems_task_delete: blocked task                                       21
46  
47 - 5 rtems_task_suspend: calling task                                      14
48 - 5 rtems_task_resume: task readied -- preempts caller                    12
49 + 5 rtems_task_suspend: calling task                                      9
50 + 5 rtems_task_resume: task readied -- preempts caller                    8
51  
52 - 6 rtems_task_restart: calling task                                      14
53 - 6 rtems_task_suspend: returns to caller                                 6
54 - 6 rtems_task_resume: task readied -- returns to caller                  6
55 - 6 rtems_task_delete: ready task                                         32
56 + 6 rtems_task_restart: calling task                                      8
57 + 6 rtems_task_suspend: returns to caller                                 3
58 + 6 rtems_task_resume: task readied -- returns to caller                  3
59 + 6 rtems_task_delete: ready task                                         22
60  
61 - 7 rtems_task_restart: suspended task -- preempts caller                 24
62 + 7 rtems_task_restart: suspended task -- preempts caller                 14
63  
64 - 8 rtems_task_set_priority: obtain current priority                      4
65 - 8 rtems_task_set_priority: returns to caller                            8
66 - 8 rtems_task_mode: obtain current mode                                  2
67 - 8 rtems_task_mode: no reschedule                                        2
68 - 8 rtems_task_mode: reschedule -- returns to caller                      4
69 - 8 rtems_task_mode: reschedule -- preempts caller                        19
70 - 8 rtems_task_set_note                                                   4
71 - 8 rtems_task_get_note                                                   4
72 - 8 rtems_clock_set                                                       9
73 + 8 rtems_task_set_priority: obtain current priority                      1
74 + 8 rtems_task_set_priority: returns to caller                            3
75 + 8 rtems_task_mode: obtain current mode                                  0
76 + 8 rtems_task_mode: no reschedule                                        0
77 + 8 rtems_task_mode: reschedule -- returns to caller                      3
78 + 8 rtems_task_mode: reschedule -- preempts caller                        13
79 + 8 rtems_task_set_note                                                   1
80 + 8 rtems_task_get_note                                                   1
81 + 8 rtems_clock_set                                                       4
82   8 rtems_clock_get                                                       0
83  
84 - 9 rtems_message_queue_create                                            54
85 - 9 rtems_message_queue_send: no waiting tasks                            8
86 - 9 rtems_message_queue_urgent: no waiting tasks                          8
87 - 9 rtems_message_queue_receive: available                                7
88 - 9 rtems_message_queue_flush: no messages flushed                        4
89 - 9 rtems_message_queue_flush: messages flushed                           5
90 - 9 rtems_message_queue_delete                                            21
91 + 9 rtems_message_queue_create                                            38
92 + 9 rtems_message_queue_send: no waiting tasks                            4
93 + 9 rtems_message_queue_urgent: no waiting tasks                          4
94 + 9 rtems_message_queue_receive: available                                4
95 + 9 rtems_message_queue_flush: no messages flushed                        2
96 + 9 rtems_message_queue_flush: messages flushed                           3
97 + 9 rtems_message_queue_delete                                            19
98  
99 -10 rtems_message_queue_receive: not available -- NO_WAIT                 4
100 -10 rtems_message_queue_receive: not available -- caller blocks           20
101 +10 rtems_message_queue_receive: not available -- NO_WAIT                 2
102 +10 rtems_message_queue_receive: not available -- caller blocks           12
103  
104 -11 rtems_message_queue_send: task readied -- preempts caller             18
105 +11 rtems_message_queue_send: task readied -- preempts caller             13
106  
107 -12 rtems_message_queue_send: task readied -- returns to caller           11
108 +12 rtems_message_queue_send: task readied -- returns to caller           7
109  
110 -13 rtems_message_queue_urgent: task readied -- preempts caller           19
111 +13 rtems_message_queue_urgent: task readied -- preempts caller           13
112  
113 -14 rtems_message_queue_urgent: task readied -- returns to caller 11
114 +14 rtems_message_queue_urgent: task readied -- returns to caller         7
115  
116  15 rtems_event_receive: obtain current events                            0
117 -15 rtems_event_receive: not available -- NO_WAIT                         3
118 -15 rtems_event_receive: not available -- caller blocks                   17
119 -15 rtems_event_send: no task readied                                     3
120 -15 rtems_event_receive: available                                        5
121 -15 rtems_event_send: task readied -- returns to caller                   10
122 +15 rtems_event_receive: not available -- NO_WAIT                         1
123 +15 rtems_event_receive: not available -- caller blocks                   11
124 +15 rtems_event_send: no task readied                                     1
125 +15 rtems_event_receive: available                                        3
126 +15 rtems_event_send: task readied -- returns to caller                   7
127  
128 -16 rtems_event_send: task readied -- preempts caller                     16
129 +16 rtems_event_send: task readied -- preempts caller                     12
130  
131 -17 rtems_task_set_priority: preempts caller                              19
132 +17 rtems_task_set_priority: preempts caller                              13
133  
134 -18 rtems_task_delete: calling task                                       41
135 +18 rtems_task_delete: calling task                                       26
136  
137 -19 rtems_signal_catch                                                    6
138 -19 rtems_signal_send: returns to caller                                  15
139 -19 rtems_signal_send: signal to self                                     25
140 -19 exit ASR overhead: returns to calling task                            11
141 -19 exit ASR overhead: returns to preempting task                         12
142 +19 rtems_signal_catch                                                    5
143 +19 rtems_signal_send: returns to caller                                  12
144 +19 rtems_signal_send: signal to self                                     19
145 +19 exit ASR overhead: returns to calling task                            7
146 +19 exit ASR overhead: returns to preempting task                         10
147  
148 -20 rtems_partition_create                                                22
149 -20 rtems_region_create                                                   30
150 -20 rtems_partition_get_buffer: available                                 10
151 -20 rtems_partition_get_buffer: not available                             4
152 -20 rtems_partition_return_buffer                                         9
153 -20 rtems_partition_delete                                                10
154 -20 rtems_region_get_segment: available                                   15
155 -20 rtems_region_get_segment: not available -- NO_WAIT                    16
156 -20 rtems_region_return_segment: no waiting tasks                         13
157 -20 rtems_region_get_segment: not available -- caller blocks              47
158 -20 rtems_region_return_segment: task readied -- preempts caller 45                                                          
159 -20 rtems_region_return_segment: task readied -- returns to caller 25
160 -20 rtems_region_delete                                                   23
161 -20 rtems_io_initialize                                                   1
162 +20 rtems_partition_create                                                21
163 +20 rtems_region_create                                                   33
164 +20 rtems_partition_get_buffer: available                                 9
165 +20 rtems_partition_get_buffer: not available                             3
166 +20 rtems_partition_return_buffer                                         8
167 +20 rtems_partition_delete                                                8
168 +20 rtems_region_get_segment: available                                   7
169 +20 rtems_region_get_segment: not available -- NO_WAIT                    7
170 +20 rtems_region_return_segment: no waiting tasks                         6
171 +20 rtems_region_get_segment: not available -- caller blocks              36
172 +20 rtems_region_return_segment: task readied -- preempts caller          33                                                 
173 +20 rtems_region_return_segment: task readied -- returns to caller        13
174 +20 rtems_region_delete                                                   18
175 +20 rtems_io_initialize                                                   0
176  20 rtems_io_open                                                         0
177  20 rtems_io_close                                                        0
178  20 rtems_io_read                                                         0
179  20 rtems_io_write                                                        0
180  20 rtems_io_control                                                      0
181  
182 -21 rtems_task_ident                                                      39
183 -21 rtems_message_queue_ident                                             38
184 -21 rtems_semaphore_ident                                                 43
185 -21 rtems_partition_ident                                                 38
186 -21 rtems_region_ident                                                    38
187 -21 rtems_port_ident                                                      37
188 -21 rtems_timer_ident                                                     38
189 -21 rtems_rate_monotonic_ident                                            38
190 +21 rtems_task_ident                                                      8
191 +21 rtems_message_queue_ident                                             8
192 +21 rtems_semaphore_ident                                                 9
193 +21 rtems_partition_ident                                                 8
194 +21 rtems_region_ident                                                    8
195 +21 rtems_port_ident                                                      8
196 +21 rtems_timer_ident                                                     8
197 +21 rtems_rate_monotonic_ident                                            8
198  
199  22 rtems_message_queue_broadcast: task readied -- returns to caller      27
200 -22 rtems_message_queue_broadcast: no waiting tasks                       6
201 -22 rtems_message_queue_broadcast: task readied -- preempts caller        22
202 +22 rtems_message_queue_broadcast: no waiting tasks                       2
203 +22 rtems_message_queue_broadcast: task readied -- preempts caller        16
204  
205 -23 rtems_timer_create                                                    4
206 -23 rtems_timer_fire_after: inactive                                      7
207 -23 rtems_timer_fire_after: active                                        7
208 -23 rtems_timer_cancel: active                                            4
209 -23 rtems_timer_cancel: inactive                                          3
210 -23 rtems_timer_reset: inactive                                           6
211 -23 rtems_timer_reset: active                                             7
212 -23 rtems_timer_fire_when: inactive                                       9
213 -23 rtems_timer_fire_when: active                                         9
214 -23 rtems_timer_delete: active                                            5
215 -23 rtems_timer_delete: inactive                                          4
216 -23 rtems_task_wake_when                                                  21
217 +23 rtems_timer_create                                                    3
218 +23 rtems_timer_fire_after: inactive                                      4
219 +23 rtems_timer_fire_after: active                                        4
220 +23 rtems_timer_cancel: active                                            2
221 +23 rtems_timer_cancel: inactive                                          1
222 +23 rtems_timer_reset: inactive                                           3
223 +23 rtems_timer_reset: active                                             3
224 +23 rtems_timer_fire_when: inactive                                       4
225 +23 rtems_timer_fire_when: active                                         4
226 +23 rtems_timer_delete: active                                            3
227 +23 rtems_timer_delete: inactive                                          3
228 +23 rtems_task_wake_when                                                  12
229  
230 -24 rtems_task_wake_after: yield -- returns to caller                     2
231 -24 rtems_task_wake_after: yields -- preempts caller                      12
232 +24 rtems_task_wake_after: yield -- returns to caller                     1
233 +24 rtems_task_wake_after: yields -- preempts caller                      9
234  
235 -25 rtems_clock_tick                                                      13
236 +25 rtems_clock_tick                                                      10
237  
238 -26 _ISR_Disable                                                           3
239 +26 _ISR_Disable                                                          3
240  26 _ISR_Flash                                                            1
241  26 _ISR_Enable                                                           0
242  26 _Thread_Disable_dispatch                                              1
243  26 _Thread_Enable_dispatch                                               3
244  26 _Thread_Set_state                                                     6
245 -26 _Thread_Disptach (NO FP)                                              13
246 -26 context switch: no floating point contexts                            10
247 +26 _Thread_Disptach (NO FP)                                              9
248 +26 context switch: no floating point contexts                            7
249  26 context switch: self                                                  1
250  26 context switch: to another task                                       2
251  26 fp context switch: restore 1st FP task -                              NA
252  26 fp context switch: save idle, restore initialized -                   NA
253  26 fp context switch: save idle, restore idle -                          NA
254  26 fp context switch: save initialized, restore initialized -            NA
255 -26 _Thread_Resume                                                        9
256 -26 _Thread_Unblock                                                       8
257 -26 _Thread_Ready                                                         5
258 -26 _Thread_Get                                                           1
259 +26 _Thread_Resume                                                        8
260 +26 _Thread_Unblock                                                       7
261 +26 _Thread_Ready                                                         4
262 +26 _Thread_Get                                                           0
263  26 _Semaphore_Get                                                        0
264  26 _Thread_Get: invalid id                                               0
265  
266 @@ -175,15 +175,15 @@
267  27 interrupt entry overhead: returns to nested interrupt                 0
268  27 interrupt exit overhead: returns to nested interrupt                  0
269  
270 -28 rtems_port_create                                                     13
271 -28 rtems_port_external_to_internal                                       3
272 -28 rtems_port_internal_to_external                                       3
273 -28 rtems_port_delete                                                     11
274 +28 rtems_port_create                                                     10
275 +28 rtems_port_external_to_internal                                       1
276 +28 rtems_port_internal_to_external                                       1
277 +28 rtems_port_delete                                                     8
278  
279 -29 rtems_rate_monotonic_create                                           13
280 -29 rtems_rate_monotonic_period: initiate period -- returns to caller     24
281 -29 rtems_rate_monotonic_period: obtain status                            5
282 -29 rtems_rate_monotonic_cancel                                           15
283 +29 rtems_rate_monotonic_create                                           12
284 +29 rtems_rate_monotonic_period: initiate period -- returns to caller     17
285 +29 rtems_rate_monotonic_period: obtain status                            3
286 +29 rtems_rate_monotonic_cancel                                           12
287  29 rtems_rate_monotonic_delete: inactive                                 12
288 -29 rtems_rate_monotonic_delete: active                                   7
289 -29 rtems_rate_monotonic_period: conclude periods -- caller blocks        13
290 +29 rtems_rate_monotonic_delete: active                                   4
291 +29 rtems_rate_monotonic_period: conclude periods -- caller blocks        9
292 Index: rtems/c/src/lib/libbsp/arm/csb336/console/uart.c
293 ===================================================================
294 --- rtems/c/src/lib/libbsp/arm/csb336/console/uart.c    (revision 42)
295 +++ rtems/c/src/lib/libbsp/arm/csb336/console/uart.c    (working copy)
296 @@ -1,262 +1,453 @@
297  /*
298 - *  console driver for MC9328XML UARTs
299 + * Console driver for MC9328XML UARTs.
300   *
301 - *  This driver uses the shared console driver in 
302 - *  ...../libbsp/shared/console.c
303 + * Written Jay Monkman <jtm@lopingdog.com>
304 + * Copyright (c) 2005 by Loping Dog Embedded Systems
305   *
306 - *  If you want the driver to be interrupt driven, you 
307 - *  need to write the ISR, and in the ISR insert the
308 - *  chars into termios's queue.
309 + * The license and distribution terms for this file may be
310 + * found in the file LICENSE in this distribution or at
311 + *    http://www.rtems.com/license
312   *
313 - *  Copyright (c) 2004 Cogent Computer Systems
314 - *  Written by Jay Monkman <jtm@lopingdog.com>
315 - *
316 - *  The license and distribution terms for this file may be
317 - *  found in the file LICENSE in this distribution or at
318 - *
319 - *  http://www.OARcorp.com/rtems/license.html.
320 - *
321 - *
322 - *  $Id$
323 -*/
324 -#include <bsp.h>                /* Must be before libio.h */
325 + * $Id:$
326 + */
327 +#include <bsp.h>
328  #include <rtems/libio.h>
329 +#include <libchip/sersupp.h>
330 +#include <rtems/error.h>
331 +#include <rtems/bspIo.h>
332  #include <termios.h>
333 -#include <rtems/bspIo.h>
334 -
335 -/* Put the CPU (or UART) specific header file #include here */
336 +#include <irq.h>
337  #include <mc9328mxl.h>
338 -#include <libchip/serial.h>
339 -#include <libchip/sersupp.h>
340  
341 +
342 +/* Define this to use interrupt driver UART driver */
343 +#define USE_INTERRUPTS 1
344 +
345  /* How many serial ports? */
346  #define NUM_DEVS       2
347 +#define poll_write(c)  imx_uart_poll_write_char(0, c)
348 +#define poll_read()  imx_uart_poll_read_char(0)
349  
350 -int     uart_poll_read(int minor);
351 +static int imx_uart_first_open(int, int, void *);
352 +static int imx_uart_last_close(int, int, void *);
353 +static int imx_uart_poll_read(int);
354 +static int imx_uart_set_attrs(int, const struct termios *);
355 +static void imx_uart_init(int minor);
356 +static void imx_uart_set_baud(int, int);
357 +static int imx_uart_poll_write(int, const char *, int);
358  
359 -int dbg_dly;
360 +#if defined(USE_INTERRUPTS) 
361 +static void imx_uart_tx_isr(rtems_irq_hdl_param);
362 +static void imx_uart_rx_isr(rtems_irq_hdl_param);
363 +static void imx_uart_isr_on(const rtems_irq_connect_data *irq);
364 +static void imx_uart_isr_off(const rtems_irq_connect_data *irq);
365 +static int imx_uart_isr_is_on(const rtems_irq_connect_data *irq);
366 +static int imx_uart_intr_write(int, const char *, int);
367 +#endif
368  
369 -/* static function prototypes */
370 -static int     uart_first_open(int major, int minor, void *arg);
371 -static int     uart_last_close(int major, int minor, void *arg);
372 -static int     uart_read(int minor);
373 -static int     uart_write(int minor, const char *buf, int len);
374 -static void    uart_init(int minor);
375 -static void    uart_write_polled(int minor, char c);
376 -static int     uart_set_attributes(int minor, const struct termios *t);
377  
378 -/* These are used by code in console.c */
379 -unsigned long Console_Port_Count = NUM_DEVS;
380 -console_data  Console_Port_Data[NUM_DEVS];
381  
382 -/* rtems console uses the following minor number */
383 -rtems_device_minor_number  Console_Port_Minor = 0;
384 -
385 -/* Pointers to functions for handling the UART. */
386 -console_fns uart_fns = 
387 -{ 
388 -    libchip_serial_default_probe,
389 -    uart_first_open,
390 -    uart_last_close,
391 -    uart_read,
392 -    uart_write,
393 -    uart_init,
394 -    uart_write_polled,   /* not used in this driver */
395 -    uart_set_attributes,
396 -    FALSE      /* TRUE if interrupt driven, FALSE if not. */
397 +/* TERMIOS callbacks */
398 +#if defined(USE_INTERRUPTS) 
399 +rtems_termios_callbacks imx_uart_cbacks = {
400 +    .firstOpen            = imx_uart_first_open,
401 +    .lastClose            = imx_uart_last_close,
402 +    .pollRead             = NULL,
403 +    .write                = imx_uart_intr_write,
404 +    .setAttributes        = imx_uart_set_attrs,
405 +    .stopRemoteTx         = NULL,
406 +    .startRemoteTx        = NULL,
407 +    .outputUsesInterrupts = 1,
408  };
409 +#else 
410 +rtems_termios_callbacks imx_uart_cbacks = {
411 +    .firstOpen            = imx_uart_first_open,
412 +    .lastClose            = imx_uart_last_close,
413 +    .pollRead             = imx_uart_poll_read,
414 +    .write                = imx_uart_poll_write,
415 +    .setAttributes        = imx_uart_set_attrs,
416 +    .stopRemoteTx         = NULL,
417 +    .startRemoteTx        = NULL,
418 +    .outputUsesInterrupts = 0,
419 +};
420 +#endif
421  
422 -/* 
423 - * There's one item in array for each UART.
424 - *
425 - * Some of these fields are marked "NOT USED". They are not used
426 - * by console.c, but may be used by drivers in libchip
427 - *
428 - */
429 -console_tbl Console_Port_Tbl[] = {
430 -    {
431 -        "/dev/com0",                      /* sDeviceName */
432 -        SERIAL_CUSTOM,                    /* deviceType */
433 -        &uart_fns,                        /* pDeviceFns */
434 -        NULL,                             /* deviceProbe */
435 -        NULL,                             /* pDeviceFlow */
436 -        0,                                /* ulMargin - NOT USED */
437 -        0,                                /* ulHysteresis - NOT USED */
438 -        NULL,                             /* pDeviceParams */
439 -        0,                                /* ulCtrlPort1  - NOT USED */
440 -        0,                                /* ulCtrlPort2  - NOT USED */
441 -        0,                                /* ulDataPort  - NOT USED */
442 -        NULL,                             /* getRegister - NOT USED */
443 -        NULL,                             /* setRegister - NOT USED */
444 -        NULL,                             /* getData - NOT USED */
445 -        NULL,                             /* setData - NOT USED */
446 -        0,                                /* ulClock - NOT USED */
447 -        0                                 /* ulIntVector - NOT USED */
448 -    },
449 -    {
450 -        "/dev/com1",                      /* sDeviceName */
451 -        SERIAL_CUSTOM,                    /* deviceType */
452 -        &uart_fns,                        /* pDeviceFns */
453 -        NULL,                             /* deviceProbe */
454 -        NULL,                             /* pDeviceFlow */
455 -        0,                                /* ulMargin - NOT USED */
456 -        0,                                /* ulHysteresis - NOT USED */
457 -        NULL,                             /* pDeviceParams */
458 -        0,                                /* ulCtrlPort1  - NOT USED */
459 -        0,                                /* ulCtrlPort2  - NOT USED */
460 -        0,                                /* ulDataPort  - NOT USED */
461 -        NULL,                             /* getRegister - NOT USED */
462 -        NULL,                             /* setRegister - NOT USED */
463 -        NULL,                             /* getData - NOT USED */
464 -        NULL,                             /* setData - NOT USED */
465 -        0,                                /* ulClock - NOT USED */
466 -        0                                 /* ulIntVector - NOT USED */
467 +#if defined(USE_INTERRUPTS) 
468 +static rtems_irq_connect_data imx_uart_tx_isr_data[NUM_DEVS];
469 +static rtems_irq_connect_data imx_uart_rx_isr_data[NUM_DEVS];
470 +#endif
471 +
472 +typedef struct {
473 +    int minor;
474 +    mc9328mxl_uart_regs_t * regs;
475 +    volatile const char *buf;
476 +    volatile int len;
477 +    volatile int idx;
478 +    void *tty;
479 +} imx_uart_data_t;
480 +
481 +static imx_uart_data_t imx_uart_data[NUM_DEVS];
482 +
483 +rtems_device_driver console_initialize(
484 +    rtems_device_major_number  major,
485 +    rtems_device_minor_number  minor,
486 +    void                      *arg
487 +)
488 +{
489 +    rtems_status_code status;
490 +    int i;
491 +
492 +    for (i = 0; i < NUM_DEVS; i++) {
493 +        imx_uart_init(i);
494      }
495 -};
496  
497 -/*********************************************************************/
498 -/* Functions called via termios callbacks (i.e. the ones in uart_fns */
499 -/*********************************************************************/
500 +    rtems_termios_initialize();
501  
502 -/* 
503 - * This is called the first time each device is opened. If the driver 
504 - * is interrupt driven, you should enable interrupts here. Otherwise, 
505 - * it's probably safe to do nothing.
506 - *
507 - * Since micromonitor already set up the UART, we do nothing.
508 - */
509 -static int uart_first_open(int major, int minor, void *arg) 
510 -{
511 -    return 0;
512 +    /* /dev/console and /dev/tty0 are the same */
513 +    status = rtems_io_register_name("/dev/console", major, 0);
514 +    if (status != RTEMS_SUCCESSFUL) {
515 +        rtems_panic("%s:%d Error registering /dev/console :: %d\n",
516 +                    __FUNCTION__, __LINE__, status);
517 +    }
518 +
519 +    status = rtems_io_register_name("/dev/tty0", major, 0);
520 +    if (status != RTEMS_SUCCESSFUL) {
521 +        rtems_panic("%s:%d Error registering /dev/tty0 :: %d\n",
522 +                    __FUNCTION__, __LINE__, status);
523 +    }
524 +
525 +    status = rtems_io_register_name("/dev/tty1", major, 1);
526 +    if (status != RTEMS_SUCCESSFUL) {
527 +        rtems_panic("%s:%d Error registering /dev/tty1 :: %d\n",
528 +                    __FUNCTION__, __LINE__, status);
529 +    }
530 +    return RTEMS_SUCCESSFUL;
531  }
532  
533 +rtems_device_driver console_open(
534 +    rtems_device_major_number major,
535 +    rtems_device_minor_number minor,
536 +    void                    * arg
537 +)
538 +{
539 +    rtems_status_code rc;
540  
541 -/* 
542 - * This is called the last time each device is closed. If the driver 
543 - * is interrupt driven, you should disable interrupts here. Otherwise, 
544 - * it's probably safe to do nothing.
545 - */
546 -static int uart_last_close(int major, int minor, void *arg) 
547 +    if (minor > (NUM_DEVS - 1)) {
548 +        return RTEMS_INVALID_NUMBER;
549 +    }
550 +
551 +    rc = rtems_termios_open(major, minor, arg, &imx_uart_cbacks);
552 +
553 +    return rc;
554 +}
555
556 +rtems_device_driver console_close(
557 +    rtems_device_major_number major,
558 +    rtems_device_minor_number minor,
559 +    void                    * arg
560 +)
561  {
562 -    return 0;
563 +    return rtems_termios_close(arg);
564  }
565
566 +rtems_device_driver console_read(
567 +    rtems_device_major_number major,
568 +    rtems_device_minor_number minor,
569 +    void                    * arg
570 +)
571 +{
572 +  return rtems_termios_read(arg);
573 +}
574
575 +rtems_device_driver console_write(
576 +    rtems_device_major_number major,
577 +    rtems_device_minor_number minor,
578 +    void                    * arg
579 +)
580 +{
581 +  return rtems_termios_write(arg);
582 +}
583
584 +rtems_device_driver console_control(
585 +    rtems_device_major_number major,
586 +    rtems_device_minor_number minor,
587 +    void                    * arg
588 +)
589 +{
590 +  return rtems_termios_ioctl(arg);
591 +}
592  
593 -
594 -/*
595 - * Read one character from UART.
596 - *
597 - * Return -1 if there's no data, otherwise return
598 - * the character in lowest 8 bits of returned int.
599 - */
600 -static int uart_read(int minor) 
601 +static void imx_uart_init(int minor)
602  {
603 -    char c;
604 +    imx_uart_data[minor].minor = minor;
605 +    imx_uart_data[minor].buf   = NULL;
606 +    imx_uart_data[minor].len   = 0;
607 +    imx_uart_data[minor].idx   = 0;
608  
609      if (minor == 0) {
610 -        if (MC9328MXL_UART1_SR2 & MC9328MXL_UART_SR2_RDR) {
611 -            c = MC9328MXL_UART1_RXD & MC9328MXL_UART_RXD_CHARMASK;
612 -            return c;
613 -        } else {
614 -            return -1;
615 -        }
616 +#if defined(USE_INTERRUPTS) 
617 +        imx_uart_tx_isr_data[minor].name = BSP_INT_UART1_TX;
618 +        imx_uart_rx_isr_data[minor].name = BSP_INT_UART1_RX;
619 +#endif
620 +        imx_uart_data[minor].regs = 
621 +            (mc9328mxl_uart_regs_t *) MC9328MXL_UART1_BASE;
622      } else if (minor == 1) {
623 -        if (MC9328MXL_UART2_SR2 & MC9328MXL_UART_SR2_RDR) {
624 -            c = MC9328MXL_UART2_RXD & MC9328MXL_UART_RXD_CHARMASK;
625 -            return c;
626 -        } else {
627 -            return -1;
628 -        }
629 +#if defined(USE_INTERRUPTS) 
630 +        imx_uart_tx_isr_data[minor].name = BSP_INT_UART2_TX;
631 +        imx_uart_rx_isr_data[minor].name = BSP_INT_UART2_RX;
632 +#endif
633 +        imx_uart_data[minor].regs = 
634 +            (mc9328mxl_uart_regs_t *) MC9328MXL_UART2_BASE;
635      } else {
636 -        printk("Unknown console minor number: %d\n", minor);
637 -        return -1;
638 +        rtems_panic("%s:%d Unknown UART minor number %d\n", 
639 +                    __FUNCTION__, __LINE__, minor); 
640      }
641  
642 +#if defined(USE_INTERRUPTS) 
643 +    imx_uart_tx_isr_data[minor].hdl    = imx_uart_tx_isr;
644 +    imx_uart_tx_isr_data[minor].handle = &imx_uart_data[minor];
645 +    imx_uart_tx_isr_data[minor].on     = imx_uart_isr_on;
646 +    imx_uart_tx_isr_data[minor].off    = imx_uart_isr_off;
647 +    imx_uart_tx_isr_data[minor].isOn   = imx_uart_isr_is_on;
648 +
649 +    imx_uart_rx_isr_data[minor].hdl    = imx_uart_rx_isr;
650 +    imx_uart_rx_isr_data[minor].handle = &imx_uart_data[minor];
651 +    imx_uart_rx_isr_data[minor].on     = imx_uart_isr_on;
652 +    imx_uart_rx_isr_data[minor].off    = imx_uart_isr_off;
653 +    imx_uart_rx_isr_data[minor].isOn   = imx_uart_isr_is_on;
654 +#endif
655 +
656 +    imx_uart_data[minor].regs->cr1 = (
657 +        MC9328MXL_UART_CR1_UARTCLKEN |
658 +        MC9328MXL_UART_CR1_UARTEN);
659 +
660 +    imx_uart_data[minor].regs->cr2 = (
661 +        MC9328MXL_UART_CR2_IRTS |
662 +        MC9328MXL_UART_CR2_WS   |
663 +        MC9328MXL_UART_CR2_TXEN |
664 +        MC9328MXL_UART_CR2_RXEN |
665 +        MC9328MXL_UART_CR2_SRST);
666 +
667 +    imx_uart_data[minor].regs->cr3 = 0;
668 +
669 +    imx_uart_data[minor].regs->cr4 = 0;
670 +
671 +    imx_uart_data[minor].regs->fcr = (
672 +        MC9328MXL_UART_FCR_TXTL(32) | 
673 +        MC9328MXL_UART_FCR_RFDIV_1 | 
674 +        MC9328MXL_UART_FCR_RXTL(1));
675 +
676 +    imx_uart_set_baud(minor, 38400);
677 +
678  }
679  
680 +static int imx_uart_first_open(int major, int minor, void *arg)
681 +{
682 +    rtems_libio_open_close_args_t *args = arg;
683  
684 -/* 
685 - * Write buffer to UART 
686 - *
687 - * return 1 on success, -1 on error
688 - */
689 -static int uart_write(int minor, const char *buf, int len)
690 +    imx_uart_data[minor].tty   = args->iop->data1;
691 +    
692 +#if defined(USE_INTERRUPTS) 
693 +    BSP_install_rtems_irq_handler(&imx_uart_tx_isr_data[minor]);
694 +    BSP_install_rtems_irq_handler(&imx_uart_rx_isr_data[minor]);
695 +
696 +    imx_uart_data[minor].regs->cr1 |= MC9328MXL_UART_CR1_RRDYEN;
697 +#endif
698 +
699 +    return 0;
700 +}
701 +
702 +static int imx_uart_last_close(int major, int minor, void *arg)
703  {
704 -    int i;
705 +#if defined(USE_INTERRUPTS) 
706 +    BSP_remove_rtems_irq_handler(&imx_uart_tx_isr_data[minor]);
707 +    BSP_remove_rtems_irq_handler(&imx_uart_rx_isr_data[minor]);
708 +#endif
709  
710 -    if (minor == 0) {
711 -        for (i = 0; i < len; i++) {
712 -            /* Wait for fifo to have room */
713 -            while(!(MC9328MXL_UART1_SR2 & MC9328MXL_UART_SR2_TXDC)) {
714 -                continue;
715 -            }
716 -            
717 -            MC9328MXL_UART1_TXD = (char) buf[i];
718 -        }
719 -    } else if (minor == 1) {
720 -        for (i = 0; i < len; i++) {
721 -            /* Wait for fifo to have room */
722 -            while(!(MC9328MXL_UART2_SR2 & MC9328MXL_UART_SR2_TXDC)) {
723 -                continue;
724 -            }
725 -            
726 -            MC9328MXL_UART2_TXD = (char) buf[i];
727 -        }
728 +    return 0;
729 +}
730 +
731 +static int imx_uart_poll_read(int minor) 
732 +{
733 +    if (imx_uart_data[minor].regs->sr2 & MC9328MXL_UART_SR2_RDR) {
734 +        return imx_uart_data[minor].regs->rxd & 0xff;
735      } else {
736 -        printk("Unknown console minor number: %d\n", minor);
737          return -1;
738      }
739 -    
740 -    return 1;
741  }
742  
743  
744 -/* Set up the UART. */
745 -static void uart_init(int minor)
746 +static int imx_uart_poll_write(int minor, const char *buf, int len) 
747  {
748 -        /* leave the debug sio port as setup by umon */
749 +    int i;
750 +    for (i = 0; i < len; i++) {
751 +        /* Wait for there to be room in the fifo */
752 +        while (!(imx_uart_data[minor].regs->sr2 & MC9328MXL_UART_SR2_TXDC)) {
753 +            continue;
754 +        }
755 +
756 +        imx_uart_data[minor].regs->txd = buf[i];
757 +    }
758 +    return 1;
759 +
760  }
761  
762 -/* I'm not sure this is needed for the shared console driver. */
763 -static void    uart_write_polled(int minor, char c)
764 +#if defined(USE_INTERRUPTS) 
765 +static int imx_uart_intr_write(int minor, const char *buf, int len)
766  {
767 -    uart_write(minor, &c, 1);
768 +    imx_uart_data[minor].buf = buf;
769 +    imx_uart_data[minor].len = len;
770 +    imx_uart_data[minor].idx = 0;
771 +        
772 +    imx_uart_data[minor].regs->cr1 |= MC9328MXL_UART_CR1_TXMPTYEN;
773 +
774 +    return 1;
775  }
776 +#endif
777  
778 +    
779  /* This is for setting baud rate, bits, etc. */
780 -static int     uart_set_attributes(int minor, const struct termios *t) 
781 +static int imx_uart_set_attrs(int minor, const struct termios *t) 
782  {
783 +    int baud;
784 +
785 +    baud = termios_baud_to_number(t->c_cflag & CBAUD);
786 +    imx_uart_set_baud(minor, baud);
787 +
788      return 0;
789  }
790  
791 -/***********************************************************************/
792 +#if defined(USE_INTERRUPTS) 
793 +static void imx_uart_isr_on(const rtems_irq_connect_data *irq)
794 +{
795 +    MC9328MXL_AITC_INTENNUM = irq->name;
796 +}
797 +static void imx_uart_isr_off(const rtems_irq_connect_data *irq)
798 +{
799 +    MC9328MXL_AITC_INTDISNUM = irq->name;
800 +}
801 +static int imx_uart_isr_is_on(const rtems_irq_connect_data *irq)
802 +{
803 +    int irq_num = (int)irq->name;
804 +    if (irq_num < 32) {
805 +        return MC9328MXL_AITC_INTENABLEL & (1 << irq_num);
806 +    } else {
807 +        return MC9328MXL_AITC_INTENABLEH & (1 << (irq_num - 32));
808 +    }
809 +}
810 +
811 +static void imx_uart_rx_isr(rtems_irq_hdl_param param)
812 +{
813 +    imx_uart_data_t *uart_data = param;
814 +    char buf[32];
815 +    int i=0;
816 +
817 +    while (uart_data->regs->sr2 & MC9328MXL_UART_SR2_RDR) {
818 +        buf[i] = uart_data->regs->rxd & 0xff;
819 +        i++;
820 +    }
821 +
822 +    rtems_termios_enqueue_raw_characters(uart_data->tty, buf, i);
823 +}
824 +
825 +static void imx_uart_tx_isr(rtems_irq_hdl_param param)
826 +{
827 +    imx_uart_data_t *uart_data = param;
828 +    int len;
829 +    int minor = uart_data->minor;
830 +
831 +
832 +    if (uart_data->idx < uart_data->len) {
833 +        while ( (uart_data->regs->sr1 & MC9328MXL_UART_SR1_TRDY) &&
834 +                (uart_data->idx < uart_data->len)) {
835 +            uart_data->regs->txd = uart_data->buf[uart_data->idx];
836 +            uart_data->idx++;
837 +        }
838 +    } else {
839 +        len = uart_data->len;
840 +        uart_data->len = 0;
841 +        imx_uart_data[minor].regs->cr1 &= ~MC9328MXL_UART_CR1_TXMPTYEN;
842 +        rtems_termios_dequeue_characters(uart_data->tty, len);
843 +    }
844 +}
845 +#endif
846 +
847  /*
848 - * The following functions are not used by TERMIOS, but other RTEMS
849 - * functions use them instead.
850 + * Set the UART's baud rate. The calculation is:
851 + *   (baud * 16) / ref_freq  = num/demom
852 + *
853 + *   ref_freq = perclk1 / RFDIV[2:0]
854 + *   BIR = num - 1
855 + *   BMR = demom - 1
856 + *
857 + * Setting 'num' to 16 yields this equation:
858 + *    demom = ref_freq / baud
859   */
860 -/***********************************************************************/
861 +static void imx_uart_set_baud(int minor, int baud)
862 +{
863 +    unsigned int perclk1;
864 +    unsigned int denom;
865 +    unsigned int ref_freq = 0;
866 +    uint32_t fcr;
867 +
868 +    perclk1 = get_perclk1_freq();
869 +    fcr = imx_uart_data[minor].regs->fcr;
870 +
871 +    switch(fcr & MC9328MXL_UART_FCR_RFDIV_MASK) {
872 +    case MC9328MXL_UART_FCR_RFDIV_1:  ref_freq = perclk1/1; break;
873 +    case MC9328MXL_UART_FCR_RFDIV_2:  ref_freq = perclk1/2; break;
874 +    case MC9328MXL_UART_FCR_RFDIV_3:  ref_freq = perclk1/3; break;
875 +    case MC9328MXL_UART_FCR_RFDIV_4:  ref_freq = perclk1/4; break;
876 +    case MC9328MXL_UART_FCR_RFDIV_5:  ref_freq = perclk1/5; break;
877 +    case MC9328MXL_UART_FCR_RFDIV_6:  ref_freq = perclk1/6; break;
878 +    case MC9328MXL_UART_FCR_RFDIV_7:  ref_freq = perclk1/7; break;
879 +    default:
880 +        rtems_panic("%s:%d Unknown RFDIV: 0x%x", 
881 +                    __FUNCTION__, __LINE__,
882 +                    fcr & MC9328MXL_UART_FCR_RFDIV_MASK);
883 +        break;
884 +    }
885 +    
886 +    denom = ref_freq / baud;
887 +
888 +    imx_uart_data[minor].regs->bir = 0xf;
889 +    imx_uart_data[minor].regs->bmr = denom;
890 +}
891 +
892 +
893  /* 
894 - * Read from UART. This is used in the exit code, and can't
895 - * rely on interrupts.
896 -*/
897 -int uart_poll_read(int minor)
898 + * Polled, non-blocking read from UART
899 + */
900 +int imx_uart_poll_read_char(int minor)
901  {
902 -    return uart_read(minor);
903 +    return imx_uart_poll_read(minor);
904  }
905  
906 +/* 
907 + * Polled, blocking write from UART
908 + */
909 +void  imx_uart_poll_write_char(int minor, char c)
910 +{
911 +    imx_uart_poll_write(minor, &c, 1);
912 +}
913  
914  /*
915 - * Write a character to the console. This is used by printk() and 
916 - * maybe other low level functions. It should not use interrupts or any
917 - * RTEMS system calls. It needs to be very simple
918 + * Functions for printk() and friends.
919   */
920 -static void _BSP_put_char( char c ) {
921 -    uart_write_polled(0, c);
922 +void _BSP_output_char(char c)
923 +{
924 +    poll_write(c);
925      if (c == '\n') {
926 -        uart_write_polled(0, '\r');
927 +        poll_write('\r');
928      }
929  }
930 +BSP_output_char_function_type BSP_output_char = _BSP_output_char;
931  
932 -BSP_output_char_function_type BSP_output_char = _BSP_put_char;
933  
934 +char _BSP_poll_char()
935 +{
936 +    return poll_read();
937 +}
938 +BSP_polling_getchar_function_type BSP_poll_char = _BSP_poll_char;
939  
940  
941 Index: rtems/c/src/lib/libbsp/arm/csb336/startup/bspstart.c
942 ===================================================================
943 --- rtems/c/src/lib/libbsp/arm/csb336/startup/bspstart.c        (revision 42)
944 +++ rtems/c/src/lib/libbsp/arm/csb336/startup/bspstart.c        (working copy)
945 @@ -86,9 +86,25 @@
946  /*   Since RTEMS is not configured, no RTEMS functions can be called.     */
947  /*                                                                        */
948  /**************************************************************************/
949 +void mmu_set_cpu_async_mode(void);
950  void bsp_start_default( void )
951  {
952 +    int i;
953  
954 +    /* Set the MCU prescaler to divide by 1 */
955 +    MC9328MXL_PLL_CSCR &= ~MC9328MXL_PLL_CSCR_PRESC;
956 +
957 +    /* Enable the MCU PLL */
958 +    MC9328MXL_PLL_CSCR |= MC9328MXL_PLL_CSCR_MPEN;
959 +
960 +    /* Delay to allow time for PLL to get going */
961 +    for (i = 0; i < 100; i++) {
962 +        asm volatile ("nop\n");
963 +    }
964 +
965 +    /* Set the CPU to asynchrous clock mode, so it uses its fastest clock */
966 +    mmu_set_cpu_async_mode();
967 +
968      /* disable interrupts */
969      MC9328MXL_AITC_INTENABLEL = 0;
970      MC9328MXL_AITC_INTENABLEH = 0;
971 @@ -153,12 +169,12 @@
972  /* Calcuate the frequency for perclk1 */
973  int get_perclk1_freq(void)
974  {
975 -    int fin;
976 -    int fpll;
977 -    int pd;
978 -    int mfd;
979 -    int mfi;
980 -    int mfn;
981 +    unsigned int fin;
982 +    unsigned int fpll;
983 +    unsigned int pd;
984 +    unsigned int mfd;
985 +    unsigned int mfi;
986 +    unsigned int mfn;
987      uint32_t reg;
988      int perclk1;
989  
990 @@ -187,13 +203,14 @@
991      printk("mfd = %d\n", mfd);
992      printk("mfi = %d\n", mfi);
993      printk("mfn = %d\n", mfn);
994 -    printk("(fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1));
995 -    printk("(fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n",
996 -           (fin * mfn) / ((pd + 1) * (mfd + 1)));
997 +    printk("rounded (fin * mfi) / (pd + 1) = %d\n", (fin * mfi) / (pd + 1));
998 +    printk("rounded (fin * mfn) / ((pd + 1) * (mfd + 1)) = %d\n",
999 +           ((long long)fin * mfn) / ((pd + 1) * (mfd + 1)));
1000  #endif
1001  
1002 -    fpll = 2 * ( ((fin * mfi) / (pd + 1)) +
1003 -                 ((fin * mfn) / ((pd + 1) * (mfd + 1))) );
1004 +    fpll = 2 * ( ((fin * mfi  + (pd + 1) / 2) / (pd + 1)) +
1005 +                 (((long long)fin * mfn + ((pd + 1) * (mfd + 1)) / 2) / 
1006 +                ((pd + 1) * (mfd + 1))) );
1007  
1008      /* calculate the output of the PERCLK1 divider */
1009      reg = MC9328MXL_PLL_PCDR;
1010 Index: rtems/c/src/lib/libbsp/arm/csb336/startup/linkcmds
1011 ===================================================================
1012 --- rtems/c/src/lib/libbsp/arm/csb336/startup/linkcmds  (revision 42)
1013 +++ rtems/c/src/lib/libbsp/arm/csb336/startup/linkcmds  (working copy)
1014 @@ -75,9 +75,6 @@
1015      rtems_vector_table = .;
1016      . += (8 * 4);                     /* 8 ARM interrupts */
1017         
1018 -    bsp_vector_table = .;
1019 -    . += (64 * 4);                    /* 64 MC9328MXL interrupts */
1020 -
1021      . = ALIGN (0x100);
1022  
1023  
1024 Index: rtems/c/src/lib/libbsp/arm/csb336/startup/exit.c
1025 ===================================================================
1026 --- rtems/c/src/lib/libbsp/arm/csb336/startup/exit.c    (revision 42)
1027 +++ rtems/c/src/lib/libbsp/arm/csb336/startup/exit.c    (working copy)
1028 @@ -29,7 +29,7 @@
1029     */
1030    printk("\n");
1031    printk(line);
1032 -  while (uart_poll_read(0) < 0) continue;
1033 +  while (BSP_poll_char() < 0) continue;
1034  
1035    bsp_reset();
1036  
1037 Index: rtems/c/src/lib/libbsp/arm/csb336/Makefile.am
1038 ===================================================================
1039 --- rtems/c/src/lib/libbsp/arm/csb336/Makefile.am       (revision 42)
1040 +++ rtems/c/src/lib/libbsp/arm/csb336/Makefile.am       (working copy)
1041 @@ -35,7 +35,7 @@
1042  startup_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
1043  
1044  noinst_PROGRAMS += console.rel
1045 -console_rel_SOURCES = console/uart.c ../../shared/console.c
1046 +console_rel_SOURCES = console/uart.c
1047  console_rel_CPPFLAGS = $(AM_CPPFLAGS)
1048  console_rel_LDFLAGS = $(RTEMS_RELLDFLAGS)
1049  
1050 Index: rtems/c/src/lib/libbsp/arm/csb336/network/network.c
1051 ===================================================================
1052 --- rtems/c/src/lib/libbsp/arm/csb336/network/network.c (revision 42)
1053 +++ rtems/c/src/lib/libbsp/arm/csb336/network/network.c (working copy)
1054 @@ -41,20 +41,20 @@
1055  /* RTEMS event used to start transmit daemon. */
1056  #define START_TRANSMIT_EVENT    RTEMS_EVENT_2
1057  
1058 -static rtems_isr enet_isr(rtems_vector_number vector);
1059 +static void enet_isr(rtems_irq_hdl_param);
1060  static void enet_isr_on(const rtems_irq_connect_data *unused);
1061  static void enet_isr_off(const rtems_irq_connect_data *unused);
1062  static int enet_isr_is_on(const rtems_irq_connect_data *irq);
1063  
1064  /* Replace the first value with the clock's interrupt name. */
1065 -rtems_irq_connect_data mc9328mxl_enet_isr_data = {BSP_INT_GPIO_PORTA,
1066 -                                                  (rtems_irq_hdl)enet_isr,
1067 -                                                  enet_isr_on,
1068 -                                                  enet_isr_off,
1069 -                                                  enet_isr_is_on,
1070 -                                                  3,    /* unused for ARM */
1071 -                                                  0 };  /* unused for ARM */
1072 -
1073 +rtems_irq_connect_data mc9328mxl_enet_isr_data = {
1074 +    .name    = BSP_INT_GPIO_PORTA,
1075 +    .hdl     = (rtems_irq_hdl)enet_isr,
1076 +    .handle  = (void *)BSP_INT_GPIO_PORTA,
1077 +    .on      = enet_isr_on,
1078 +    .off     = enet_isr_off,
1079 +    .isOn    = enet_isr_is_on,
1080 +};
1081  typedef struct {
1082    unsigned long rx_packets;        /* total packets received         */
1083    unsigned long tx_packets;        /* total packets transmitted      */
1084 @@ -102,7 +102,8 @@
1085  void mc9328mxl_enet_sendpacket (struct ifnet *ifp, struct mbuf *m);
1086  void mc9328mxl_enet_rx_task(void *arg);
1087  void mc9328mxl_enet_stats(mc9328mxl_enet_softc_t *sc);
1088 -static int mc9328mxl_enet_ioctl(struct ifnet *ifp, int command, caddr_t data);
1089 +static int mc9328mxl_enet_ioctl(struct ifnet *ifp, 
1090 +                                unsigned long command, caddr_t data);
1091  
1092  
1093  int rtems_mc9328mxl_enet_attach (
1094 @@ -631,7 +632,7 @@
1095  
1096  /*  Driver ioctl handler */
1097  static int
1098 -mc9328mxl_enet_ioctl (struct ifnet *ifp, int command, caddr_t data)
1099 +mc9328mxl_enet_ioctl (struct ifnet *ifp, unsigned long command, caddr_t data)
1100  {
1101      mc9328mxl_enet_softc_t *sc = ifp->if_softc;
1102      int error = 0;
1103 @@ -678,7 +679,7 @@
1104  }
1105  
1106  /* interrupt handler */
1107 -rtems_isr enet_isr (rtems_vector_number v)
1108 +static void enet_isr(rtems_irq_hdl_param unused)
1109  {
1110      uint16_t int_reg;
1111  
1112 Index: rtems/c/src/lib/libbsp/arm/shared/irq/irq_init.c
1113 ===================================================================
1114 --- rtems/c/src/lib/libbsp/arm/shared/irq/irq_init.c    (revision 42)
1115 +++ rtems/c/src/lib/libbsp/arm/shared/irq/irq_init.c    (working copy)
1116 @@ -30,21 +30,14 @@
1117  void  rtems_irq_mngt_init()
1118  {
1119      int                        i;
1120 -    long                       *vectorTable;
1121      rtems_interrupt_level       level;
1122  
1123 -    vectorTable = (long *) VECTOR_TABLE;
1124 -
1125      _CPU_ISR_Disable(level);
1126  
1127      /* First, connect the ISR_Handler for IRQ and FIQ interrupts */
1128      _CPU_ISR_install_vector(ARM_EXCEPTION_IRQ, _ISR_Handler, NULL);
1129      _CPU_ISR_install_vector(ARM_EXCEPTION_FIQ, _ISR_Handler, NULL);
1130  
1131 -     /* Initialize the vector table contents with default handler */
1132 -    for (i=0; i<BSP_MAX_INT; i++)
1133 -      *(vectorTable + i) = (long)(default_int_handler);
1134 -
1135      /* Initialize the INT at the BSP level */
1136      BSP_rtems_irq_mngt_init();
1137  }
1138 Index: rtems/c/src/lib/libbsp/arm/edb7312/irq/bsp_irq_init.c
1139 ===================================================================
1140 --- rtems/c/src/lib/libbsp/arm/edb7312/irq/bsp_irq_init.c       (revision 42)
1141 +++ rtems/c/src/lib/libbsp/arm/edb7312/irq/bsp_irq_init.c       (working copy)
1142 @@ -22,7 +22,16 @@
1143  void BSP_rtems_irq_mngt_init()
1144  {
1145         long int_stat;
1146 +        long *vectorTable;
1147 +        int i;
1148  
1149 +        vectorTable = (long *) VECTOR_TABLE;
1150 +
1151 +        /* Initialize the vector table contents with default handler */
1152 +        for (i=0; i<BSP_MAX_INT; i++) {
1153 +            *(vectorTable + i) = (long)(default_int_handler);
1154 +        }
1155 +
1156         /* mask all interrupts */
1157         *EP7312_INTMR1 = 0x0;
1158         *EP7312_INTMR2 = 0x0;
1159 Index: rtems/c/src/lib/libbsp/arm/gba/irq/bsp_irq_init.c
1160 ===================================================================
1161 --- rtems/c/src/lib/libbsp/arm/gba/irq/bsp_irq_init.c   (revision 42)
1162 +++ rtems/c/src/lib/libbsp/arm/gba/irq/bsp_irq_init.c   (working copy)
1163 @@ -29,6 +29,16 @@
1164   */
1165  void BSP_rtems_irq_mngt_init(void)
1166  {
1167 +  long *vectorTable;
1168 +  int i;
1169 +
1170 +  vectorTable = (long *) VECTOR_TABLE;
1171 +    
1172 +  /* Initialize the vector table contents with default handler */
1173 +  for (i=0; i<BSP_MAX_INT; i++) {
1174 +      *(vectorTable + i) = (long)(default_int_handler);
1175 +  }
1176 +
1177    /* clear all interrupt status flags */
1178    GBA_REG_IF = 0xffff;
1179    /* disable all interrupts */
1180 Index: rtems/c/src/lib/libcpu/arm/mc9328mxl/include/mc9328mxl.h
1181 ===================================================================
1182 --- rtems/c/src/lib/libcpu/arm/mc9328mxl/include/mc9328mxl.h    (revision 42)
1183 +++ rtems/c/src/lib/libcpu/arm/mc9328mxl/include/mc9328mxl.h    (working copy)
1184 @@ -131,6 +131,33 @@
1185  #define MC9328MXL_UART2_MPR4  (*((volatile uint32_t *)((MC9328MXL_UART2_BASE) + 0xcc)))
1186  #define MC9328MXL_UART2_TS    (*((volatile uint32_t *)((MC9328MXL_UART2_BASE) + 0xd0)))
1187  
1188 +typedef struct {
1189 +    volatile uint32_t rxd;
1190 +    volatile uint32_t _res0[15];
1191 +    volatile uint32_t txd;
1192 +    volatile uint32_t _res1[15];
1193 +    volatile uint32_t cr1;
1194 +    volatile uint32_t cr2;
1195 +    volatile uint32_t cr3;
1196 +    volatile uint32_t cr4;
1197 +    volatile uint32_t fcr;
1198 +    volatile uint32_t sr1;
1199 +    volatile uint32_t sr2;
1200 +    volatile uint32_t esc;
1201 +    volatile uint32_t tim;
1202 +    volatile uint32_t bir;
1203 +    volatile uint32_t bmr;
1204 +    volatile uint32_t brc;
1205 +    volatile uint32_t ipr1;
1206 +    volatile uint32_t ipr2;
1207 +    volatile uint32_t ipr3;
1208 +    volatile uint32_t ipr4;
1209 +    volatile uint32_t mpr1;
1210 +    volatile uint32_t mpr2;
1211 +    volatile uint32_t mpr3;
1212 +    volatile uint32_t mpr4;
1213 +    volatile uint32_t ts;
1214 +} mc9328mxl_uart_regs_t;
1215  
1216  #define MC9328MXL_UART_RXD_CHARRDY    (bit(15))
1217  #define MC9328MXL_UART_RXD_ERR        (bit(14))
1218 @@ -205,6 +232,17 @@
1219  #define MC9328MXL_UART_CR4_OREN       (bit(1))
1220  #define MC9328MXL_UART_CR4_DREN       (bit(0))
1221  
1222 +#define MC9328MXL_UART_FCR_TXTL(x)    (((x) & 0x3f) << 10)
1223 +#define MC9328MXL_UART_FCR_RFDIV_1    (5 << 7)
1224 +#define MC9328MXL_UART_FCR_RFDIV_2    (4 << 7)
1225 +#define MC9328MXL_UART_FCR_RFDIV_3    (3 << 7)
1226 +#define MC9328MXL_UART_FCR_RFDIV_4    (2 << 7)
1227 +#define MC9328MXL_UART_FCR_RFDIV_5    (1 << 7)
1228 +#define MC9328MXL_UART_FCR_RFDIV_6    (0 << 7)
1229 +#define MC9328MXL_UART_FCR_RFDIV_7    (6 << 7)
1230 +#define MC9328MXL_UART_FCR_RFDIV_MASK (7 << 7)
1231 +#define MC9328MXL_UART_FCR_RXTL(x)    (((x) & 0x3f) << 0)
1232 +
1233  #define MC9328MXL_UART_SR1_PARERR     (bit(15))
1234  #define MC9328MXL_UART_SR1_RTSS       (bit(14))
1235  #define MC9328MXL_UART_SR1_TRDY       (bit(13))
1236 Index: rtems/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c
1237 ===================================================================
1238 --- rtems/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c       (revision 42)
1239 +++ rtems/c/src/lib/libcpu/arm/mc9328mxl/clock/clockdrv.c       (working copy)
1240 @@ -28,13 +28,14 @@
1241  static int clock_isr_is_on(const rtems_irq_connect_data *irq);
1242  
1243  /* Replace the first value with the clock's interrupt name. */
1244 -rtems_irq_connect_data clock_isr_data = {BSP_INT_TIMER1,
1245 -                                         (rtems_irq_hdl)Clock_isr,
1246 -                                         clock_isr_on,
1247 -                                         clock_isr_off,
1248 -                                         clock_isr_is_on,
1249 -                                         3,     /* unused for ARM cpus */
1250 -                                         0 };   /* unused for ARM cpus */
1251 +rtems_irq_connect_data clock_isr_data = {
1252 +    .name   = BSP_INT_TIMER1,
1253 +    .hdl    = (rtems_irq_hdl)Clock_isr,
1254 +    .handle = (void *)BSP_INT_TIMER1,
1255 +    .on     = clock_isr_on,
1256 +    .off    = clock_isr_off,
1257 +    .isOn   = clock_isr_is_on,
1258 +};
1259  
1260  /* If you follow the code, this is never used, so any value 
1261   * should work
1262 @@ -82,7 +83,7 @@
1263          int cnt; \
1264          freq = get_perclk1_freq(); \
1265          printk("perclk1 freq is %d\n", freq); \
1266 -        cnt = ((freq / 1000) * BSP_Configuration.microseconds_per_tick) / 1000;\
1267 +        cnt = ((long long)freq * BSP_Configuration.microseconds_per_tick + 500000) / 1000000;\
1268          printk("cnt freq is %d\n", cnt); \
1269          MC9328MXL_TMR1_TCMP = cnt; \
1270          /* use PERCLK1 as input, enable timer */ \
1271 Index: rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/bsp_irq_asm.S
1272 ===================================================================
1273 --- rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/bsp_irq_asm.S      (revision 42)
1274 +++ rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/bsp_irq_asm.S      (working copy)
1275 @@ -31,13 +31,15 @@
1276  
1277    /* find the ISR's address based on the vector */     
1278    ldr   r0, =bsp_vector_table
1279 -  ldr  r0, [r0, r1, LSL #2]    /* Read the address */
1280 +  mov   r1, r1, LSL #3          /* Shift vector to get offset into table */
1281 +  add   r1, r0, r1              /* r1 has address of vector entry */
1282 +  ldr   r0, [r1, #4]            /* Get the data pointer */
1283 +  ldr  r1, [r1]                /* Get the vector */
1284  
1285 -
1286    stmdb          sp!,{lr}
1287    ldr     lr, =IRQ_return         /* prepare the return from handler  */
1288  
1289 -  mov     pc, r0               /* EXECUTE INT HANDLER */
1290 +  mov     pc, r1               /* EXECUTE INT HANDLER */
1291  
1292  IRQ_return:
1293    ldmia sp!,{lr}
1294 Index: rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/irq.h
1295 ===================================================================
1296 --- rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/irq.h      (revision 42)
1297 +++ rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/irq.h      (working copy)
1298 @@ -15,6 +15,8 @@
1299  #ifndef __IRQ_H__
1300  #define __IRQ_H__
1301  
1302 +#include <rtems/irq.h>
1303 +
1304  #ifdef __cplusplus
1305  extern "C" {
1306  #endif
1307 @@ -34,7 +36,7 @@
1308   * Constants
1309   **********************************************************************/
1310  
1311 -/* possible interrupt sources on the AT91RM9200 */
1312 +/* possible interrupt sources on the MC9328MXL */
1313  #define BSP_INT_UART3_PFERR       0 
1314  #define BSP_INT_UART3_RTS         1     
1315  #define BSP_INT_UART3_DTR         2     
1316 @@ -101,64 +103,21 @@
1317  #define BSP_INT_WDT              63
1318  #define BSP_MAX_INT              64
1319                
1320 -typedef unsigned char  rtems_irq_level;
1321 -typedef unsigned char  rtems_irq_trigger;
1322 +typedef struct {
1323 +    rtems_irq_hdl       vector;
1324 +    rtems_irq_hdl_param data;
1325 +} mc9328mxl_irq_info_t;
1326  
1327 -typedef unsigned int rtems_irq_number;
1328 -struct  __rtems_irq_connect_data__;     /* forward declaratiuon */
1329  
1330 -typedef void (*rtems_irq_hdl)       (void);
1331 -typedef void (*rtems_irq_enable)    (const struct __rtems_irq_connect_data__*);
1332 -typedef void (*rtems_irq_disable)   (const struct __rtems_irq_connect_data__*);
1333 -typedef int  (*rtems_irq_is_enabled)(const struct __rtems_irq_connect_data__*);
1334  
1335 -extern rtems_irq_hdl bsp_vector_table[BSP_MAX_INT];
1336 -#define VECTOR_TABLE bsp_vector_table
1337 -                                                                                          
1338 -typedef struct __rtems_irq_connect_data__ {
1339 -    /* IRQ line */
1340 -    rtems_irq_number              name;
1341 +extern mc9328mxl_irq_info_t bsp_vector_table[BSP_MAX_INT];
1342  
1343 -    /* Handler */
1344 -    rtems_irq_hdl                 hdl;
1345 -
1346 -    /* function for enabling interrupts at device level. */
1347 -    rtems_irq_enable              on;
1348 -
1349 -    /* function for disabling interrupts at device level. */
1350 -    rtems_irq_disable             off;
1351 -
1352 -    /* Function to test if interrupt is enabled */
1353 -    rtems_irq_is_enabled        isOn;
1354 -
1355 -    /* priority level of interrupt */
1356 -    rtems_irq_level               irqLevel;
1357 -
1358 -    /* Trigger method (rising/falling edge or high/low level) */
1359 -    rtems_irq_trigger             irqTrigger;
1360 -} rtems_irq_connect_data;
1361 -
1362  /*
1363   * function to initialize the interrupt for a specific BSP
1364   */
1365  void BSP_rtems_irq_mngt_init();
1366  
1367  
1368 -/*
1369 - * function to connect a particular irq handler.
1370 - */
1371 -int BSP_install_rtems_irq_handler       (const rtems_irq_connect_data*);
1372 -
1373 -/*
1374 - * function to get the current RTEMS irq handler for ptr->name. 
1375 - */
1376 -int BSP_get_current_rtems_irq_handler   (rtems_irq_connect_data* ptr);
1377 -
1378 -/*
1379 - * function to disconnect the RTEMS irq handler for ptr->name.
1380 - */
1381 -int BSP_remove_rtems_irq_handler        (const rtems_irq_connect_data*);
1382 -
1383  #endif /* __asm__ */
1384  
1385  #ifdef __cplusplus
1386 Index: rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/bsp_irq_init.c
1387 ===================================================================
1388 --- rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/bsp_irq_init.c     (revision 42)
1389 +++ rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/bsp_irq_init.c     (working copy)
1390 @@ -23,10 +23,11 @@
1391   */
1392  void BSP_rtems_irq_mngt_init()
1393  {
1394 -#if 0
1395 -    /* disable all interrupts */
1396 -    AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
1397 -#endif
1398 +    int i;
1399  
1400 +    for (i = 0; i < BSP_MAX_INT; i++) {
1401 +        bsp_vector_table[i].vector = default_int_handler;
1402 +        bsp_vector_table[i].data   = NULL;
1403 +    }
1404  }
1405  
1406 Index: rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/irq.c
1407 ===================================================================
1408 --- rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/irq.c      (revision 42)
1409 +++ rtems/c/src/lib/libcpu/arm/mc9328mxl/irq/irq.c      (working copy)
1410 @@ -16,6 +16,8 @@
1411  #include <rtems/score/apiext.h>
1412  #include <mc9328mxl.h>
1413  
1414 +mc9328mxl_irq_info_t bsp_vector_table[BSP_MAX_INT];
1415 +
1416  /*
1417   * This function check that the value given for the irq line
1418   * is valid.
1419 @@ -36,9 +38,6 @@
1420  int BSP_install_rtems_irq_handler  (const rtems_irq_connect_data* irq)
1421  {
1422      rtems_interrupt_level level;
1423 -    rtems_irq_hdl *bsp_tbl;
1424 -
1425 -    bsp_tbl = (rtems_irq_hdl *)&bsp_vector_table;
1426      
1427      if (!isValidInterrupt(irq->name)) {
1428        return 0;
1429 @@ -47,8 +46,8 @@
1430      /*
1431       * Check if default handler is actually connected. If not issue an error.
1432       */
1433 -    if (bsp_tbl[irq->name] != default_int_handler) {
1434 -      return 0;
1435 +    if (bsp_vector_table[irq->name].vector != default_int_handler) {
1436 +        return 0;
1437      }
1438  
1439      _CPU_ISR_Disable(level);
1440 @@ -56,7 +55,8 @@
1441      /*
1442       * store the new handler
1443       */
1444 -    bsp_tbl[irq->name] = irq->hdl;
1445 +    bsp_vector_table[irq->name].vector = irq->hdl;
1446 +    bsp_vector_table[irq->name].data = irq->handle;
1447  
1448      /*
1449       * Enable interrupt on device
1450 @@ -80,18 +80,15 @@
1451  int BSP_remove_rtems_irq_handler  (const rtems_irq_connect_data* irq)
1452  {
1453      rtems_interrupt_level level;
1454 -    rtems_irq_hdl *bsp_tbl;
1455  
1456 -    bsp_tbl = (rtems_irq_hdl *)&bsp_vector_table;
1457 -  
1458      if (!isValidInterrupt(irq->name)) {
1459        return 0;
1460      }
1461      /*
1462       * Check if the handler is actually connected. If not issue an error.
1463       */
1464 -    if (bsp_tbl[irq->name] != irq->hdl) {
1465 -      return 0;
1466 +    if (bsp_vector_table[irq->name].vector != irq->hdl) {
1467 +        return 0;
1468      }
1469  
1470      _CPU_ISR_Disable(level);
1471 @@ -106,8 +103,8 @@
1472      /*
1473       * restore the default irq value
1474       */
1475 -    bsp_tbl[irq->name] = default_int_handler;
1476 -    
1477 +    bsp_vector_table[irq->name].vector = default_int_handler;
1478 +    bsp_vector_table[irq->name].data = NULL;
1479  
1480      _CPU_ISR_Enable(level);
1481  
1482 Index: rtems/c/src/lib/libcpu/arm/shared/arm920/mmu.c
1483 ===================================================================
1484 --- rtems/c/src/lib/libcpu/arm/shared/arm920/mmu.c      (revision 42)
1485 +++ rtems/c/src/lib/libcpu/arm/shared/arm920/mmu.c      (working copy)
1486 @@ -151,7 +151,7 @@
1487  static inline uint32_t mmu_get_ctrl(void)
1488  {
1489      uint32_t val;
1490 -    asm volatile ("msr 15, 0, %0, cr1, cr0\n" : "=r" (val));
1491 +    asm volatile ("mrc 15, 0, %0, cr1, cr0\n" : "=r" (val));
1492      return val;
1493  }
1494  
1495 @@ -240,3 +240,13 @@
1496          base[i] = MMU_SET_LVL1_INVAL;
1497      }
1498  }
1499 +
1500 +
1501 +void mmu_set_cpu_async_mode(void)
1502 +{
1503 +    uint32_t reg;
1504 +    reg = mmu_get_ctrl();
1505 +    reg |= 0xc0000000;
1506 +    mmu_set_ctrl(reg);
1507 +}
1508 +    
1509 Index: rtems/c/src/lib/libcpu/arm/at91rm9200/irq/bsp_irq_init.c
1510 ===================================================================
1511 --- rtems/c/src/lib/libcpu/arm/at91rm9200/irq/bsp_irq_init.c    (revision 42)
1512 +++ rtems/c/src/lib/libcpu/arm/at91rm9200/irq/bsp_irq_init.c    (working copy)
1513 @@ -23,6 +23,16 @@
1514   */
1515  void BSP_rtems_irq_mngt_init()
1516  {
1517 +    long *vectorTable;
1518 +    int i;
1519 +
1520 +    vectorTable = (long *) VECTOR_TABLE;
1521 +
1522 +    /* Initialize the vector table contents with default handler */
1523 +    for (i=0; i<BSP_MAX_INT; i++) {
1524 +        *(vectorTable + i) = (long)(default_int_handler);
1525 +    }
1526 +
1527      /* disable all interrupts */
1528      AIC_CTL_REG(AIC_IDCR) = 0xffffffff;
1529  }
1530 Index: rtems/c/src/lib/libcpu/arm/s3c2400/irq/bsp_irq_init.c
1531 ===================================================================
1532 --- rtems/c/src/lib/libcpu/arm/s3c2400/irq/bsp_irq_init.c       (revision 42)
1533 +++ rtems/c/src/lib/libcpu/arm/s3c2400/irq/bsp_irq_init.c       (working copy)
1534 @@ -20,6 +20,16 @@
1535  
1536  void BSP_rtems_irq_mngt_init() 
1537  {
1538 +    long *vectorTable;
1539 +    int i;
1540 +
1541 +    vectorTable = (long *) VECTOR_TABLE;
1542 +
1543 +    /* Initialize the vector table contents with default handler */
1544 +    for (i=0; i<BSP_MAX_INT; i++) {
1545 +        *(vectorTable + i) = (long)(default_int_handler);
1546 +    }
1547 +
1548      /*
1549       * Here is the code to initialize the INT for
1550       * the specified BSP
1551 Index: rtems/make/custom/csb336.cfg
1552 ===================================================================
1553 --- rtems/make/custom/csb336.cfg        (revision 42)
1554 +++ rtems/make/custom/csb336.cfg        (working copy)
1555 @@ -22,12 +22,12 @@
1556  # -O4 is ok for RTEMS
1557  # NOTE2: some level of -O may be actually required by inline assembler (at least
1558  # -O2 so far.
1559 -CFLAGS_OPTIMIZE_V=-O3
1560 +CFLAGS_OPTIMIZE_V=-O3 -g
1561  #CFLAGS_OPTIMIZE_V=-O4 -mmultiple -mstring -mstrict-align
1562  
1563  # debug flags: typically none, but at least -O1 is required due to this
1564  # BSP using inlined code
1565 -CFLAGS_DEBUG_V = -O1
1566 +CFLAGS_DEBUG_V = -O1 -g
1567  #CFLAGS_DEBUG_V = -O1 -mmultiple -mstring -mstrict-align
1568  
1569