source: rtems/c/src/lib/libbsp/i386/shared/io/printk.c @ b285860

4.104.114.84.95
Last change on this file since b285860 was de9edc4, checked in by Joel Sherrill <joel.sherrill@…>, on 08/31/98 at 22:56:20

Patch from Eric Valette <valette@…>:

Here is a brief description of the attached patch :

1) There was a bug in the code for the COM2 serial line driver. Aleksey
gave me a fix that fixes the driver code itself. I would like to thank
him again publicly,

2) I introduced constants in the serial driver code because I had a hard
time reading the meanning of hexadecimal values in the NS data book :)

3)You can now mix printk and printf on serial line (tested on COM2).
There is a #ifdef PRINTK_ON_SERIAL in console.c that enables to have
printk on console while printf on serial line,
4) Removed call to displayCpuInfo because anyway if was at the wrong
place for serial line console (too early). It can anyway be called at
application level,

5) The original printk was unable to display negative integer values
and was also recursive. It now works corectly,

All the modifications have been tested here on the COM2 port from
a PC running RTEMS to a PC running linux,

NB : there is still a bug on PC386 serial line : exit does not flush the
remaining output queue. As this is not a bug in the driver itself but
somewhere in PC386 initialization/termios relationship it will be part
of another patch.

NB2 : As Emmanuel excerced the exception hanlder code, while porting the
SMC driver to the new BSD stack, we found a bug in the exception
handler : it shall not delete the current thread in case we are running
at interrupt level. This will be part of another patch...

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*-------------------------------------------------------------------------+
2| printk.c v1.1 - PC386 BSP - 1997/08/07
3+--------------------------------------------------------------------------+
4| (C) Copyright 1997 -
5| - NavIST Group - Real-Time Distributed Systems and Industrial Automation
6|
7| http://pandora.ist.utl.pt
8|
9| Instituto Superior Tecnico * Lisboa * PORTUGAL
10+--------------------------------------------------------------------------+
11| Disclaimer:
12|
13| This file is provided "AS IS" without warranty of any kind, either
14| expressed or implied.
15+--------------------------------------------------------------------------+
16| This code is based on code by: Jose Rufino - IST
17|
18|  $Id$
19+--------------------------------------------------------------------------*/
20
21
22#include <stdarg.h>
23#include <stdio.h>
24#include <bspIo.h>
25#include <libcpu/cpu.h>
26
27/*-------------------------------------------------------------------------+
28|         Function: printNum
29|      Description: print number in a given base.
30| Global Variables: None.
31|        Arguments: num - number to print, base - base used to print the number.
32|          Returns: Nothing.
33+--------------------------------------------------------------------------*/
34static void
35printNum(long unsigned int num, int base, int sign)
36{
37  long unsigned int n;
38  int count;
39  char toPrint[20];
40
41  if ( (sign == 1) && ((long)num <  0) ) {
42    BSP_output_char('-');
43    num = -num;
44  }
45 
46  count = 0;
47  while ((n = num / base) > 0) {
48    toPrint[count++] = (num - (n*base));
49    num = n ;
50  }
51  toPrint[count++] = num;
52
53  for (n = 0; n < count; n++){
54    BSP_output_char("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]);
55  }
56} /* printNum */
57
58
59/*-------------------------------------------------------------------------+
60|         Function: printk
61|      Description: a simplified version of printf intended for use when the
62                    console is not yet initialized or in ISR's.
63| Global Variables: None.
64|        Arguments: as in printf: fmt - format string, ... - unnamed arguments.
65|          Returns: Nothing.
66+--------------------------------------------------------------------------*/
67void
68printk(char *fmt, ...)
69{
70  va_list  ap;      /* points to each unnamed argument in turn */
71  char     c, *str;
72  int      lflag, base, sign;
73  unsigned int level;
74
75  _CPU_ISR_Disable(level);
76 
77  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
78  for (; *fmt != '\0'; fmt++)
79  {
80    lflag = 0;
81    base  = 0;
82    sign = 0;
83    if (*fmt == '%')
84    {
85      if ((c = *++fmt) == 'l')
86      {
87        lflag = 1;
88        c = *++fmt;
89      }
90      switch (c)
91      {
92        case 'o': case 'O': base = 8; sign = 0; break;
93        case 'd': case 'D': base = 10; sign = 1; break;
94        case 'u': case 'U': base = 10; sign = 0; break;
95        case 'x': case 'X': base = 16; sign = 0; break;
96        case 's':
97          for (str = va_arg(ap, char *); *str; str++)
98            BSP_output_char(*str);
99          break;
100        case 'c':
101          BSP_output_char(va_arg(ap, char));
102          break;
103        default:
104          BSP_output_char(c);
105          break;
106      } /* switch*/
107
108      if (base)
109        printNum(lflag ? va_arg(ap, long int) : (long int)va_arg(ap, int),
110                 base, sign);
111    }
112    else
113    {
114      BSP_output_char(*fmt);
115    }
116  }
117  va_end(ap); /* clean up when done */
118  _CPU_ISR_Enable(level);
119
120} /* printk */
121
Note: See TracBrowser for help on using the repository browser.