LLEntity.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. using System;
  2. using Aitex.Core.Util;
  3. using Aitex.Core.RT.Fsm;
  4. using Aitex.Core.RT.Log;
  5. using MECF.Framework.Common.Equipment;
  6. using MECF.Framework.Common.SubstrateTrackings;
  7. using Venus_RT.Modules.TM;
  8. using Venus_RT.Devices;
  9. using Venus_Core;
  10. using Aitex.Core.RT.DataCenter;
  11. using Aitex.Core.RT.OperationCenter;
  12. using Aitex.Core.RT.Device;
  13. using Aitex.Core.RT.SCCore;
  14. namespace Venus_RT.Modules
  15. {
  16. class LLEntity : Entity, IEntity, IModuleEntity
  17. {
  18. public enum LLStatus
  19. {
  20. Not_Ready,
  21. Ready_For_TM,
  22. Ready_For_EFEM,
  23. }
  24. public enum STATE
  25. {
  26. Unknown,
  27. Init,
  28. Initializing,
  29. Idle,
  30. Error,
  31. Pumping,
  32. Venting,
  33. Purging,
  34. LeakCheck,
  35. Prepare_For_TM,
  36. Prepare_For_EFEM,
  37. Ready_For_TM,
  38. Ready_For_EFEM,
  39. }
  40. public enum MSG
  41. {
  42. Home,
  43. Online,
  44. Offline,
  45. Pump,
  46. Vent,
  47. AutoPump,
  48. AutoVent,
  49. Purge,
  50. CyclePurge,
  51. LeakCheck,
  52. Prepare_TM,
  53. Prepare_EFEM,
  54. TM_Exchange_Ready,
  55. EFEM_Exchange_Ready,
  56. Error,
  57. Abort,
  58. }
  59. public ModuleName Module { get; private set; }
  60. public LLStatus Status { get; private set; }
  61. public bool Check(int msg, out string reason, params object[] args)
  62. {
  63. throw new NotImplementedException();
  64. }
  65. public bool IsIdle
  66. {
  67. get { return fsm.State == (int)STATE.Idle; }
  68. }
  69. public bool IsError
  70. {
  71. get { return fsm.State == (int)STATE.Error; }
  72. }
  73. public bool IsInit
  74. {
  75. get { return fsm.State == (int)STATE.Unknown || fsm.State == (int)STATE.Init; }
  76. }
  77. public bool IsBusy
  78. {
  79. get { return !IsInit && !IsError && !IsIdle; }
  80. }
  81. public bool IsOnline { get; internal set; }
  82. public bool IsVac { get { return _JetTM.IsModuleVaccum(Module); } }
  83. public bool IsATM { get { return _JetTM.IsModuleATM(Module); } }
  84. private readonly JetTM _JetTM;
  85. private readonly MFPumpRoutine _pumpingRoutine;
  86. private readonly MFVentRoutine _ventingRoutine;
  87. private readonly MFLeakCheckRoutine _leakCheckRoutine;
  88. private readonly MFPurgeRoutine _purgeRoutine;
  89. private readonly int _slotNumber = 4;
  90. public LLEntity(ModuleName module)
  91. {
  92. Module = module;
  93. _JetTM= DEVICE.GetDevice<JetTM>("TM");
  94. _pumpingRoutine = new MFPumpRoutine(_JetTM, Module);
  95. _ventingRoutine = new MFVentRoutine(_JetTM, Module);
  96. _leakCheckRoutine = new MFLeakCheckRoutine(_JetTM, Module);
  97. _purgeRoutine = new MFPurgeRoutine(_JetTM, Module);
  98. _slotNumber = SC.GetValue<int>($"{module.ToString()}.SlotNumber");
  99. WaferManager.Instance.SubscribeLocation(Module, _slotNumber);
  100. InitFsmMap();
  101. }
  102. protected override bool Init()
  103. {
  104. OP.Subscribe($"{Module}.Home", (cmd, args) => CheckToPostMessage((int)MSG.Home));
  105. OP.Subscribe($"{Module}.{RtOperation.Pump}", (cmd, args) => CheckToPostMessage((int)MSG.Pump));
  106. OP.Subscribe($"{Module}.{RtOperation.Vent}", (cmd, args) => CheckToPostMessage((int)MSG.Vent));
  107. OP.Subscribe($"{Module}.{RtOperation.Purge}", (cmd, args) => CheckToPostMessage((int)MSG.Purge));
  108. OP.Subscribe($"{Module}.{RtOperation.Abort}", (cmd, args) => CheckToPostMessage((int)MSG.Abort));
  109. OP.Subscribe($"{Module}.{RtOperation.LeakCheck}", (cmd, args) => CheckToPostMessage((int)MSG.LeakCheck));
  110. OP.Subscribe($"{Module}.{RtOperation.Online}", (cmd, args) => CheckToPostMessage((int)MSG.Online));
  111. OP.Subscribe($"{Module}.{RtOperation.Offline}", (cmd, args) => CheckToPostMessage((int)MSG.Offline));
  112. DATA.Subscribe($"{Module}.FsmState", () => (((STATE)fsm.State).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  113. DATA.Subscribe($"{Module}.FsmPrevState", () => (((PMState)fsm.PrevState).ToString()),SubscriptionAttribute.FLAG.IgnoreSaveDB);
  114. DATA.Subscribe($"{Module}.FsmLastMessage", () => (((MSG)fsm.LastMsg).ToString()), SubscriptionAttribute.FLAG.IgnoreSaveDB);
  115. DATA.Subscribe($"{Module}.IsOnline", () => IsOnline,SubscriptionAttribute.FLAG.IgnoreSaveDB);
  116. return true;
  117. }
  118. private void InitFsmMap()
  119. {
  120. fsm = new StateMachine<LLEntity>(Module.ToString(), (int)STATE.Init, 50);
  121. fsm.EnableRepeatedMsg(true);
  122. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_TM, fnEnterTMReady, FSM_MSG.NONE, fnExitTMReady);
  123. EnterExitTransition<STATE, FSM_MSG>(STATE.Ready_For_EFEM, fnEnterEFEMReady, FSM_MSG.NONE, fnExitEFEMReady);
  124. //AnyStateTransition(FSM_MSG.TIMER, fnMonitor, FSM_STATE.SAME);
  125. AnyStateTransition(MSG.Error, fnError, STATE.Error);
  126. AnyStateTransition(MSG.Online, fnOnline, FSM_STATE.SAME);
  127. AnyStateTransition(MSG.Offline, fnOffline, FSM_STATE.SAME);
  128. AnyStateTransition(MSG.Home, fnHome, STATE.Initializing);
  129. // Home
  130. Transition(STATE.Initializing, FSM_MSG.TIMER, fnHoming, STATE.Idle);
  131. Transition(STATE.Idle, FSM_MSG.TIMER, fnMonitor, STATE.Idle);
  132. Transition(STATE.Init, FSM_MSG.TIMER, fnMonitor, STATE.Init);
  133. //vent sequence
  134. Transition(STATE.Idle, MSG.Vent, FnStartVent, STATE.Venting);
  135. Transition(STATE.Venting, FSM_MSG.TIMER, FnVentTimeout, STATE.Idle);
  136. Transition(STATE.Venting, MSG.Abort, FnAbortVent, STATE.Idle);
  137. //Pump sequence
  138. Transition(STATE.Idle, MSG.Pump, FnStartPump, STATE.Pumping);
  139. Transition(STATE.Pumping, FSM_MSG.TIMER, FnPumpTimeout, STATE.Idle);
  140. Transition(STATE.Pumping, MSG.Abort, FnAbortPump, STATE.Idle);
  141. // Purge sequence
  142. Transition(STATE.Idle, MSG.Purge, FnStartPurge, STATE.Purging);
  143. Transition(STATE.Purging, FSM_MSG.TIMER, FnPurgeTimeout, STATE.Idle);
  144. Transition(STATE.Purging, MSG.Abort, FnAbortPurge, STATE.Idle);
  145. // Leak check sequence
  146. Transition(STATE.Idle, MSG.LeakCheck, FnStartLeakCheck, STATE.LeakCheck);
  147. Transition(STATE.LeakCheck, FSM_MSG.TIMER, FnLeakCheckTimeout, STATE.Idle);
  148. Transition(STATE.LeakCheck, MSG.Abort, FnAbortLeakCheck, STATE.Idle);
  149. // Prepare TM Transfer
  150. Transition(STATE.Idle, MSG.Prepare_TM, FnStartPrepareTM, STATE.Prepare_For_TM);
  151. Transition(STATE.Prepare_For_TM, FSM_MSG.TIMER, FnPreparaTMTimeout, STATE.Ready_For_TM);
  152. Transition(STATE.Prepare_For_TM, MSG.Prepare_TM, null, STATE.Prepare_For_TM);
  153. Transition(STATE.Prepare_For_TM, MSG.Abort, FnAbortPreparaTM, STATE.Idle);
  154. Transition(STATE.Ready_For_TM, MSG.TM_Exchange_Ready, null, STATE.Idle);
  155. Transition(STATE.Ready_For_TM, MSG.Prepare_TM, null, STATE.Ready_For_TM);
  156. Transition(STATE.Ready_For_TM, MSG.Abort, null, STATE.Idle);
  157. Transition(STATE.Ready_For_TM, MSG.AutoVent, FnTryAutoVent, STATE.Venting);
  158. // Prepare EFEM Transfer
  159. Transition(STATE.Idle, MSG.Prepare_EFEM, FnStartPrepareEFEM, STATE.Prepare_For_EFEM);
  160. Transition(STATE.Prepare_For_EFEM, FSM_MSG.TIMER, FnPrepareEFEMTimeout, STATE.Ready_For_EFEM);
  161. Transition(STATE.Prepare_For_EFEM, MSG.Abort, FnAbortPrepareEFEM, STATE.Idle);
  162. Transition(STATE.Ready_For_EFEM, MSG.EFEM_Exchange_Ready, null, STATE.Idle);
  163. Transition(STATE.Ready_For_EFEM, MSG.Prepare_EFEM, null, STATE.Ready_For_EFEM);
  164. Transition(STATE.Ready_For_EFEM, MSG.Abort, null, STATE.Idle);
  165. Transition(STATE.Ready_For_EFEM, MSG.AutoPump, FnTryAutoPump, STATE.Pumping);
  166. Running = true;
  167. }
  168. public int Invoke(string function, params object[] args)
  169. {
  170. switch (function)
  171. {
  172. case "Home":
  173. CheckToPostMessage((int)MSG.Home);
  174. return (int)MSG.Home;
  175. }
  176. return (int)FSM_MSG.NONE;
  177. }
  178. public bool CheckAcked(int msg)
  179. {
  180. return fsm.CheckExecuted(msg);
  181. }
  182. public bool CheckToPostMessage(int msg, params object[] args)
  183. {
  184. if (!fsm.FindTransition(fsm.State, msg))
  185. {
  186. LOG.Write(eEvent.WARN_FSM_WARN, Module, $"{Module} is in {(STATE)fsm.State} state,can not do {(MSG)msg}");
  187. return false;
  188. }
  189. Running = true;
  190. fsm.PostMsg(msg, args);
  191. return true;
  192. }
  193. public (int processed, int unprocessed) GetWaferProcessStatus()
  194. {
  195. int processedCount = 0;
  196. int unprocessCount = 0;
  197. for (int i = 0; i < _slotNumber; i++)
  198. {
  199. var wafer = WaferManager.Instance.GetWafer(Module, i);
  200. if (!wafer.IsEmpty)
  201. {
  202. if (wafer.ProcessState == Aitex.Core.Common.EnumWaferProcessStatus.Completed)
  203. {
  204. processedCount++;
  205. }
  206. else
  207. {
  208. unprocessCount++;
  209. }
  210. }
  211. }
  212. return (processedCount, unprocessCount);
  213. }
  214. private bool fnEnterTMReady(object[] param)
  215. {
  216. Status = LLStatus.Ready_For_TM;
  217. return true;
  218. }
  219. private bool fnExitTMReady(object[] param)
  220. {
  221. Status = LLStatus.Not_Ready;
  222. return true;
  223. }
  224. private bool fnEnterEFEMReady(object[] param)
  225. {
  226. Status = LLStatus.Ready_For_EFEM;
  227. return true;
  228. }
  229. private bool fnExitEFEMReady(object[] param)
  230. {
  231. Status = LLStatus.Not_Ready;
  232. return true;
  233. }
  234. private bool fnMonitor(object[] param)
  235. {
  236. _debugRoutine();
  237. return true;
  238. }
  239. private bool fnError(object[] param)
  240. {
  241. IsOnline = false;
  242. return true;
  243. }
  244. private bool fnOnline(object[] param)
  245. {
  246. IsOnline = true;
  247. return true;
  248. }
  249. private bool fnOffline(object[] param)
  250. {
  251. IsOnline = false;
  252. return true;
  253. }
  254. private bool fnAbort(object[] param)
  255. {
  256. return true;
  257. }
  258. private bool fnHome(object[] param)
  259. {
  260. IsOnline = true;
  261. return true;
  262. }
  263. private bool fnHoming(object[] param)
  264. {
  265. return true;
  266. }
  267. private bool FnStartVent(object[] param)
  268. {
  269. return _ventingRoutine.Start() == RState.Running;
  270. }
  271. private bool FnTryAutoVent(object[] param)
  272. {
  273. if (RouteManager.IsATMMode)
  274. {
  275. PostMsg(MSG.TM_Exchange_Ready);
  276. return false;
  277. }
  278. return _ventingRoutine.Start() == RState.Running;
  279. }
  280. private bool FnVentTimeout(object[] param)
  281. {
  282. RState ret = _ventingRoutine.Monitor();
  283. if (ret == RState.Failed || ret == RState.Timeout)
  284. {
  285. PostMsg(MSG.Error);
  286. return false;
  287. }
  288. return ret == RState.End;
  289. }
  290. private bool FnAbortVent(object[] param)
  291. {
  292. _ventingRoutine.Abort();
  293. return true;
  294. }
  295. private bool FnStartPump(object[] param)
  296. {
  297. return _pumpingRoutine.Start() == RState.Running;
  298. }
  299. private bool FnPumpTimeout(object[] param)
  300. {
  301. RState ret = _pumpingRoutine.Monitor();
  302. if (ret == RState.Failed || ret == RState.Timeout)
  303. {
  304. PostMsg(MSG.Error);
  305. return false;
  306. }
  307. return ret == RState.End;
  308. }
  309. private bool FnAbortPump(object[] param)
  310. {
  311. _pumpingRoutine.Abort();
  312. return true;
  313. }
  314. private bool FnTryAutoPump(object[] param)
  315. {
  316. if(_JetTM.LLPumpStatus != JetTM.LLPumpState.Idle || RouteManager.IsATMMode)
  317. {
  318. PostMsg(MSG.EFEM_Exchange_Ready);
  319. return false;
  320. }
  321. return _pumpingRoutine.Start() == RState.Running;
  322. }
  323. private bool FnStartPurge(object[] param)
  324. {
  325. return _purgeRoutine.Start() == RState.Running;
  326. }
  327. private bool FnPurgeTimeout(object[] param)
  328. {
  329. RState ret = _purgeRoutine.Monitor();
  330. if (ret == RState.Failed || ret == RState.Timeout)
  331. {
  332. PostMsg(MSG.Error);
  333. return false;
  334. }
  335. return ret == RState.End;
  336. }
  337. private bool FnAbortPurge(object[] param)
  338. {
  339. _purgeRoutine.Abort();
  340. return true;
  341. }
  342. private bool FnStartLeakCheck(object[] param)
  343. {
  344. return _leakCheckRoutine.Start() == RState.Running;
  345. }
  346. private bool FnLeakCheckTimeout(object[] param)
  347. {
  348. RState ret = _leakCheckRoutine.Monitor();
  349. if (ret == RState.Failed || ret == RState.Timeout)
  350. {
  351. PostMsg(MSG.Error);
  352. return false;
  353. }
  354. return ret == RState.End;
  355. }
  356. private bool FnAbortLeakCheck(object[] param)
  357. {
  358. _leakCheckRoutine.Abort();
  359. return true;
  360. }
  361. private bool FnStartPrepareTM(object[] param)
  362. {
  363. if (RouteManager.IsATMMode)
  364. return true;
  365. return _pumpingRoutine.Start() == RState.Running;
  366. }
  367. private bool FnPreparaTMTimeout(object[] param)
  368. {
  369. if (RouteManager.IsATMMode)
  370. {
  371. if (fsm.ElapsedTime > 10000)
  372. {
  373. LOG.Write(eEvent.ERR_TM, Module, $"Cannot transfer wafer as {Module} is not ATM.");
  374. PostMsg(MSG.Error);
  375. return true;
  376. }
  377. return _JetTM.IsModuleATM(Module);
  378. }
  379. RState ret = _pumpingRoutine.Monitor();
  380. if (ret == RState.Failed || ret == RState.Timeout)
  381. {
  382. PostMsg(MSG.Error);
  383. return false;
  384. }
  385. return ret == RState.End;
  386. }
  387. private bool FnAbortPreparaTM(object[] param)
  388. {
  389. _pumpingRoutine.Abort();
  390. return true;
  391. }
  392. private bool FnStartPrepareEFEM(object[] param)
  393. {
  394. if (RouteManager.IsATMMode)
  395. return true;
  396. return _ventingRoutine.Start() == RState.Running;
  397. }
  398. private bool FnPrepareEFEMTimeout(object[] param)
  399. {
  400. if (RouteManager.IsATMMode)
  401. {
  402. if (fsm.ElapsedTime > 10000)
  403. {
  404. LOG.Write(eEvent.ERR_TM, Module, $"Cannot transfer wafer as {Module} is not ATM.");
  405. PostMsg(MSG.Error);
  406. return true;
  407. }
  408. return _JetTM.IsModuleATM(Module);
  409. }
  410. RState ret = _ventingRoutine.Monitor();
  411. if (ret == RState.Failed || ret == RState.Timeout)
  412. {
  413. PostMsg(MSG.Error);
  414. return false;
  415. }
  416. return ret == RState.End;
  417. }
  418. private bool FnAbortPrepareEFEM(object[] param)
  419. {
  420. _ventingRoutine.Abort();
  421. return true;
  422. }
  423. private void _debugRoutine()
  424. {
  425. int flag = 0;
  426. // Test Home routine
  427. if (flag == 1)
  428. {
  429. PostMsg(MSG.Home);
  430. }
  431. else if (flag == 2)
  432. {
  433. PostMsg(MSG.Vent);
  434. }
  435. else if (flag == 3)
  436. {
  437. PostMsg(MSG.Pump);
  438. }
  439. //else if (flag == 4)
  440. //{
  441. // PostMsg(MSG.PumpLoadLock);
  442. //}
  443. //else if (flag == 5)
  444. //{
  445. // PostMsg(MSG.VentLoadLock);
  446. //}
  447. //else if (flag == 6)
  448. //{
  449. // PostMsg(MSG.PurgeLoadLock);
  450. //}
  451. //else if (flag == 7)
  452. //{
  453. // PostMsg(MSG.LaunchPump);
  454. //}
  455. //else if (flag == 8)
  456. //{
  457. // PostMsg(MSG.LaunchTurboPump);
  458. //}
  459. //else if (flag == 9)
  460. //{
  461. // PostMsg(MSG.LoadLockLeakCheck);
  462. //}
  463. else if (flag == 10)
  464. {
  465. PostMsg(MSG.CyclePurge);
  466. }
  467. //else if (flag == 11)
  468. //{
  469. // PostMsg(MSG.GasLinePurge);
  470. //}
  471. //else if (flag == 12)
  472. //{
  473. // PostMsg(MSG.LeakCheck);
  474. //}
  475. //else if (flag == 13)
  476. //{
  477. // PostMsg(MSG.GasLeakCheck);
  478. //}
  479. //else if (flag == 14)
  480. //{
  481. // PostMsg(MSG.LLPlace);
  482. //}
  483. //else if (flag == 15)
  484. //{
  485. // PostMsg(MSG.LLPick);
  486. //}
  487. //else if (flag == 16)
  488. //{
  489. // PostMsg(MSG.RunRecipe, "7777");
  490. //}
  491. //else if (flag == 17)
  492. //{
  493. // PostMsg(MSG.MFCVerification, "MFC2", (double)50, 10);
  494. //}
  495. }
  496. }
  497. }