/usr/include/gpsim/comparator.h is in gpsim-dev 0.26.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | /*
Copyright (C) 1998-2002 T. Scott Dattalo
Copyright (C) 2006,2010 Roy R. Rankin
This file is part of the libgpsim 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>.
*/
#ifndef __COMPARATOR_H__
#define __COMPARATOR_H__
/***************************************************************************
*
* Include file for: Processors with dual comparators and Voltage Refarence
*
*
*
***************************************************************************/
#define CFG_MASK 0x7
#define CFG_SHIFT 3
class CMSignalSource;
class VRSignalSource;
class CMCON;
class TMRL;
enum compare_inputs
{
AN0 = 0,
AN1,
AN2,
AN3,
VREF = 6, // use reference voltage
NO_IN = 7 // no input port
};
enum compare_outputs
{
OUT0 = 0,
OUT1,
ZERO = 6, // register value == 0
NO_OUT = 7 // no ouput port
};
class VRCON : public sfr_register
{
public:
CMCON *_cmcon;
enum VRCON_bits
{
VR0 = 1<<0, // VR0-3 Value selection
VR1 = 1<<1,
VR2 = 1<<2,
VR3 = 1<<3,
VRSS = 1<<4, // Use external references (16f88x)
VRR = 1<<5, // Range select
VROE = 1<<6, // Output Reference to external pin
VREN = 1<<7 // Enable Vref
};
VRCON(Processor *pCpu, const char *pName, const char *pDesc);
~VRCON();
virtual void put(unsigned int new_value);
virtual void setIOpin(PinModule *);
virtual double get_Vref();
void setValidBits(unsigned int mask) { valid_bits = mask;}
protected:
unsigned int valid_bits;
PinModule *vr_PinModule;
double vr_Vref;
stimulus *vr_pu;
stimulus *vr_pd;
stimulus *vr_06v;
double vr_Rhigh;
double vr_Rlow;
double Vref_high; // usually VDD
double Vref_low; // usually VSS
char *pin_name; // original name of pin
};
// VSCOM class with two comparators as per 16f690
//
class VRCON_2 : public sfr_register
{
public:
CMCON *_cmcon;
enum VRCON_bits
{
VR0 = 1<<0, // VR0-3 Value selection
VR1 = 1<<1,
VR2 = 1<<2,
VR3 = 1<<3,
VP6EN = 1<<4, // 0.6V reference enable
VRR = 1<<5, // Range select
C2VREN = 1<<6, // Comparator 2 Reference enable
C1VREN = 1<<7 // Comparator 1 Reference enable
};
VRCON_2(Processor *pCpu, const char *pName, const char *pDesc);
~VRCON_2();
virtual void put(unsigned int new_value);
protected:
unsigned int valid_bits;
PinModule *vr_PinModule;
double vr_Vref;
stimulus *vr_pu;
stimulus *vr_pd;
stimulus *vr_06v;
char *pin_name; // original name of pin
};
class CM_stimulus : public stimulus
{
public:
CM_stimulus(CMCON *arg, const char *n=0,
double _Vth=0.0, double _Zth=1e12
);
CMCON *_cmcon;
virtual void set_nodeVoltage(double v);
};
class CMCON1 : public sfr_register
{
public:
enum CMCON1_bits
{
CMSYNC = 1<<0,
T1GSS = 1<<1
};
virtual void put(unsigned int);
void set_tmrl(TMRL *arg) { m_tmrl = arg; }
CMCON1(Processor *pCpu, const char *pName, const char *pDesc);
~CMCON1();
private:
TMRL *m_tmrl;
};
class CMCON : public sfr_register
{
public:
VRCON *_vrcon;
enum CMCON_bits
{
CM0 = 1<<0,
CM1 = 1<<1,
CM2 = 1<<2,
CIS = 1<<3,
C1INV = 1<<4,
C2INV = 1<<5,
C1OUT = 1<<6,
C2OUT = 1<<7,
};
virtual void setINpin(int i, PinModule *);
virtual void setOUTpin(int i, PinModule *);
virtual void assign_pir_set(PIR_SET *new_pir_set);
virtual unsigned int get();
virtual void rename_pins(unsigned int) { cout << "CMCON::rename_pins() should not be called\n";}
virtual void put(unsigned int);
virtual void set_configuration(int comp, int mode, int il1, int ih1, int il2, int ih2, int out);
virtual double comp_voltage(int ind, int invert);
void set_tmrl(TMRL *arg) { m_tmrl = arg; }
void set_eccpas(ECCPAS *_eccpas) { m_eccpas = _eccpas; }
CMCON(Processor *pCpu, const char *pName, const char *pDesc);
~CMCON();
protected:
PinModule *cm_input[4];
PinModule *cm_output[2];
char *cm_input_pin[4];
char *cm_output_pin[2];
CMSignalSource *cm_source[2];
unsigned int m_CMval[2];
PIR_SET *pir_set;
TMRL *m_tmrl;
CM_stimulus *cm_stimulus[4];
ECCPAS *m_eccpas;
static const int cMaxConfigurations=8;
static const int cMaxComparators=2;
unsigned int m_configuration_bits[cMaxComparators][cMaxConfigurations];
};
class ComparatorModule
{
public:
ComparatorModule(Processor *);
void initialize( PIR_SET *pir_set, PinModule *pin_vr0, PinModule *pin_cm0,
PinModule *pin_cm1, PinModule *pin_cm2,
PinModule *pin_cm3, PinModule *pin_cm4, PinModule *pin_cm5);
//protected:
CMCON cmcon;
CMCON1 cmcon1;
VRCON vrcon;
};
/*
* Compare module for 16f88x processors
*/
class CM1CON0;
class CM1CON0_2;
class CM2CON0;
/*
* SRCON SR Latch Control Register
*/
class SRCON : public sfr_register
{
public:
enum SRCON_bits
{
FVREN = 1<<0, // Fixed Voltage Reference Enable
PULSR = 1<<2, // Pulse Reset of SR latch
PULSS = 1<<3, // Pulse set of SR Latch
C2REN = 1<<4, // C2OUT resets SR latch
C1SEN = 1<<5, // C1OUT sets SR latch
SR0 = 1<<6, // MUX SR Q out and C1OUT
SR1 = 1<<7 // MUX SR -Q out and C2OUT
};
int writable_bits;
bool SR_Q;
bool set;
bool reset;
virtual void put(unsigned int new_value);
SRCON(Processor *pCpu, const char *pName, const char *pDesc);
~SRCON(){}
};
/*
* CM2CON1 Comparator control register 1
*/
class CM2CON1 : public sfr_register
{
public:
enum CM2CON1_bits
{
C2SYNC = 1<<0, //C2 Output sync bit
T1GSS = 1<<1, // Timer1 Gate Source Select bit
C2RSEL = 1<<4, // C2 Reference Select bit
C1RSEL = 1<<5, // C1 Reference Select bit
MC2OUT = 1<<6, // Mirror C2OUT bit
MC1OUT = 1<<7 // Mirror C1OUT bit
};
int writable_bits;
CM1CON0 *m_cm1con0;
CM2CON0 *m_cm2con0;
virtual void put(unsigned int new_value);
void link_cm12con0(CM1CON0 *_cm1con0, CM2CON0 *_cm2con0);
CM2CON1(Processor *pCpu, const char *pName, const char *pDesc);
~CM2CON1(){}
};
/*
* CM12CON0 is common support for CM1CON0 AND CM2CON0
*/
class CM12CON0 : public sfr_register
{
public:
VRCON *m_vrcon;
enum CM12CON0_bits
{
CH0 = 1<<0, // Channel select bit 0
CH1 = 1<<1, // Channel select bit 1
R = 1<<2, // Reference select bit (non-inverting input)
POL = 1<<4, // Output polarity select bit
OE = 1<<5, // Output enable
OUT = 1<<6, // Output bit
ON = 1<<7, // Enable bit
};
virtual void put(unsigned int);
virtual unsigned int get();
virtual void setpins(PinModule * c12in0, PinModule * c12in1,
PinModule * c12in2, PinModule * c12in3, PinModule * cinPlus,
PinModule * cout);
virtual void state_change(unsigned int cmcon_val) { cout << "CM12CON:state_change should not be called\n"; }
virtual double CVref() { cout << "CM12CON:CVref should not be called\n"; return(0.);}
virtual void link_registers(PIR_SET *new_pir_set, CM2CON1 *_cm2con1,
VRCON *_vrcon, SRCON *_srcon, ECCPAS *_eccpas);
void set_tmrl(TMRL *arg) { m_tmrl = arg; }
CM12CON0(Processor *pCpu, const char *pName, const char *pDesc);
~CM12CON0();
protected:
friend class CM1CON0_2;
friend class CM1CON0;
friend class CM2CON1;
friend class CM2CON0;
PinModule *cm_input[5];
PinModule *cm_output;
CMSignalSource *cm_source;
CM2CON1 *m_cm2con1;
SRCON *m_srcon;
PIR_SET *pir_set;
TMRL *m_tmrl;
CM_stimulus *cm_stimulus[2];
Stimulus_Node *cm_snode[2];
ECCPAS *m_eccpas;
CM_stimulus *cm_cvref;
CM_stimulus *cm_v06ref;
};
class CM1CON0 : public CM12CON0
{
public:
CM1CON0(Processor *pCpu, const char *pName, const char *pDesc) :
CM12CON0(pCpu, pName, pDesc) {}
~CM1CON0(){}
virtual void state_change(unsigned int cmcon_val);
virtual double CVref();
};
class CM2CON0 : public CM12CON0
{
public:
CM2CON0(Processor *pCpu, const char *pName, const char *pDesc) :
CM12CON0(pCpu, pName, pDesc) {}
~CM2CON0() {}
virtual void state_change(unsigned int cmcon_val);
virtual double CVref();
};
class CM1CON0_2 : public CM12CON0
{
public:
CM1CON0_2(Processor *pCpu, const char *pName, const char *pDesc) :
CM12CON0(pCpu, pName, pDesc) {}
~CM1CON0_2(){}
virtual void state_change(unsigned int cmcon_val);
virtual double CVref();
};
class CM2CON0_2 : public CM12CON0
{
public:
CM2CON0_2(Processor *pCpu, const char *pName, const char *pDesc) :
CM12CON0(pCpu, pName, pDesc) {}
~CM2CON0_2() {}
virtual void state_change(unsigned int cmcon_val);
virtual double CVref();
};
#endif // __COMPARATOR_H__
|