srecord  1.65.0
mips_flash.h
Go to the documentation of this file.
1 //
2 // srecord - Manipulate EPROM load files
3 // Copyright (C) 2011 Peter Miller
4 //
5 // This program is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or (at your
8 // option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 // more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #ifndef SRECORD_OUTPUT_FILE_MIPS_FLASH_H
20 #define SRECORD_OUTPUT_FILE_MIPS_FLASH_H
21 
22 #include <srecord/output/file.h>
23 #include <srecord/endian.h>
24 
25 namespace srecord {
26 
27 /**
28  * The output_file_mips_flash class is used to write a MIPS-Flash
29  * formatted file.
30  */
32  public output_file
33 {
34 public:
35  /**
36  * The destructor.
37  */
39 
40  /**
41  * The create_le class method is used to create new dynamically
42  * allocated instances of this class, using little-endian byte
43  * ordering.
44  *
45  * @param file_name
46  * The name of the file to be written.
47  */
48  static pointer create_le(const std::string &file_name);
49 
50  /**
51  * The create_be class method is used to create new dynamically
52  * allocated instances of this class, using big-endian byte
53  * ordering.
54  *
55  * @param file_name
56  * The name of the file to be written.
57  */
58  static pointer create_be(const std::string &file_name);
59 
60 protected:
61  // See base class for documentation.
62  void write(const record &);
63 
64  // See base class for documentation.
65  void line_length_set(int);
66 
67  // See base class for documentation.
68  void address_length_set(int);
69 
70  // See base class for documentation.
71  int preferred_block_size_get(void) const;
72 
73  // See base class for documentation.
74  bool preferred_block_size_set(int nbytes);
75 
76  // See base class for documentation.
77  const char *format_name(void) const;
78 
79 private:
80  /**
81  * The constructor. It is private on purpose, use the #create_le
82  * or #create_be class method instead.
83  *
84  * @param file_name
85  * The name of the file to be written. The special name "-"
86  * indicates the standard output is to be used.
87  * @param endian
88  * The byte order to expect.
89  */
90  output_file_mips_flash(const std::string &file_name, endian_t endian);
91 
92  /**
93  * The write_inner method is used to write a single line (record)
94  * to the file. Use by the write() method.
95  */
96  void write_inner(int type, unsigned long addr, int addr_len,
97  const void *data, int data_len);
98 
99  /**
100  * The endia instance variable is used to remember whetehr this
101  * file is big-endian or little-endian.
102  */
103  endian_t endian;
104 
105  /**
106  * The address instance variable is used to remember the address at
107  * which the next byte is to be placed.
108  */
109  unsigned long address;
110 
111  /**
112  * The base instance variable is used to remember teh base address
113  * of the current flash segment.
114  */
115  unsigned long base;
116 
117  /**
118  * The base_set instance variable is used to remember whether or
119  * not the #base instance varaible has been set yet. This also
120  * implies no data has been seen yet.
121  */
122  bool base_set;
123 
124  /**
125  * The buffer instance variable is used to remember the accumulated
126  * data so far. Must be a multiple of 4 bytes long.
127  */
128  unsigned char buffer[256];
129 
130  /**
131  * The buffer_length instance variable is used to remember how many
132  * bytes of the #buffer array have been consumed to date.
133  */
134  size_t buffer_length;
135 
136  /**
137  * The buffer_flush method is used to write the #buffer_length
138  * bytes of data in the #buffer array to the file. The
139  * #buffer_length has been reset to zero on return.
140  */
141  void buffer_flush(void);
142 
143  /**
144  * The buffer_flush_newline method is used to write the datam,
145  * using the #buffer_flush method, and then issue a newline if the
146  * output is not at the beginning of a new line.
147  */
148  void buffer_flush_newline(void);
149 
150  /**
151  * The line_length instance variable is used to remember the
152  * preferred line length for the output, in fixed width character
153  * columns.
154  */
155  int line_length;
156 
157  /**
158  * The column instance variable is used to rememebr the current
159  * output column. If zero, it means we are positioned at the
160  * beginning of a new line of text.
161  */
162  int column;
163 
164  /**
165  * The default constructor. Do not use.
166  */
168 
169  /**
170  * The copy constructor. Do not use.
171  */
173 
174  /**
175  * The assignment operator. Do not use.
176  */
178 };
179 
180 };
181 
182 // vim: set ts=8 sw=4 et :
183 #endif // SRECORD_OUTPUT_FILE_MIPS_FLASH_H
The output_file_mips_flash class is used to write a MIPS-Flash formatted file.
Definition: mips_flash.h:33
int preferred_block_size_get(void) const
The preferred_block_size_get method is used to get the proferred block size of the output fformat.
void write(const record &)
The write method is used to write a recordonto an output.
void line_length_set(int)
The set_line_length method is used to set the maximum length of an output line, for those formats for...
static pointer create_le(const std::string &file_name)
The create_le class method is used to create new dynamically allocated instances of this class,...
void address_length_set(int)
The address_length_set method is used to set the minimum number of bytes to be written for addresses ...
const char * format_name(void) const
The format_name method is used to obtain the name of this output format.
virtual ~output_file_mips_flash()
The destructor.
static pointer create_be(const std::string &file_name)
The create_be class method is used to create new dynamically allocated instances of this class,...
bool preferred_block_size_set(int nbytes)
The preferred_block_size_set method is is to set a precific number of bytes for the preferred block s...
The srecord::output_file class is used to represent a generic output file.
Definition: file.h:35
std::shared_ptr< output > pointer
Definition: output.h:41
The srecord::record class is used to represent a data record read from a file.
Definition: record.h:35
endian_t
Definition: endian.h:27