@@ -715,6 +715,7 @@ def is_linked_to(self, dest, src):
715715 return res
716716
717717 def decodeFunc (self ,inVar , funcName ):
718+ s = ""
718719 if funcName == "NandGate" :
719720 s = f"!( { inVar [0 ]['val' ]} "
720721 for v in inVar [1 :]:
@@ -789,7 +790,36 @@ def decodeFunc(self,inVar, funcName):
789790 s = inVar [0 ]["numO" ]* " !" + f"T{ self .varTempNum } "
790791 self .varTempNum += 1
791792 self .varScript += [sT ]
792-
793+ elif funcName == "BinaryCounter" :
794+ if inVar [0 ]["numO" ] == 0 :
795+ self .numTemp = []
796+ CE = inVar [6 ]["CE" ]
797+ iU = inVar [8 ]["iU" ]
798+ iL = inVar [7 ]["iL" ]
799+ D0 = inVar [0 ]["val" ]
800+ D1 = inVar [1 ]["val" ]
801+ D2 = inVar [0 ]["val" ]
802+ D3 = inVar [0 ]["val" ]
803+ sT = f"T{ self .varTempNum } = { CE } & { iL } & !T{ self .varTempNum } _precedant + !{ iL } & { D0 } + !{ CE } & { iL } & T{ self .varTempNum } _precedant; "
804+ self .numTemp += [self .varTempNum ]
805+ self .varTempNum += 1
806+ self .varScript += [sT ]
807+ sT = f"T{ self .varTempNum } = (!{ CE } | !T{ self .varTempNum - 1 } _precedant | !T{ self .varTempNum } _precedant) & " \
808+ + f"({ CE } & T{ self .varTempNum - 1 } _precedant + T{ self .varTempNum } _precedant ) & { iL } + !{ iL } & { D1 } + !{ CE } & { iL } & T{ self .varTempNum } _precedant; "
809+ self .numTemp += [self .varTempNum ]
810+ self .varTempNum += 1
811+ self .varScript += [sT ]
812+ sT = f"T{ self .varTempNum } = (!{ CE } | !T{ self .varTempNum - 2 } _precedant | !T{ self .varTempNum - 1 } _precedant | !T{ self .varTempNum } _precedant) & " \
813+ + f"({ CE } & T{ self .varTempNum - 2 } _precedant & T{ self .varTempNum - 1 } _precedant + T{ self .varTempNum } _precedant ) & { iL } + !{ iL } & { D2 } + !{ CE } & { iL } & T{ self .varTempNum } _precedant; "
814+ self .numTemp += [self .varTempNum ]
815+ self .varTempNum += 1
816+ self .varScript += [sT ]
817+ sT = f"T{ self .varTempNum } = (!{ CE } | !T{ self .varTempNum - 3 } _precedant | !T{ self .varTempNum - 2 } _precedant | !T{ self .varTempNum - 1 } _precedant | !T{ self .varTempNum } _precedant) & " \
818+ + f"({ CE } & T{ self .varTempNum - 3 } _precedant & T{ self .varTempNum - 2 } _precedant & T{ self .varTempNum - 1 } _precedant + T{ self .varTempNum } _precedant ) & { iL } + !{ iL } & { D3 } + !{ CE } & { iL } & T{ self .varTempNum } _precedant; "
819+ self .numTemp += [self .varTempNum ]
820+ self .varTempNum += 1
821+ self .varScript += [sT ]
822+ s = f"T{ self .numTemp [inVar [0 ]["numO" ]]} "
793823
794824 return s
795825
@@ -808,6 +838,12 @@ def checkCloseCircuit(self, ioOut, params={}):
808838 chip_in_j = params .get ("chip_in_j" , [])
809839 chip_in_k = params .get ("chip_in_k" , [])
810840 chip_in_inv_k = params .get ("chip_in_inv_k" , [])
841+
842+ chip_in_ce = params .get ("count_enable_pin" , [])
843+ chip_in_inv_L = params .get ("inv_load_enable_pin" , [])
844+ chip_in_inv_U = params .get ("inv_up_down_input_pin" , [])
845+ chip_out_TC = params .get ("terminal_count_pin" , [])
846+
811847 findOut = False
812848 circuitClose = True
813849 script = ""
@@ -872,14 +908,38 @@ def checkCloseCircuit(self, ioOut, params={}):
872908 chipInInvK = [(c1 ,l1 ) for (c1 ,l1 ,nfunc ) in chipInInvK if nfunc == nf ]
873909 else : chipInInvK = []
874910
911+ if chip_in_ce :
912+ chipInCE = chip_in_ce
913+ [chipInCE ] = [list (chipICE [1 :]) for chipICE in chipInCE if chipICE [0 ] == idOut ]
914+ chipInCE = [(c1 ,l1 ) for (c1 ,l1 ,nfunc ) in chipInCE if nfunc == nf ]
915+ else : chipInCE = []
916+
917+ if chip_in_inv_L :
918+ chipInInvL = chip_in_inv_L
919+ [chipInInvL ] = [list (chipIIL [1 :]) for chipIIL in chipInInvL if chipIIL [0 ] == idOut ]
920+ chipInInvL = [(c1 ,l1 ) for (c1 ,l1 ,nfunc ) in chipInInvL if nfunc == nf ]
921+ else : chipInInvL = []
922+
923+ if chip_in_inv_U :
924+ chipInInvU = chip_in_inv_U
925+ [chipInInvU ] = [list (chipIIU [1 :]) for chipIIU in chipInInvU if chipIIU [0 ] == idOut ]
926+ chipInInvU = [(c1 ,l1 ) for (c1 ,l1 ,nfunc ) in chipInInvU if nfunc == nf ]
927+ else : chipInInvU = []
928+
929+ if chip_out_TC :
930+ chipOutTC = chip_out_TC
931+ [chipOutTC ] = [list (chipOTC [1 :]) for chipOTC in chipOutTC if chipOTC [0 ] == idOut ]
932+ chipOutTC = [(c1 ,l1 ) for (c1 ,l1 ,nfunc ) in chipOutTC if nfunc == nf ]
933+ else : chipOutTC = []
934+
875935 if chip_out_inv :
876936 chipOutInv = chip_out_inv
877937 [chipOutInv ] = [list (chipOI [1 :]) for chipOI in chipOutInv if chipOI [0 ] == idOut ]
878938 else : chipOutInv = []
879939
880940 inLst += chipSel + chipEnInv + chipEn + chipInClock + chipInInvReset + chipInInvSet + \
881- chipInInvClk + chipInK + chipInInvK
882- outLst += chipOutInv
941+ chipInInvClk + chipInK + chipInInvK + chipInCE + chipInInvL + chipInInvU
942+ outLst += chipOutInv + chipOutTC
883943 for no ,out in enumerate (outLst ):
884944 #if out not in chip_out_checked:
885945 if self .is_linked_to (ioZone , out ):
@@ -920,7 +980,19 @@ def checkCloseCircuit(self, ioOut, params={}):
920980 constKey = "K"
921981 for c in chipInInvK :
922982 if c == inFunc :
923- constKey = 'iK'
983+ constKey = "iK"
984+
985+ for c in chipInCE :
986+ if c == inFunc :
987+ constKey = "CE"
988+ for c in chipInInvL :
989+ if c == inFunc :
990+ constKey = "iL"
991+ for c in chipInInvU :
992+ if c == inFunc :
993+ constKey = "iU"
994+
995+
924996 if self .is_linked_to (self .pwrP , inFunc ):
925997 inFuncConst += [{constKey :pos , "num" :n , "numO" :no }]
926998 else : inFuncConst += [{constKey :neg , "num" :n , "numO" :no }]
@@ -961,7 +1033,18 @@ def checkCloseCircuit(self, ioOut, params={}):
9611033 constKey = "K"
9621034 for c in chipInInvK :
9631035 if c == inFunc :
964- constKey = 'iK'
1036+ constKey = "iK"
1037+
1038+ for c in chipInCE :
1039+ if c == inFunc :
1040+ constKey = "CE"
1041+ for c in chipInInvL :
1042+ if c == inFunc :
1043+ constKey = "iL"
1044+ for c in chipInInvU :
1045+ if c == inFunc :
1046+ constKey = "iU"
1047+
9651048 #inFuncConst += [{constKey:self.mcu_pin[f"I{id[4:]}"], "num":n, "numO":no}] # [self.mcu_pin[f"I{id[4:]}"]] # ici ajouter n
9661049 inFuncConst += [{constKey :f"I{ n + 1 } " , "num" :n , "numO" :no }] # [self.mcu_pin[f"I{id[4:]}"]] # ici ajouter n
9671050 findIn = True
@@ -1002,7 +1085,18 @@ def checkCloseCircuit(self, ioOut, params={}):
10021085 constKey = "K"
10031086 for c in chipInInvK :
10041087 if c == inFunc :
1005- constKey = 'iK'
1088+ constKey = "iK"
1089+
1090+ for c in chipInCE :
1091+ if c == inFunc :
1092+ constKey = "CE"
1093+ for c in chipInInvL :
1094+ if c == inFunc :
1095+ constKey = "iL"
1096+ for c in chipInInvU :
1097+ if c == inFunc :
1098+ constKey = "iU"
1099+
10061100 #inFuncConst += [{constKey:self.mcu_pin[f"I{id[4:]}"], "num":n, "numO":no}]
10071101 inFuncConst += [{constKey :f"I{ n + 1 } " , "num" :n , "numO" :no }]
10081102 findIn = True
@@ -1042,7 +1136,11 @@ def checkCloseCircuit(self, ioOut, params={}):
10421136 for c in chipEn :
10431137 if c == inFunc :
10441138 constKey = "enb"
1045-
1139+
1140+ for c in chipOutTC :
1141+ if c == inFunc :
1142+ constKey = "TC"
1143+
10461144 for c in chipOutInv :
10471145 if c == pt :
10481146 outPrev = "!" + outPrev
@@ -1061,7 +1159,11 @@ def checkCloseCircuit(self, ioOut, params={}):
10611159 for c in chipEn :
10621160 if c == inFunc :
10631161 constKey = "enb"
1064-
1162+
1163+ for c in chipOutTC :
1164+ if c == inFunc :
1165+ constKey = "TC"
1166+
10651167 for c in chipOutInv :
10661168 if c == pt :
10671169 s = "!" + s
@@ -1087,7 +1189,11 @@ def checkCloseCircuit(self, ioOut, params={}):
10871189 for c in chipEn :
10881190 if c == inFunc :
10891191 constKey = "enb"
1090-
1192+
1193+ for c in chipOutTC :
1194+ if c == inFunc :
1195+ constKey = "TC"
1196+
10911197 for c in chipOutInv :
10921198 if c == pt :
10931199 outPrev = "!" + outPrev
@@ -1107,7 +1213,11 @@ def checkCloseCircuit(self, ioOut, params={}):
11071213 for c in chipEn :
11081214 if c == inFunc :
11091215 constKey = "enb"
1110-
1216+
1217+ for c in chipOutTC :
1218+ if c == inFunc :
1219+ constKey = "TC"
1220+
11111221 for c in chipOutInv :
11121222 if c == pt :
11131223 exp = "!" + exp
@@ -1166,6 +1276,12 @@ def checkCircuit(self):
11661276 chip_in_j = []
11671277 chip_in_k = []
11681278 chip_in_inv_k = []
1279+
1280+ chip_in_ce = []
1281+ chip_in_inv_L = []
1282+ chip_in_inv_U = []
1283+ chip_out_TC = []
1284+
11691285 self .varTempNum = 1
11701286 self .varScript = []
11711287
@@ -1328,6 +1444,50 @@ def checkCircuit(self):
13281444 if ioIK :
13291445 chip_in_k += [(id , * ioIK )]
13301446 self .chip_in += [(id , * ioIK )]
1447+
1448+ #### l' entrée CE ###
1449+ ioInCE = component .get ("count_enable_pin" , [])
1450+ if ioInCE :
1451+ ioICE = [
1452+ (col + numPin - 1 if numPin <= numPinBR else col + (numPinBR - (numPin % numPinBR ) ), line + 1 - (numPin // numPinBR ),n )
1453+ for (n ,numPin ) in sum (ioInCE , [])
1454+ ]
1455+ if ioICE :
1456+ chip_in_ce += [(id , * ioICE )]
1457+ self .chip_in += [(id , * ioICE )]
1458+
1459+ #### l' entrée L ###
1460+ ioInInvL = component .get ("inv_load_enable_pin" , [])
1461+ if ioInInvL :
1462+ ioIIL = [
1463+ (col + numPin - 1 if numPin <= numPinBR else col + (numPinBR - (numPin % numPinBR ) ), line + 1 - (numPin // numPinBR ),n )
1464+ for (n ,numPin ) in sum (ioInInvL , [])
1465+ ]
1466+ if ioIIL :
1467+ chip_in_inv_L += [(id , * ioIIL )]
1468+ self .chip_in += [(id , * ioIIL )]
1469+
1470+ #### l' entrée U ###
1471+ ioInInvU = component .get ("inv_up_down_input_pin" , [])
1472+ if ioInInvU :
1473+ ioIIU = [
1474+ (col + numPin - 1 if numPin <= numPinBR else col + (numPinBR - (numPin % numPinBR ) ), line + 1 - (numPin // numPinBR ),n )
1475+ for (n ,numPin ) in sum (ioInInvU , [])
1476+ ]
1477+ if ioIIU :
1478+ chip_in_inv_U += [(id , * ioIIU )]
1479+ self .chip_in += [(id , * ioIIU )]
1480+
1481+ #### l' entrée TC ###
1482+ ioOutTC = component .get ("terminal_count_pin" , [])
1483+ if ioOutTC :
1484+ ioOTC = [
1485+ (col + numPin - 1 if numPin <= numPinBR else col + (numPinBR - (numPin % numPinBR ) ), line + 1 - (numPin // numPinBR ),n )
1486+ for (n ,numPin ) in sum (ioOutTC , [])
1487+ ]
1488+ if ioOTC :
1489+ chip_out_TC += [(id , * ioOTC )]
1490+ self .chip_out += [(id , * ioOTC )]
13311491
13321492 elif id [:6 ] == "_wire_" : # [(col1, line1,col2,line2), ...]
13331493 self .wire += [(id , * component ["coord" ][0 ])]
@@ -1426,7 +1586,7 @@ def checkCircuit(self):
14261586 for chipAllio in self .chip_out :
14271587 id = chipAllio [0 ]
14281588 for chipio in chipAllio [1 :]:
1429- ( c1 ,l1 ) = chipio
1589+ c1 ,l1 , * n = chipio
14301590 if self .is_linked_to (self .pwrM , (c1 , l1 )):
14311591 self .chip_ioCC += [(id , chipio )]
14321592 elif self .is_linked_to (self .pwrP , (c1 , l1 )):
@@ -1475,7 +1635,7 @@ def checkCircuit(self):
14751635 id = chipAllio [0 ]
14761636 inChipOutWire = False
14771637 for chipio in chipAllio [1 :]:
1478- (c1 ,l1 ) = chipio
1638+ (c1 ,l1 , * n ) = chipio
14791639 for cow in self .chip_out_wire :
14801640 if self .is_linked_to (cow , (c1 , l1 )):
14811641 inChipOutWire = True
@@ -1534,9 +1694,17 @@ def checkCircuit(self):
15341694 "chip_in_j" : chip_in_j ,
15351695 "chip_in_k" : chip_in_k ,
15361696 "chip_in_inv_k" : chip_in_inv_k ,
1537- }
1697+ "count_enable_pin" : chip_in_ce ,
1698+ "inv_load_enable_pin" : chip_in_inv_L ,
1699+ "inv_up_down_input_pin" : chip_in_inv_U ,
1700+ "terminal_count_pin" : chip_out_TC ,
1701+ }
1702+ def io_position (io ):
1703+ id ,[[p ]] = io
1704+ return p [0 ]
1705+
15381706 # "chip_in_address_pins":chip_in_address_pins}
1539- for no ,ioOut in enumerate (self .io_out ):
1707+ for no ,ioOut in enumerate (sorted ( self .io_out , key = lambda io : io_position ( io )) ):
15401708 #self.script += self.mcu_pin[f"O{ioOut[0][4:]}"] + " = " # f"O{no+1}"
15411709
15421710 circuitClose , script = self .checkCloseCircuit (ioOut ,params )
0 commit comments