File: gpsim_modules.cc

package info (click to toggle)
gpsim 0.32.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,640 kB
  • sloc: cpp: 121,258; asm: 54,223; ansic: 13,576; python: 9,708; sh: 4,695; makefile: 1,566; lex: 1,139; yacc: 854; pascal: 511; perl: 93; awk: 44; xml: 41
file content (229 lines) | stat: -rw-r--r-- 6,345 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/*
   Copyright (C) 1998,1999,2000 T. Scott Dattalo

This file is part of the libgpsim_modules library of gpsim

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see
<http://www.gnu.org/licenses/lgpl-2.1.html>.
*/

/*
  gpsim_modules.cc

  gpsim supports modules, or thingies, that are not part of gpsim proper.
This is to say, that the modules are not compiled and linked with the
core gpsim software. Instead, they are compiled and linked separately and
then dynamically loaded by gpsim. This approach provides a flexibility
to the user to create customized objects for simulation purposes. The
big benefit of course, is that the user doesn't have to get bogged down
in to the nitty-gritty details of the way gpsim is designed. The templates
provided here can serve as a relatively simple example of how one may
go about creating customized modules.

Please see the README.MODULES for more details on how modules are intended
to be used.

Here are a list of functions that a gpsim compliant module library should
support:

  void mod_list() - Prints a list of the modules in a library
  Module_Types * get_mod_list()  - Obtain pointer to the list of modules
*/

/* IN_MODULE should be defined for modules */
#define IN_MODULE

#include <cstdio>
#include <cstring>
#include <iostream>

#include "../config.h"    // get the definition for HAVE_GUI

#include "../src/modules.h"

#include "resistor.h"
#include "usart.h"
#ifndef _WIN32
//#include "paraface.h"
#endif
#include "switch.h"
#include "logic.h"
#include "led.h"
#ifdef HAVE_GUI
#include "push_button.h"
#include "video.h"
#include "encoder.h"
#endif
#include "m_stimuli.h"
#include "ttl.h"
#include "i2c-eeprom.h"
#include "i2c.h"
#include "i2c2par.h"


static Module_Types available_modules[] = {

#ifndef _WIN32
  // Parallel port interface
  /*
    TSD - removed 16APR06 - The parallel port interface uses the deprecated
    IOPORT class.
  { {"parallel_interface",         "paraface"}, Paraface::construct},
  */
#endif

  // Switch
  { {"switch",         "sw"}, Switches::Switch::construct},

  // Logic
  { {"and2", "and2"}, AND2Gate::construct},
  { {"or2",  "or2"},  OR2Gate::construct},
  { {"xor2", "xor2"}, XOR2Gate::construct},
  { {"not",  "not"},  NOTGate::construct},

  // Leds
  { {"led_7segments", "led7s"}, Leds::Led_7Segments::construct},
  { {"led", "led"}, Leds::Led::construct},
#ifdef HAVE_GUI
  { {"push_button",      "pb"},   PushButton::construct },
#endif
  { {"PortStimulus",     "ps"},   ExtendedStimuli::PortStimulus::construct8 },
/* these do not make sense RRR 20/9/2020 as registers are 8 bits wide
  { {"PortStimulus16",   "ps16"},   ExtendedStimuli::PortStimulus::construct16 },
  { {"PortStimulus32",   "ps32"},   ExtendedStimuli::PortStimulus::construct32 },
*/
  { {"pullup",           "pu"},   PullupResistor::pu_construct },
  { {"pulldown",         "pd"},   PullupResistor::pd_construct },
  { {"pulsegen",         "pg"},   ExtendedStimuli::PulseGen::construct },
  { {"FileRecorder",     "fr"},   ExtendedStimuli::FileRecorder::construct },
  { {"FileStimulus",     "fs"},   ExtendedStimuli::FileStimulus::construct },

#ifdef HAVE_GUI
  // PGS added back 23MAY10
  // TSD Removed 17APR06
  // Video
  { {"PAL_video", "video"}, Video::construct},

  // Encoder
  { {"Encoder", "encoder"}, Encoder::construct},
#endif
  // USART
  { {"usart",            "usart"}, USARTModule::USART_construct},

  // TTL devices
  { {"TTL165", "ttl165"}, TTL::TTL165::construct},
  { {"TTL377", "ttl377"}, TTL::TTL377::construct},
  { {"TTL595", "ttl595"}, TTL::TTL595::construct},

  // I2c EEPROM
  { {"I2C-EEPROM2k", "e24xx024"}, I2C_EEPROM_Modules::I2C_EE_Module::construct_2k},
  { {"I2C-EEPROM16k", "e24xx16b"}, I2C_EEPROM_Modules::I2C_EE_Module::construct_16k},
  { {"I2C-EEPROM256k", "e24xx256"}, I2C_EEPROM_Modules::I2C_EE_Module::construct_256k},
  { {"i2cmaster", "I2CMaster"},   I2C_Module::I2CMaster::construct },
  { {"i2c2par", "I2C2PAR"},   I2C2PAR_Modules::i2c2par::construct },

  // No more modules
  { {nullptr, nullptr}, nullptr}
};

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */


/********************************************************************************
 * mod_list - Display all of the modules in this library.
 *
 * This is a required function for gpsim compliant libraries.
 */

Module_Types *get_mod_list()
{
  return available_modules;
}


/********************************************************************************
 * mod_list - Display all of the modules in this library.
 *
 * This is a required function for gpsim compliant libraries.
 */
void mod_list()
{
  const size_t number_of = sizeof(available_modules) / sizeof(Module_Types);
  size_t i;
  size_t k;
  size_t longest = 0;

  for (i = 0; i < number_of; i++) {
    k = strlen(available_modules[i].names[1]);

    if (k > longest) {
      longest = k;
    }
  }

  k = 0;

  do {
    for (i = 0; (i < 4) && (k < number_of); i++) {
      std::cout << available_modules[k].names[1];

      if (i < 3) {
        const size_t l = longest + 2 - strlen(available_modules[k].names[1]);

        for (size_t j = 0; j < l; j++) {
          std::cout << ' ';
        }
      }

      k++;
    }

    std::cout << '\n';
  } while (k < number_of);
}


/************************************************************
 *
 * _init() - this is called when the library is opened.
 */
void init()
{
  //cout << "gpsim modules has been opened\n";
  printf("%s\n", __func__);
}


/************************************************************
 *
 * _fini() - this is called when the library is closed.
 */
void fini()
{
  //cout << "gpsim modules has been closed\n";
  printf("%s\n", __func__);
}


void test()
{
  //cout << "This is a test\n";
  printf("%s\n", __func__);
}

#ifdef __cplusplus
}
#endif /* __cplusplus */