1 /*
2    Copyright (C) 1998-2002 T. Scott Dattalo
3    Copyright (C) 2006,2010,2013 Roy R. Rankin
4 
5 This file is part of the libgpsim library of gpsim
6 
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11 
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, see
19 <http://www.gnu.org/licenses/lgpl-2.1.html>.
20 */
21 
22 #ifndef SRC_COMPARATOR_H_
23 #define SRC_COMPARATOR_H_
24 
25 #include "14bit-tmrs.h"
26 
27 #include <cstdio>
28 #include <string>
29 
30 #include "registers.h"
31 #include "stimuli.h"
32 
33 class ADCON2_TRIG;
34 class CLC_BASE;
35 class COG;
36 class CM1CON0;
37 class CM2CON0;
38 class CM2CON1_V2;
39 class CMCON;
40 class CMSignalSource;
41 class CMxCON1;
42 class CMxSignalSource;
43 class CTMU;
44 class ComparatorModule2;
45 class ECCPAS;
46 class InterruptSource;
47 class PIR_SET;
48 class PinModule;
49 class Processor;
50 class SR_MODULE;
51 class T1GCON;
52 class TMRL;
53 
54 /***************************************************************************
55  *
56  * Include file for: Processors with dual comparators and Voltage Refarence
57  *
58  *
59  *
60  ***************************************************************************/
61 
62 #define CFG_MASK 0xf
63 #define CFG_SHIFT 4
64 
65 enum compare_inputs
66 {
67     AN0 = 0,
68     AN1,
69     AN2,
70     AN3,
71     AN4,
72     AN5,
73     VREF = 6,	// use reference voltage
74     NO_IN = 7,	// no input port
75     V06 = 8		// Reference voltage 0.6
76 };
77 
78 enum compare_outputs
79 {
80     OUT0 = 0,
81     OUT1,
82     ZERO = 6,	// register value == 0
83     NO_OUT = 7	// no ouput port
84 };
85 
86 class VRCON : public sfr_register
87 {
88 public:
89     VRCON(Processor *pCpu, const char *pName, const char *pDesc);
90     ~VRCON();
91 
92     enum VRCON_bits
93     {
94         VR0 = 1 << 0,	// VR0-3 Value selection
95         VR1 = 1 << 1,
96         VR2 = 1 << 2,
97         VR3 = 1 << 3,
98         VRSS = 1 << 4,	// Use external references (16f88x)
99         VRR = 1 << 5,	// Range select
100         VROE = 1 << 6,	// Output Reference to external pin
101         VREN = 1 << 7	// Enable Vref
102     };
103 
104     virtual void put(unsigned int new_value);
105     virtual void setIOpin(PinModule *);
106     virtual double get_Vref();
setValidBits(unsigned int mask)107     void setValidBits(unsigned int mask)
108     {
109         valid_bits = mask;
110     }
111 
112     CMCON *_cmcon = nullptr;
113 
114 protected:
115     unsigned int		valid_bits;
116     PinModule 		*vr_PinModule = nullptr;
117     double 		vr_Vref = 0.0;
118     stimulus		*vr_pu = nullptr;
119     stimulus		*vr_pd = nullptr;
120     stimulus		*vr_06v = nullptr;
121     double		vr_Rhigh = 0.0;
122     double		vr_Rlow = 0.0;
123     double		Vref_high = 0.0;	// usually VDD
124     double		Vref_low = 0.0;	// usually VSS
125 private:
126     std::string pin_name;	// original name of pin
127 };
128 
129 
130 // VSCOM class with two comparators as per 16f690
131 //
132 class VRCON_2 : public sfr_register
133 {
134 public:
135     VRCON_2(Processor *pCpu, const char *pName, const char *pDesc);
136     ~VRCON_2();
137 
138     enum VRCON_bits
139     {
140         VR0 = 1 << 0,	// VR0-3 Value selection
141         VR1 = 1 << 1,
142         VR2 = 1 << 2,
143         VR3 = 1 << 3,
144         VP6EN = 1 << 4,	// 0.6V reference enable
145         VRR = 1 << 5,	// Range select
146         C2VREN = 1 << 6,	// Comparator 2 Reference enable
147         C1VREN = 1 << 7	// Comparator 1 Reference enable
148     };
149 
150     virtual void put(unsigned int new_value);
151 
152     CMCON *_cmcon = nullptr;
153 
154 protected:
155     unsigned int valid_bits = 0;
156     PinModule 		*vr_PinModule = nullptr;
157     double 		vr_Vref = 0.0;
158     stimulus		*vr_pu;
159     stimulus		*vr_pd;
160     stimulus		*vr_06v;
161     char			*pin_name = nullptr;	// original name of pin
162 };
163 
164 
165 class CM_stimulus : public stimulus
166 {
167 public:
168     CM_stimulus(CMCON *arg, const char *n = nullptr,
169                 double _Vth = 0.0, double _Zth = 1e12
170                );
171     ~CM_stimulus();
172 
173     CMCON *_cmcon;
174 
175     virtual void   set_nodeVoltage(double v);
176 };
177 
178 
179 class CMv2_stimulus : public stimulus
180 {
181 public:
182     CMv2_stimulus(CM2CON1_V2 *arg, const char *n = nullptr,
183                   double _Vth = 0.0, double _Zth = 1e12
184                  );
185     ~CMv2_stimulus();
186 
187     CM2CON1_V2 *_cm2con1;
188 
189     virtual void   set_nodeVoltage(double v);
190 };
191 
192 
193 class CMCON1 : public sfr_register
194 {
195 public:
196     CMCON1(Processor *pCpu, const char *pName, const char *pDesc);
197     ~CMCON1();
198 
199     enum CMCON1_bits
200     {
201         CMSYNC = 1 << 0,
202         T1GSS  = 1 << 1
203     };
204 
205     virtual void put(unsigned int);
206 
set_tmrl(TMRL * arg)207     void set_tmrl(TMRL *arg)
208     {
209         m_tmrl = arg;
210     }
211 
212 private:
213     TMRL *m_tmrl = nullptr;
214     unsigned int valid_bits;
215 };
216 
217 
218 class CMCON : public sfr_register, public apfpin
219 {
220 public:
221     CMCON(Processor *pCpu, const char *pName, const char *pDesc);
222     ~CMCON();
223 
224     enum CMCON_bits
225     {
226         CM0 = 1 << 0,
227         CM1 = 1 << 1,
228         CM2 = 1 << 2,
229         CIS = 1 << 3,
230         C1INV = 1 << 4,
231         C2INV = 1 << 5,
232         C1OUT = 1 << 6,
233         C2OUT = 1 << 7,
234     };
235 
236     virtual void setINpin(int i, PinModule *, const char *an);
237     virtual void setIOpin(PinModule *, int i);
238     virtual void assign_pir_set(PIR_SET *new_pir_set);
239     virtual unsigned int get();
rename_pins(unsigned int)240     virtual void rename_pins(unsigned int)
241     {
242         puts("CMCON::rename_pins() should not be called");
243     }
244     virtual void put(unsigned int);
245     virtual void set_configuration(int comp, int mode, int il1, int ih1, int il2, int ih2, int out);
246     virtual double comp_voltage(int ind, int invert);
247 
248     void releasePin(int);
249 
set_tmrl(TMRL * arg)250     void set_tmrl(TMRL *arg)
251     {
252         m_tmrl = arg;
253     }
set_eccpas(ECCPAS * _eccpas)254     void set_eccpas(ECCPAS *_eccpas)
255     {
256         m_eccpas = _eccpas;
257     }
258 
259     VRCON *_vrcon = nullptr;
260 
261 protected:
262     PinModule *cm_input[4];
263     PinModule *cm_output[2];
264 private:
265     std::string cm_input_pin[4];
266     std::string cm_an[4];
267     std::string cm_output_pin[2];
268 protected:
269     CMSignalSource *cm_source[2];
270     bool	cm_source_active[2];
271     unsigned int m_CMval[2];
272     PIR_SET *pir_set = nullptr;
273     TMRL *m_tmrl = nullptr;
274     CM_stimulus *cm_stimulus[6];
275     ECCPAS 	*m_eccpas = nullptr;
276 
277     static const int cMaxConfigurations = 8;
278     static const int cMaxComparators = 2;
279 
280     guint32 m_configuration_bits[cMaxComparators][cMaxConfigurations];
281 };
282 
283 
284 class ComparatorModule
285 {
286 public:
287     explicit ComparatorModule(Processor *);
288 
289     void initialize(PIR_SET *pir_set, PinModule *pin_vr0, PinModule *pin_cm0,
290                     PinModule *pin_cm1, PinModule *pin_cm2,
291                     PinModule *pin_cm3, PinModule *pin_cm4, PinModule *pin_cm5);
292     //protected:
293     CMCON cmcon;
294     CMCON1 cmcon1;
295     VRCON vrcon;
296 };
297 
298 
299 /*
300  * Compare module for 16f88x processors
301  */
302 
303 /*
304  * SRCON SR Latch Control Register
305  */
306 class SRCON  : public sfr_register
307 {
308 public:
309     SRCON(Processor *pCpu, const char *pName, const char *pDesc);
~SRCON()310     ~SRCON() {}
311 
312     enum SRCON_bits
313     {
314         FVREN = 1 << 0, // Fixed Voltage Reference Enable
315         PULSR = 1 << 2, // Pulse Reset of SR latch
316         PULSS = 1 << 3, // Pulse set of SR Latch
317         C2REN = 1 << 4, // C2OUT resets SR latch
318         C1SEN = 1 << 5, // C1OUT sets SR latch
319         SR0   = 1 << 6, // MUX SR Q out and C1OUT
320         SR1   = 1 << 7 // MUX SR -Q out and C2OUT
321     };
322     int writable_bits;
323     bool SR_Q;
324     bool set;
325     bool reset;
326 
327     virtual void put(unsigned int new_value);
328 };
329 
330 
331 /*
332  * CM2CON1 Comparator control register 1
333  */
334 class CM2CON1 : public sfr_register
335 {
336 public:
337     CM2CON1(Processor *pCpu, const char *pName, const char *pDesc);
~CM2CON1()338     ~CM2CON1() {}
339 
340     enum CM2CON1_bits
341     {
342         C2SYNC = 1 << 0, //C2 Output sync bit
343         T1GSS  = 1 << 1, // Timer1 Gate Source Select bit
344         C2RSEL = 1 << 4, // C2 Reference Select bit
345         C1RSEL = 1 << 5, // C1 Reference Select bit
346         MC2OUT = 1 << 6, // Mirror C2OUT bit
347         MC1OUT = 1 << 7 // Mirror C1OUT bit
348     };
349     int writable_bits;
350     CM1CON0 *m_cm1con0;
351     CM2CON0 *m_cm2con0;
352 
353     virtual void put(unsigned int new_value);
354     void link_cm12con0(CM1CON0 *_cm1con0, CM2CON0 *_cm2con0);
355 };
356 
357 
358 // The following classes are for comparators which have 3 registers
359 //
360 
361 class CMxCON0_base : public sfr_register
362 {
363 public:
364     CMxCON0_base(Processor *pCpu, const char *pName, const char *pDesc,
365                  unsigned int _cm, ComparatorModule2 *cmModule);
366     ~CMxCON0_base();
367 
368     enum
369     {
370         ON = 1 << 7,
371         OE = 1 << 5
372     };
373     virtual unsigned int get();
get_Vpos()374     virtual double get_Vpos()
375     {
376         return 0.0;
377     }
get_Vneg()378     virtual double get_Vneg()
379     {
380         return 0.0;
381     }
put(unsigned int)382     virtual void put(unsigned int)
383     {
384         puts("Help");
385     }
386     //    virtual int get(){return 0;}
setBitMask(unsigned int bm)387     virtual void setBitMask(unsigned int bm)
388     {
389         mValidBits = bm;
390     }
setIntSrc(InterruptSource * _IntSrc)391     virtual void setIntSrc(InterruptSource *_IntSrc)
392     {
393         IntSrc = _IntSrc;
394     }
CVref()395     virtual double CVref()
396     {
397         return 0.0;
398     }
notify()399     virtual void notify() {}
output_active()400     virtual bool output_active()
401     {
402         return value.get() & (ON | OE);
403     }
get_hysteresis()404     virtual double get_hysteresis()
405     {
406         return 0.0;
407     }
output_high()408     virtual bool output_high()
409     {
410         return false;
411     }
set_output(bool)412     virtual void set_output(bool /* output */ ) {}
is_on()413     virtual bool is_on()
414     {
415         return false;
416     }
out_invert()417     virtual bool out_invert()
418     {
419         return true;
420     }
releasePin()421     virtual void releasePin()
422     {
423         cm_source_active = false;
424     }
425 
426     unsigned int mValidBits = 0;
427     PinModule     *cm_input[5];
428     PinModule     *cm_output = nullptr;
429     CM2CON1       *m_cm2con1 = nullptr;
430     SRCON         *m_srcon = nullptr;
431     //  PIR_SET       *pir_set;
432     InterruptSource *IntSrc = nullptr;
433     //  TMRL          *m_tmrl;
434     CM_stimulus   *cm_stimulus[2];
435     Stimulus_Node *cm_snode[2];
436     ECCPAS        *m_eccpas = nullptr;
437     unsigned int      cm;	// comparator number
438     CMxCON1	    *m_cmxcon1 = nullptr;
439     ComparatorModule2 *m_cmModule;
440     CMxSignalSource   *cm_source = nullptr;
441     bool              cm_source_active = false;
442 };
443 
444 
445 class CMxCON0 : public CMxCON0_base
446 {
447 public:
448     CMxCON0(Processor *pCpu, const char *pName, const char *pDesc, unsigned int x, ComparatorModule2 *);
449     ~CMxCON0();
450 
451     enum
452     {
453         CxSYNC 	= 1 << 0,	// Output Synchronous Mode bit
454         CxHYS 	= 1 << 1,	// Hysteresis Enable bit
455         CxSP   	= 1 << 2,	// Speed/Power Select bit
456         CxZLF	= 1 << 3, // Zero Latency Filter Enable bit
457         CxPOL 	= 1 << 4,	// Output polarity select bit
458         CxOE  	= 1 << 5,	// Output enable
459         CxOUT 	= 1 << 6,	// Output bit
460         CxON  	= 1 << 7,	// Enable bit
461     };
462 
463     void put(unsigned int);
464     virtual double get_Vpos();
465     virtual double get_Vneg();
setBitMask(unsigned int bm)466     void setBitMask(unsigned int bm)
467     {
468         mValidBits = bm;
469     }
is_on()470     virtual bool is_on()
471     {
472         return (value.get() & CxON);
473     }
out_invert()474     virtual bool out_invert()
475     {
476         return value.get() & CxPOL;
477     }
478     virtual double get_hysteresis();
479     virtual void set_output(bool output);
output_high()480     virtual bool output_high()
481     {
482         return value.get() & CxOUT;
483     }
484 };
485 
486 
487 class CMxCON0_V2 : public CMxCON0_base
488 {
489 public:
490     CMxCON0_V2(Processor *pCpu, const char *pName, const char *pDesc,
491                unsigned int _cm, ComparatorModule2 *cmModule);
492     ~CMxCON0_V2();
493 
494     enum
495     {
496         CxCH0 = 1 << 0,	// Channel select bit 0
497         CxCH1 = 1 << 1,	// Channel select bit 1
498         CxR   = 1 << 2,	// Reference select bit (non-inverting input)
499         CxPOL = 1 << 4,	// Output polarity select bit
500         CxOE  = 1 << 5,	// Output enable
501         CxOUT = 1 << 6,	// Output bit
502         CxON  = 1 << 7,	// Enable bit
503         NEG	= 0,
504         POS	= 1,
505     };
506 
507     virtual void put(unsigned int);
508     virtual double get_Vpos();
509     virtual double get_Vneg();
setBitMask(unsigned int bm)510     void setBitMask(unsigned int bm)
511     {
512         mValidBits = bm;
513     }
is_on()514     virtual bool is_on()
515     {
516         return (value.get() & CxON);
517     }
out_invert()518     virtual bool out_invert()
519     {
520         return value.get() & CxPOL;
521     }
522     virtual double get_hysteresis();
523     virtual void set_output(bool output);
output_high()524     virtual bool output_high()
525     {
526         return value.get() & CxOUT;
527     }
528 
529     PinModule		*stimulus_pin[2];
530 };
531 
532 
533 class CMxCON1_base : public sfr_register, public apfpin
534 {
535 public:
536     CMxCON1_base(Processor *pCpu, const char *pName, const char *pDesc, unsigned int _cm, ComparatorModule2 *);
537     ~CMxCON1_base();
538 
539     enum
540     {
541         NEG	= 0,
542         POS	= 1
543 
544     };
545 
setBitMask(unsigned int bm)546     void setBitMask(unsigned int bm)
547     {
548         mValidBits = bm;
549     }
550     PinModule *output_pin(int cm = 0)
551     {
552         return cm_output[cm];
553     }
put(unsigned int)554     virtual void put(unsigned int /* new_value */ ) {}
555     virtual double get_Vpos(unsigned int arg = 0, unsigned int arg2 = 0)
556     {
557         (void)arg;
558         (void)arg2;
559         return 0.0;
560     }
561     virtual double get_Vneg(unsigned int arg = 0, unsigned int arg2 = 0)
562     {
563         (void)arg;
564         (void)arg2;
565         return 0.0;
566     }
567     virtual void setPinStimulus(PinModule *, int);
568     virtual void set_INpinNeg(PinModule *pin_cm0, PinModule *pin_cm1,
569                               PinModule *pin_cm2 = nullptr,  PinModule *pin_cm3 = nullptr,
570                               PinModule *pin_cm4 = nullptr);
571     virtual void set_OUTpin(PinModule *pin_cm0, PinModule *pin_cm1 = nullptr);
572     virtual void set_INpinPos(PinModule *pin_cm0, PinModule *pin_cm1 = nullptr);
573     virtual void setIOpin(PinModule *pin_cm0, int arg);
hyst_active(unsigned int)574     virtual bool hyst_active(unsigned int /* cm */ )
575     {
576         return false;
577     }
set_vrcon(VRCON *)578     virtual void set_vrcon(VRCON * ) {}
set_vrcon(VRCON_2 *)579     virtual void set_vrcon(VRCON_2 * ) {}
tmr_gate(unsigned int,bool)580     virtual void tmr_gate(unsigned int /* cm */, bool /* output */ ) {}
581 
582 protected:
583     unsigned int cm;	// comparator number
584     CM_stimulus 	    *cm_stimulus[4];     // stimuli to monitor input pin
585     PinModule	    *stimulus_pin[4];    // monitor stimulus loaded on this pin
586     PinModule	    *ctmu_stimulus_pin;  // ctmu stimulus pin
587     ComparatorModule2 *m_cmModule;
588     PinModule 	    *cm_inputNeg[5];
589     PinModule 	    *cm_inputPos[2];
590     PinModule 	    *cm_output[2];
591 };
592 
593 
594 // CMxCON1 only uses 1 0r 2 of Negative select bits and 2 Positive select bits
595 class CMxCON1 : public CMxCON1_base
596 {
597 public:
598     CMxCON1(Processor *pCpu, const char *pName, const char *pDesc, unsigned int _x, ComparatorModule2 *);
599     ~CMxCON1();
600 
601     enum
602     {
603         CxNCH0 	= 1 << 0,	//  Negative Input Channel Select bits
604         CxNCH1 	= 1 << 1,	//  Negative Input Channel Select bits
605         CxNCH2 	= 1 << 2,	//  Negative Input Channel Select bits
606         CxPCH0	= 1 << 3, //  Positive Input Channel Select bits
607         CxPCH1	= 1 << 4, //  Positive Input Channel Select bits
608         CxPCH2	= 1 << 5, //  Positive Input Channel Select bits
609         CxINTN 	= 1 << 6,	//  Interrupt on Negative Going Edge Enable bits
610         CxINTP  	= 1 << 7,	//  Interrupt on Positive Going Edge Enable bits
611         CxNMASK = (CxNCH0 | CxNCH1 | CxNCH2),
612         CxPMASK = (CxPCH0 | CxPCH1 | CxPCH2)
613     };
614 
615     virtual void put(unsigned int new_value);
616     virtual double get_Vpos(unsigned int arg = 0, unsigned int arg2 = 0);
617     virtual double get_Vneg(unsigned int arg = 0, unsigned int arg2 = 0);
618 };
619 
620 
621 /*  two comparators with common CM2CON1 and no COUT register, hyteresis,
622     C1, C2 possible T1,3,5  gate, FVR or  DAC for voltage reference,
623     used by 18f26k22.
624 */
625 class CM2CON1_V2 : public CMxCON1_base
626 {
627 public:
628     CM2CON1_V2(Processor *pCpu, const char *pName, const char *pDesc,
629                ComparatorModule2 * cmModule);
630     ~CM2CON1_V2();
631 
632     enum
633     {
634         C2SYNC = 1 << 0,
635         C1SYNC = 1 << 1,
636         C2HYS  = 1 << 2,
637         C1HYS  = 1 << 3,
638         C2RSEL = 1 << 4,
639         C1RSEL = 1 << 5,
640         MC2OUT = 1 << 6,
641         MC1OUT = 1 << 7
642     };
643 
644     virtual void put(unsigned int new_value);
645     virtual double get_Vpos(unsigned int cm, unsigned int cmxcon0);
646     virtual double get_Vneg(unsigned int cm, unsigned int cmxcon0);
647     virtual bool hyst_active(unsigned int cm);
648     virtual void tmr_gate(unsigned int cm, bool output);
649     void set_ctmu_stim(stimulus *_ctmu_stim, CTMU *_ctmu_module);
650     void attach_ctmu_stim();
651     void detach_ctmu_stim();
652 
653 private:
654     stimulus          *ctmu_stim = nullptr;
655     stimulus          *comp_input_cap = nullptr;
656     bool	            ctmu_attached = false;
657 };
658 
659 
660 /*  two comparators, no hyteresis, cm2con1 controls t1 gate,
661     C2 possible T1 gate, vrcon for voltage reference
662     used by 16f882.
663 */
664 
665 class CM2CON1_V3 : public CMxCON1_base
666 {
667 public:
CM2CON1_V3(Processor * pCpu,const char * pName,const char * pDesc,unsigned int _cm,ComparatorModule2 * cmModule)668     CM2CON1_V3(Processor *pCpu, const char *pName, const char *pDesc,
669                unsigned int _cm, ComparatorModule2 * cmModule) :
670         CMxCON1_base(pCpu, pName, pDesc, _cm, cmModule) {}
~CM2CON1_V3()671     ~CM2CON1_V3() {}
672 
673     enum
674     {
675         C2SYNC = 1 << 0,
676         T1GSS  = 1 << 1,
677         C2RSEL = 1 << 4,
678         C1RSEL = 1 << 5,
679         MC2OUT = 1 << 6,
680         MC1OUT = 1 << 7
681     };
682 
683     virtual void put(unsigned int new_value);
684     virtual double get_Vpos(unsigned int cm, unsigned int cmxcon0);
685     virtual double get_Vneg(unsigned int cm, unsigned int cmxcon0);
hyst_active(unsigned int)686     virtual bool hyst_active(unsigned int /* cm */ )
687     {
688         return false;
689     }
set_vrcon(VRCON * _vrcon)690     void set_vrcon(VRCON * _vrcon)
691     {
692         m_vrcon = _vrcon;
693     }
694     virtual void tmr_gate(unsigned int cm, bool output);
695 
696 protected:
697     VRCON 	*m_vrcon = nullptr;
698 };
699 
700 
701 /*  two comparators, no hyteresis, cm2con1 controls t1 gate,
702     C2 possible T1 gate, VRCON for voltage reference
703     Like CM2CON1_V3 without C1RSEL, C2RSEL
704     used by 16f690.
705 */
706 
707 class CM2CON1_V4 : public CM2CON1_V3
708 {
709 public:
710     CM2CON1_V4(Processor *pCpu, const char *pName, const char *pDesc,
711                unsigned int _cm, ComparatorModule2 * cmModule);
712     ~CM2CON1_V4();
713 
714     virtual void put(unsigned int new_value);
715     virtual double get_Vpos(unsigned int cm, unsigned int cmxcon0);
set_vrcon(VRCON_2 * _vrcon)716     void set_vrcon(VRCON_2 * _vrcon)
717     {
718         m_vrcon = _vrcon;
719     }
720 
721 protected:
722     VRCON_2 	*m_vrcon = nullptr;
723     CM_stimulus 	*cm1_cvref;
724     CM_stimulus 	*cm1_v06ref;
725     CM_stimulus 	*cm2_cvref;
726     CM_stimulus 	*cm2_v06ref;
727 };
728 
729 
730 class CMOUT : public sfr_register
731 {
732 public:
CMOUT(Processor * pCpu,const char * pName,const char * pDesc)733     CMOUT(Processor *pCpu, const char *pName, const char *pDesc)
734         : sfr_register(pCpu, pName, pDesc) {}
735 
put(unsigned int)736     void put(unsigned int /* val */ )
737     {
738         // Read only by user
739     }
740 };
741 
742 
743 // uses CMxCON0, CMxCON1, CMOUT
744 class ComparatorModule2
745 {
746 public:
747     explicit ComparatorModule2(Processor *);
748     ~ComparatorModule2();
749 
run_get(unsigned int comp)750     void run_get(unsigned int comp)
751     {
752         cmxcon0[comp]->get();
753     }
754 
755     void set_DAC_volt(double);
756     void set_FVR_volt(double);
757     void set_cmout(unsigned int bit, bool value);
758     void set_if(unsigned int);
assign_pir_set(PIR_SET * new_pir_set)759     void assign_pir_set(PIR_SET *new_pir_set) { pir_set = new_pir_set; }
760     void assign_tmr1l(TMRL *t1, TMRL *t3 = nullptr, TMRL *t5 = nullptr)
761     {
762         tmr1l[0] = t1;
763         tmr1l[1] = t3;
764         tmr1l[2] = t5;
765     }
766     void assign_t1gcon(T1GCON *t1g, T1GCON *t3g = nullptr, T1GCON *t5g = nullptr)
767     {
768         t1gcon[0] = t1g;
769         t1gcon[1] = t3g;
770         t1gcon[2] = t5g;
771     }
assign_sr_module(SR_MODULE * _sr_module)772     void assign_sr_module(SR_MODULE *_sr_module) { sr_module = _sr_module; }
773 
774     void assign_eccpsas(ECCPAS *a1, ECCPAS *a2 = nullptr, ECCPAS *a3 = nullptr)
775     {
776         eccpas[0] = a1;
777         eccpas[1] = a2;
778         eccpas[2] = a3;
779     }
780 
781     CMxCON0_base 	*cmxcon0[4];
782     CMxCON1_base 	*cmxcon1[4];
783     CMOUT		*cmout = nullptr;
784 
785     //protected:
786     double 	DAC_voltage = 0.0;
787     double 	FVR_voltage = 0.0;
788     PIR_SET 	*pir_set = nullptr;
789     TMRL		*tmr1l[3];
790     T1GCON	*t1gcon[3];
791     SR_MODULE	*sr_module = nullptr;
792     CTMU		*ctmu_module = nullptr;
793     ECCPAS 	*eccpas[3];
794     ADCON2_TRIG   *m_adcon2 = nullptr;
795     CLC_BASE	*m_clc[4];
796     COG		*p_cog = nullptr;
797 };
798 
799 
800 #endif // __COMPARATOR_H__
801