OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [i960/] [rxgen960/] [console/] [serial.c] - Blame information for rev 30

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  $Id: serial.c,v 1.2 2001-09-27 11:59:58 chris Exp $
3
 */
4
 
5
#include "serial.h"
6
#include "rtems.h"
7
 
8
 
9
typedef unsigned char uchar ;           /* Abbreviations */
10
typedef unsigned short ushort ;
11
typedef unsigned long ulong ;
12
int DBGConsole_make_sync = 0;
13
#define CONSOLE_CHANNELS        1 
14
 
15
#define MAX_CONSOLE 4
16
static int consoles[MAX_CONSOLE];
17
static int active_consoles = 0;
18
static struct{
19
        rtems_id sem;
20
        int rx;
21
        int cnt;
22
        char in_line[128];
23
}cons_input[MAX_CONSOLE];
24
 
25
 
26
 
27
/* This uses the message out and in buffers as serial emulator.
28
        Pretty stupid eh?
29
*/
30
 
31
#define uart1   ((volatile unsigned char *)0x1318)
32
#define uart1_rx        ((volatile unsigned int *)0x1310)
33
 
34
#define NUM_UARTS 1
35
static volatile unsigned int * uart = { uart1 };
36
static volatile unsigned int * uart_rx = { uart1_rx };
37
 
38
 
39
extern void     display_msg(void);
40
/*extern int    sprintf();*/
41
 
42
 
43
 
44
int
45
console_uartinit(unsigned int BAUDRate)
46
{
47
#ifdef CONSOLE_CHANNELS
48
        void cons_isr();
49
        rpmu_attach_inmsg0(cons_isr);
50
#endif
51
        return(0);
52
}
53
 
54
 
55
/* Introduce a new console channel */
56
console_new(char * name)
57
{
58
#ifdef CONSOLE_CHANNELS
59
        unsigned int x, stat;
60
        x = 0xfe000000 | (name[0] << 16) | (name[1] << 8) | name[2];
61
        do {
62
                stat = *uart;
63
        } while (DBGConsole_make_sync && (stat != 0));
64
        *uart = x;
65
        x = ( name[3] << 24) | ( name[4] << 16) | ( name[5] << 8) |  name[6] ;
66
        do {
67
                stat = *uart;
68
        } while (DBGConsole_make_sync && (stat != 0));
69
        *uart = x;
70
        active_consoles += 1;
71
        rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &consoles[active_consoles] );
72
#endif
73
}
74
 
75
 
76
 
77
    /***********************************************************************
78
     ***  Transmit character to host.
79
     *** put the console ID in upper byte
80
     ***
81
     ***********************************************************************/
82
 
83
int console_sps_putc(int cc)
84
{
85
        register unsigned char  stat;
86
        int rtid, i;
87
        unsigned int ch;
88
        unsigned int level;
89
#ifdef CONSOLE_CHANNELS
90
        rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &rtid );
91
        ch = cc & 0xff;
92
        for(i=1; i <= active_consoles; i++){
93
                if( rtid == consoles[i]){
94
                        ch |= (i ) << 24 ;
95
                        break;
96
                }
97
        }
98
#else
99
        ch = cc;
100
#endif
101
 
102
        /*
103
         *  Pause until there is room in the UART transmit
104
         *  buffer.
105
         */
106
 
107
        if (ch == -1)
108
          return ch;
109
 
110
wait:
111
        do {
112
                stat = *uart;
113
        } while (DBGConsole_make_sync && (stat != 0));
114
        rtems_interrupt_disable(level);
115
        if( (*uart != 0) && DBGConsole_make_sync){
116
                rtems_interrupt_enable(level);
117
                goto wait;
118
        }
119
 
120
        /*
121
         *  Transmit data. (Junk)
122
         */
123
 
124
        *uart = ch;
125
        rtems_interrupt_enable(level);
126
        return cc;
127
 
128
}
129
 
130
 
131
    /*
132
      * putnum -- print a 32 bit number in hex
133
      */
134
     int
135
     putnum (num)
136
     unsigned int num;
137
     {
138
       char  buffer[9];
139
       int   count;
140
       int   digit;
141
 
142
       for (count = 7 ; count >= 0 ; count--) {
143
         digit = (num >> (count * 4)) & 0xf;
144
 
145
         if (digit <= 9)
146
           console_sps_putc( (char) ('0' + digit));
147
         else
148
           console_sps_putc( (char) ('A' - 10 + digit));
149
       }
150
     }
151
 
152
    /*
153
      * putmem -- print the specified memory block
154
      */
155
     void
156
     putmem (addr, num)
157
     char *addr;
158
     unsigned int num;
159
     {
160
       int i = 0;
161
       int j = 0;
162
       int val = 0;
163
       int digit = 0;
164
 
165
       console_sps_putc(13);
166
       console_sps_putc(10);
167
       putnum((unsigned int) addr);
168
       console_sps_putc(':');
169
       console_sps_putc(' ');
170
       while(num)
171
       {
172
         val = *addr;
173
 
174
         for (j = 0; j < 2; j++)
175
         {
176
           digit = (val & 0xf0) >> 4;
177
           val <<= 4;
178
 
179
           if (digit < 10)
180
           {
181
             console_sps_putc(digit + '0');
182
           }
183
           else
184
           {
185
             console_sps_putc(digit - 10 + 'A');
186
           }
187
         }
188
         console_sps_putc(' ');
189
 
190
         num--;
191
         addr++;
192
         if (++i == 16)
193
         {
194
           console_sps_putc(13);
195
           console_sps_putc(10);
196
           putnum((unsigned int) addr);
197
           console_sps_putc(':');
198
           console_sps_putc(' ');
199
           i = 0;
200
         }
201
       }
202
       console_sps_putc(13);
203
       console_sps_putc(10);
204
     }
