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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [i386/] [shared/] [io/] [printk.c] - Blame information for rev 602

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

Line No. Rev Author Line
1 30 unneback
/*-------------------------------------------------------------------------+
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: printk.c,v 1.2 2001-09-27 11:59:49 chris Exp $
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
+--------------------------------------------------------------------------*/
34
static void
35
printNum(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
+--------------------------------------------------------------------------*/
67
void
68
printk(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
 

powered by: WebSVN 2.1.0

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