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

Subversion Repositories bluespec-reedsolomon

[/] [bluespec-reedsolomon/] [trunk/] [bsv-reedsolomon/] [file_interface.cpp] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 abhiag
//----------------------------------------------------------------------//
2
// The MIT License 
3
// 
4
// Copyright (c) 2008 Abhinav Agarwal, Alfred Man Cheuk Ng
5
// Contact: abhiag@gmail.com
6
// 
7
// Permission is hereby granted, free of charge, to any person 
8
// obtaining a copy of this software and associated documentation 
9
// files (the "Software"), to deal in the Software without 
10
// restriction, including without limitation the rights to use,
11
// copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the
13
// Software is furnished to do so, subject to the following conditions:
14
// 
15
// The above copyright notice and this permission notice shall be
16
// included in all copies or substantial portions of the Software.
17
// 
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
// OTHER DEALINGS IN THE SOFTWARE.
26
//----------------------------------------------------------------------//
27
 
28
#include <iostream>
29
#include <fstream>
30
using namespace std;
31
 
32
 
33
extern "C"
34
{
35
   void loadByteStream (void);
36
   char getNextStreamByte (void);
37
   void storeByteStream (void);
38
   void putNextStreamByte (unsigned char byte);
39
   void putMACData (unsigned char n, unsigned char t);
40
   unsigned char isStreamActive (void);
41
   void closeOutputFile ();
42
}
43
 
44
 
45
ifstream ifs_Input;
46
ofstream ofs_Output;
47
 
48
 
49
//---------------------------------------------------------------------
50
void loadByteStream (void)
51
{
52
   cout << "  reading from file '" << DATA_FILE_PATH << "'" << endl;
53
   ifs_Input.open (DATA_FILE_PATH);
54
   if (false == ifs_Input.is_open ())
55
      cout << "[ERROR]  failed to open input file." << endl;
56
}
57
 
58
 
59
//---------------------------------------------------------------------
60
char getNextStreamByte (void)
61
{
62
   int byte;
63
   ifs_Input >> byte;
64
 
65
   if (true == ifs_Input.eof ())
66
      cout << "  end of file reached." << endl;
67
 
68
   return (unsigned char) byte;
69
}
70
 
71
 
72
//---------------------------------------------------------------------
73
void storeByteStream (void)
74
{
75
   cout << "  writing to file '" << OUT_DATA_FILE_PATH << "'" << endl;
76
   ofs_Output.open (OUT_DATA_FILE_PATH);
77
   if (false == ofs_Output.is_open ())
78
      cout << "[ERROR]  failed to open output file." << endl;
79
}
80
 
81
 
82
//---------------------------------------------------------------------
83
void putNextStreamByte (unsigned char byte)
84
{
85
   ofs_Output << (int) byte << endl;
86
}
87
 
88
 
89
//---------------------------------------------------------------------
90
void putMACData (unsigned char n, unsigned char t)
91
{
92
   ofs_Output << (int) n << ' ' << (int)t << endl;
93
}
94
 
95
 
96
//---------------------------------------------------------------------
97
unsigned char isStreamActive (void)
98
{
99
   return ((true == ifs_Input.is_open ()) && (false == ifs_Input.eof ()));
100
}
101
 
102
 
103
//---------------------------------------------------------------------
104
void closeOutputFile ()
105
{
106
   ofs_Output.flush ();
107
   ofs_Output.close ();
108
}

powered by: WebSVN 2.1.0

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