205
 
206
    /*
207
      * putcmem -- print the specified pci config memory block
208
      */
209
     void
210
     putcmem (addr, num)
211
     unsigned char *addr;
212
     unsigned int num;
213
     {
214
       int i = 0;
215
       int j = 0;
216
       unsigned short val = 0;
217
       int digit = 0;
218
       unsigned int *satucmd = (unsigned int *) 0x1298;
219
       unsigned int *soccar = (unsigned int *) 0x12a8;
220
       unsigned int *soccdp = (unsigned int *) 0x12b0;
221
 
222
       *satucmd = 4;
223
 
224
       console_sps_putc(13);
225
       console_sps_putc(10);
226
       putnum((unsigned int) addr);
227
       console_sps_putc(':');
228
       console_sps_putc(' ');
229
       while(num)
230
       {
231
         *soccar =  (unsigned int) addr;
232
         val = *soccdp;
233
 
234
         for (j = 0; j < 4; j++)
235
         {
236
           digit = (val & 0xf000) >> 12;
237
           val <<= 4;
238
 
239
           if (digit < 10)
240
           {
241
             console_sps_putc(digit + '0');
242
           }
243
           else
244
           {
245
             console_sps_putc(digit - 10 + 'A');
246
           }
247
         }
248
         console_sps_putc(' ');
249
 
250
         num -= 2;
251
         addr += 2;
252
         if (++i == 8)
253
         {
254
           console_sps_putc(13);
255
           console_sps_putc(10);
256
           putnum((unsigned int) addr);
257
           console_sps_putc(':');
258
           console_sps_putc(' ');
259
           i = 0;
260
         }
261
       }
262
       console_sps_putc(13);
263
       console_sps_putc(10);
264
     }
265
 
266
    /***********************************************************************
267
     ***  Read character from host.
268
     ***********************************************************************/
269
#ifdef CONSOLE_CHANNELS
270
int console_sps_getc()
271
{
272
 
273
        int consinx;
274
        int rtid, i;
275
        unsigned int level, level2;
276
        char ch;
277
        consinx = 0;
278
        rtems_task_ident( RTEMS_SELF, RTEMS_SEARCH_ALL_NODES, &rtid );
279
        for(i=1; i <= active_consoles; i++){
280
                if( rtid == consoles[i]){
281
                        consinx = i ;
282
                        break;
283
                }
284
        }
285
        if( i > active_consoles)
286
                consinx = 0;
287
        if( cons_input[consinx].sem == 0){
288
                rtems_name sname;
289
                sname = rtems_build_name('S','U','X',(char)(consinx + '0'));
290
                rtems_semaphore_create(sname, 0, RTEMS_DEFAULT_ATTRIBUTES, 0, &cons_input[consinx].sem);
291
                cons_input[consinx].rx = 0;
292
        }
293
        while( cons_input[consinx].cnt == cons_input[consinx].rx){
294
                rtems_semaphore_obtain(cons_input[consinx].sem, RTEMS_WAIT, 0);
295
/*      rtems_task_wake_after( RTEMS_YIELD_PROCESSOR);*/
296
}
297
        rtems_interrupt_disable(level);
298
        i = cons_input[consinx].rx;
299
        ch = cons_input[consinx].in_line[i];
300
        i++;
301
        if( i >= sizeof( cons_input[consinx].in_line))
302
                i = 0;
303
        cons_input[consinx].rx = i;
304
        rtems_interrupt_enable(level);
305
        return ch;
306
}
307
 
308
 
309
void cons_isr()
310
{
311
        unsigned int i, chin,  consinx, st;
312
        chin = *uart_rx;
313
        consinx = chin >> 24;
314
        if( consinx > active_consoles)
315
                goto release;
316
        i = cons_input[consinx].cnt;
317
        cons_input[consinx].in_line[i] = chin & 0xff;
318
        i++;
319
        if( i >= sizeof( cons_input[consinx].in_line))
320
                i = 0;
321
        cons_input[consinx].cnt = i;
322
        st = rtems_semaphore_release( cons_input[consinx].sem);
323
release:
324
        *uart_rx = 0;
325
}
326
 
327
#else
328
volatile int console_foo = 0;
329
int console_sps_getc()
330
{
331
        volatile unsigned int   stat;
332
        register int    ch;
333
 
334
        stat = *uart_rx;
335
        while (stat == 0)
336
        {
337
                rtems_task_wake_after( RTEMS_YIELD_PROCESSOR );
338
                stat = *uart_rx;
339
                console_foo++;
340
        }
341
        *uart_rx = 0;
342
 
343
        ch = stat;
344
 
345
        return ch;
346
}
347
#endif
348
 
349
    /***********************************************************************
350
     ***  check character from host.
351
     ***********************************************************************/
352
 
353
int console_sps_kbhit()
354
{
355
        register unsigned short stat;
356
 
357
        stat = *uart;
358
        return ( stat != 0);
359
}
360
 
361
 
362
 
363
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.