simulavr  1.1.0
specialmem.cpp
Go to the documentation of this file.
1 /*
2  ****************************************************************************
3  *
4  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
5  * Copyright (C) 2001, 2002, 2003 Klaus Rudolph
6  * Copyright (C) 2009 Onno Kortmann
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  ****************************************************************************
23  *
24  * $Id$
25  */
26 #include <iostream>
27 #include <cstdlib>
28 #include "specialmem.h"
29 #include "avrerror.h"
30 
31 using namespace std;
32 
34  const string &tracename,
35  const string &filename):
36  RWMemoryMember(registry, tracename),
37  os(filename=="-" ? cout : ofs),
38  value(0)
39 {
40  if(filename != "-")
41  ofs.open(filename.c_str());
42 }
43 
44 void RWWriteToFile::set(unsigned char val) {
45  value = val;
46  os << val;
47  os.flush();
48 }
49 
50 unsigned char RWWriteToFile::get() const {
52  avr_warning("Invalid read access to RWWriteToFile register.");
53  return value;
54 }
55 
57  const string &tracename,
58  const string &filename):
59  RWMemoryMember(registry, tracename),
60  is((filename=="-") ? cin : ifs)
61 {
62  if(filename != "-")
63  ifs.open(filename.c_str());
64 }
65 
66 void RWReadFromFile::set(unsigned char val) {
68  avr_warning("Invalid write access to RWReadFromFile register with value %d.", (int)val);
69 }
70 
71 unsigned char RWReadFromFile::get() const {
72  char val;
73  is.get(val);
74  return val;
75 }
76 
77 
79  const string &tracename) :
80  RWMemoryMember(registry, tracename) {}
81 
82 
83 void RWExit::set(unsigned char c) {
84  avr_message("Exiting at simulated program request (write)");
87 }
88 
89 unsigned char RWExit::get() const {
90  avr_message("Exiting at simulated program request (read)");
93  return 0;
94 }
95 
97  const string &tracename) :
98  RWMemoryMember(registry, tracename) {}
99 
100 void RWAbort::set(unsigned char c) {
101  avr_warning("Aborting at simulated program request (write)");
104 }
105 
106 unsigned char RWAbort::get() const {
107  avr_warning("Aborting at simulated program request (read)");
110  return 0;
111 }
112 
void set(unsigned char)
Definition: specialmem.cpp:66
RWAbort(TraceValueRegister *registry, const std::string &tracename="")
Definition: specialmem.cpp:96
unsigned char get() const
Definition: specialmem.cpp:71
RWWriteToFile(TraceValueRegister *registry, const std::string &tracename, const std::string &filename)
Definition: specialmem.cpp:33
SystemConsoleHandler sysConHandler
The SystemConsoleHandler instance for common usage.
Definition: avrerror.cpp:234
TraceValueRegister * registry
Definition: rwmem.h:106
#define avr_message(...)
Definition: avrerror.h:132
STL namespace.
void void void ATTRIBUTE_NORETURN void ATTRIBUTE_NORETURN void AbortApplication(int code)
Aborts application: uses abort or exception depending on useExitAndAbort.
Definition: avrerror.cpp:202
ATTRIBUTE_NORETURN void ExitApplication(int code)
Exits application: uses exit or exception depending on useExitAndAbort.
Definition: avrerror.cpp:210
unsigned char get() const
Definition: specialmem.cpp:106
void set(unsigned char)
Definition: specialmem.cpp:44
void stopApplication(void)
Stop processing on all dumpers and removes it from dumpers list.
Definition: traceval.cpp:701
RWReadFromFile(TraceValueRegister *registry, const std::string &tracename, const std::string &filename)
Definition: specialmem.cpp:56
std::istream & is
Definition: specialmem.h:77
unsigned char get() const
Definition: specialmem.cpp:50
Build a register for TraceValue&#39;s.
Definition: traceval.h:442
void set(unsigned char)
Definition: specialmem.cpp:83
Member of any memory area in an AVR device.
Definition: rwmem.h:42
void set(unsigned char)
Definition: specialmem.cpp:100
std::ifstream ifs
Definition: specialmem.h:78
#define avr_warning(...)
Definition: avrerror.h:133
const std::string tracename
Definition: rwmem.h:107
unsigned char get() const
Definition: specialmem.cpp:89
bool global_suppress_memory_warnings
flag to suppress invalid memory usage warnings
Definition: avrerror.cpp:237
static DumpManager * Instance(void)
Singleton class access.
Definition: traceval.cpp:567
std::ofstream ofs
Definition: specialmem.h:53
unsigned char value
Definition: specialmem.h:56
std::ostream & os
Definition: specialmem.h:52
RWExit(TraceValueRegister *registry, const std::string &tracename="")
Definition: specialmem.cpp:78