OpenCores
URL https://opencores.org/ocsvn/bluespec-h264/bluespec-h264/trunk

Subversion Repositories bluespec-h264

[/] [bluespec-h264/] [trunk/] [test/] [decoder/] [ldecod/] [src/] [filehandle.c] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jamey.hick
 
2
/*!
3
 **************************************************************************************
4
 * \file
5
 *    filehandle.c
6
 * \brief
7
 *     Trace file handling and standard error handling function.
8
 * \author
9
 *    Main contributors (see contributors.h for copyright, address and affiliation details)
10
 *      - Karsten Suehring            <suehring@hhi.de>
11
 ***************************************************************************************
12
 */
13
 
14
#include <stdlib.h>
15
 
16
#include "contributors.h"
17
#include "global.h"
18
#include "mbuffer.h"
19
 
20
/*!
21
 ************************************************************************
22
 * \brief
23
 *    Error handling procedure. Print error message to stderr and exit
24
 *    with supplied code.
25
 * \param text
26
 *    Error message
27
 * \param code
28
 *    Exit code
29
 ************************************************************************
30
 */
31
void error(char *text, int code)
32
{
33
  fprintf(stderr, "%s\n", text);
34
  flush_dpb();
35
  exit(code);
36
}
37
 
38
#if TRACE
39
 
40
static int bitcounter = 0;
41
 
42
/*!
43
 ************************************************************************
44
 * \brief
45
 *    Tracing bitpatterns for symbols
46
 *    A code word has the following format: 0 Xn...0 X2 0 X1 0 X0 1
47
 ************************************************************************
48
 */
49
void tracebits(
50
    const char *trace_str,  //!< tracing information, char array describing the symbol
51
    int len,                //!< length of syntax element in bits
52
    int info,               //!< infoword of syntax element
53
    int value1)
54
{
55
 
56
  int i, chars;
57
  // int outint = 1;
58
 
59
 
60
  if(len>=34)
61
  {
62
    snprintf(errortext, ET_SIZE, "Length argument to put too long for trace to work");
63
    error (errortext, 600);
64
  }
65
 
66
  putc('@', p_trace);
67
  chars = fprintf(p_trace, "%i", bitcounter);
68
  while(chars++ < 5)
69
    putc(' ',p_trace);
70
 
71
  chars += fprintf(p_trace, " %s", trace_str);
72
  while(chars++ < 55)
73
    putc(' ',p_trace);
74
 
75
  // Align bitpattern
76
  if(len<15)
77
  {
78
    for(i=0 ; i<15-len ; i++)
79
      fputc(' ', p_trace);
80
  }
81
 
82
  // Print bitpattern
83
  for(i=0 ; i<len/2 ; i++)
84
  {
85
    fputc('0', p_trace);
86
  }
87
  // put 1
88
  fprintf(p_trace, "1");
89
 
90
  // Print bitpattern
91
  for(i=0 ; i<len/2 ; i++)
92
  {
93
      if (0x01 & ( info >> ((len/2-i)-1)))
94
        fputc('1', p_trace);
95
      else
96
        fputc('0', p_trace);
97
  }
98
 
99
  fprintf(p_trace, " (%3d) \n", value1);
100
  bitcounter += len;
101
 
102
  fflush (p_trace);
103
 
104
}
105
 
106
/*!
107
 ************************************************************************
108
 * \brief
109
 *    Tracing bitpatterns
110
 ************************************************************************
111
 */
112
void tracebits2(
113
    const char *trace_str,  //!< tracing information, char array describing the symbol
114
    int len,                //!< length of syntax element in bits
115
    int info)
116
{
117
 
118
  int i, chars;
119
  // int outint = 1;
120
 
121
  if(len>=45)
122
  {
123
    snprintf(errortext, ET_SIZE, "Length argument to put too long for trace to work");
124
    error (errortext, 600);
125
  }
126
 
127
  putc('@', p_trace);
128
  chars = fprintf(p_trace, "%i", bitcounter);
129
  while(chars++ < 5)
130
    putc(' ',p_trace);
131
  chars += fprintf(p_trace, " %s", trace_str);
132
  while(chars++ < 55)
133
    putc(' ',p_trace);
134
 
135
  // Align bitpattern
136
  if(len<15)
137
    for(i=0 ; i<15-len ; i++)
138
      fputc(' ', p_trace);
139
 
140
 
141
  bitcounter += len;
142
  while (len >= 32)
143
  {
144
    for(i=0 ; i<8 ; i++)
145
    {
146
      fputc('0', p_trace);
147
    }
148
    len -= 8;
149
 
150
  }
151
  // Print bitpattern
152
  for(i=0 ; i<len ; i++)
153
  {
154
    if (0x01 & ( info >> (len-i-1)))
155
      fputc('1', p_trace);
156
    else
157
      fputc('0', p_trace);
158
  }
159
 
160
  fprintf(p_trace, " (%3d) \n", info);
161
 
162
  fflush (p_trace);
163
}
164
#endif
165
 

powered by: WebSVN 2.1.0

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