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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libcsupport/] [src/] [printk.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*-------------------------------------------------------------------------+
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
|  printk.c,v 1.6 2002/04/08 18:29:16 joel Exp
19
+--------------------------------------------------------------------------*/
20
 
21
#if HAVE_CONFIG_H
22
#include "config.h"
23
#endif
24
 
25
#include <stdarg.h>
26
#include <stdio.h>
27
#include <rtems/bspIo.h>
28
 
29
/*-------------------------------------------------------------------------+
30
|         Function: printNum
31
|      Description: print number in a given base.
32
| Global Variables: None.
33
|        Arguments: num - number to print, base - base used to print the number.
34
|          Returns: Nothing.
35
+--------------------------------------------------------------------------*/
36
static void
37
printNum(long unsigned int num, int base, int sign, int maxwidth, int lead)
38
{
39
  long unsigned int n;
40
  int count;
41
  char toPrint[20];
42
 
43
  if ( (sign == 1) && ((long)num <  0) ) {
44
    BSP_output_char('-');
45
    num = -num;
46
    if (maxwidth) maxwidth--;
47
  }
48
 
49
  count = 0;
50
  while ((n = num / base) > 0) {
51
    toPrint[count++] = (num - (n*base));
52
    num = n ;
53
  }
54
  toPrint[count++] = num;
55
 
56
  if (maxwidth) {
57
    for (n=maxwidth-count ; n ; n-- )
58
      BSP_output_char(lead);
59
  }
60
 
61
  for (n = 0; n < count; n++){
62
    BSP_output_char("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]);
63
  }
64
} /* printNum */
65
 
66
 
67
/*-------------------------------------------------------------------------+
68
|         Function: printk
69
|      Description: a simplified version of printf intended for use when the
70
                    console is not yet initialized or in ISR's.
71
| Global Variables: None.
72
|        Arguments: as in printf: fmt - format string, ... - unnamed arguments.
73
|          Returns: Nothing.
74
+--------------------------------------------------------------------------*/
75
void
76
printk(char *fmt, ...)
77
{
78
  va_list  ap;      /* points to each unnamed argument in turn */
79
  char     c, *str;
80
  int      lflag, base, sign, width, lead;
81
  /* unsigned int level; */
82
 
83
  /* _CPU_ISR_Disable(level); */
84
 
85
  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
86
  for (; *fmt != '\0'; fmt++)
87
  {
88
    lflag = 0;
89
    base  = 0;
90
    sign = 0;
91
    width = 0;
92
    lead = ' ';
93
    if (*fmt == '%')
94
    {
95
      fmt++;
96
      if (*fmt == '0' ) {
97
        lead = '0';
98
        fmt++;
99
      }
100
      while (*fmt >= '0' && *fmt <= '9' ) {
101
        width *= 10;
102
        width += (*fmt - '0');
103
        fmt++;
104
      }
105
 
106
      if ((c = *fmt) == 'l')
107
      {
108
        lflag = 1;
109
        c = *++fmt;
110
      }
111
      switch (c)
112
      {
113
        case 'o': case 'O': base = 8; sign = 0; break;
114
        case 'd': case 'D': base = 10; sign = 1; break;
115
        case 'u': case 'U': base = 10; sign = 0; break;
116
        case 'x': case 'X': base = 16; sign = 0; break;
117
        case 's':
118
          for (str = va_arg(ap, char *); *str; str++)
119
            BSP_output_char(*str);
120
          break;
121
        case 'c':
122
#if 0
123
#if defined(_TMS320C3x) || defined(_TMS320C4x)
124
          BSP_output_char(va_arg(ap, int));
125
#else
126
          BSP_output_char(va_arg(ap, char));
127
#endif
128
#else
129
          BSP_output_char(va_arg(ap, int));
130
#endif
131
          break;
132
        default:
133
          BSP_output_char(c);
134
          break;
135
      } /* switch*/
136
 
137
      if (base)
138
        printNum(lflag ? va_arg(ap, long int) : (long int)va_arg(ap, int),
139
                 base, sign, width, lead);
140
    }
141
    else
142
    {
143
      BSP_output_char(*fmt);
144
    }
145
  }
146
  va_end(ap); /* clean up when done */
147
  /* _CPU_ISR_Enable(level); */
148
 
149
} /* printk */
150
 

powered by: WebSVN 2.1.0

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