PMProcessRoutine.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using System;
  2. using System.Collections.Generic;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.RT.SCCore;
  5. using Aitex.Core.Common;
  6. using Aitex.Core.RT.RecipeCenter;
  7. using Venus_RT.Devices;
  8. using MECF.Framework.Common.Equipment;
  9. using MECF.Framework.Common.SubstrateTrackings;
  10. using Venus_Core;
  11. using System.Diagnostics;
  12. using MECF.Framework.Common.DBCore;
  13. using Venus_Unity;
  14. using System.Threading.Tasks;
  15. using Aitex.Core.RT.Event;
  16. namespace Venus_RT.Modules.PMs
  17. {
  18. class PMProcessRoutine : PMRoutineBase, IRoutine
  19. {
  20. private enum ProcessStep
  21. {
  22. kPreparePressure,
  23. kPrepareTemperature,
  24. kRunRecipes,
  25. kEnd,
  26. }
  27. public string CurrentRunningRecipe { get; set; }
  28. public string ProcessRecipeName { get; set; }
  29. public string ChuckRecipeName { get; set; }
  30. public string DechuckRecipeName { get; set; }
  31. public string CleanRecipeName { get; set; }
  32. public RecipeHead ProcessRecipeHead { get; set; }
  33. public DateTime RecipeStartTime { get; private set; }
  34. public DateTime RecipeEndTime { get; private set; }
  35. public string WaferId { get; set; }
  36. public string SlotID { get; set; }
  37. public string LotID { get; set; }
  38. public string GuidAllStep { get; set; }
  39. //public bool CurrentRecipeType { get; set; }
  40. //int Timeall;
  41. private Stopwatch Recipetime = new Stopwatch();
  42. private readonly PumpDownRoutine _pumpDownRoutine;
  43. private readonly ProcessHelper _processHelper;
  44. private bool _withWafer = true;
  45. //private bool _needPumpDown = false;
  46. public Recipe _currentRecipe = null;
  47. private int _currentStep = 0;
  48. private Queue<Recipe> _qeRecipes = new Queue<Recipe>();
  49. private double _tolerance;
  50. private double _OffsetTemp = 0.0f;
  51. private bool _bLoopMode = false;
  52. private int _loopStartStep = 0;
  53. private int _loopCounter = 0;
  54. private int _recipeRunningMode = 0;
  55. private Stopwatch _stepTime = new Stopwatch();
  56. public RecipeResult currentRecipeResult;
  57. public bool isMaualEndStep;
  58. private RecipeFACallback _faCallback;
  59. private JetChamber _jetChamber;
  60. private RecipeType _recipeType;
  61. private Recipe processRecipe;
  62. private double ChillerTemp
  63. {
  64. get
  65. {
  66. if (ProcessRecipeHead != null)
  67. {
  68. if (!string.IsNullOrEmpty(ProcessRecipeHead.ChillerTemp))
  69. {
  70. double setpoint = Convert.ToDouble(ProcessRecipeHead.ChillerTemp);
  71. if (setpoint > 0 && setpoint < 600)
  72. return setpoint;
  73. }
  74. }
  75. return 0;
  76. }
  77. }
  78. private double BasePressure
  79. {
  80. get
  81. {
  82. if (ProcessRecipeHead != null)
  83. {
  84. if (!string.IsNullOrEmpty(ProcessRecipeHead.BasePressure))
  85. {
  86. double setpoint = Convert.ToDouble(ProcessRecipeHead.BasePressure);
  87. if (setpoint > 0 && setpoint < 750000)
  88. return setpoint;
  89. }
  90. }
  91. return SC.GetValue<int>($"{Module}.Pump.PumpBasePressure");
  92. }
  93. }
  94. public double EstimatedTotalLeftTime
  95. {
  96. get;
  97. private set;
  98. }
  99. public PMProcessRoutine(JetPMBase chamber, PumpDownRoutine pdRoutine) : base(chamber)
  100. {
  101. Name = "Process";
  102. _pumpDownRoutine = pdRoutine;
  103. _processHelper = new ProcessHelper(chamber);
  104. _faCallback = new RecipeFACallback();
  105. _jetChamber = (JetChamber)SC.GetValue<int>($"{chamber.Module}.ChamberType");
  106. }
  107. private bool AssignFuns(Recipe recipe)
  108. {
  109. foreach (var step in recipe.Steps)
  110. {
  111. if (_processHelper.LoadStepFuns(step) == false)
  112. return false;
  113. foreach (ProcessUnitBase unit in step.LstUnit)
  114. {
  115. if (_processHelper.LoadMethods(unit) == false)
  116. {
  117. Stop($"Cannot find the process routine for unit:{unit.GetType()}");
  118. return false;
  119. }
  120. }
  121. }
  122. return true;
  123. }
  124. public RState Start(params object[] objs)
  125. {
  126. string recipeName = (string)objs[0];
  127. if (objs.Length >= 2)
  128. {
  129. _recipeType = (RecipeType)Enum.Parse(typeof(RecipeType), objs[2].ToString());
  130. if (_recipeType == RecipeType.Clean)
  131. {
  132. _withWafer = false;
  133. }
  134. else
  135. {
  136. _withWafer = true;
  137. }
  138. }
  139. //if (objs.Length >= 2)
  140. //{
  141. // _withWafer = (bool)objs[2];
  142. //}
  143. if (_withWafer && WaferManager.Instance.CheckNoWafer(Module, 0))
  144. {
  145. Stop($"can not run process, no wafer at {Module}");
  146. EV.PostAlarmLog(Module.ToString(), $"can not run process, no wafer at {Module}");
  147. return RState.Failed;
  148. }
  149. else if (!_withWafer && WaferManager.Instance.CheckHasWafer(Module, 0))
  150. {
  151. Stop($"can not run clean recipe{recipeName}, a wafer at {Module}");
  152. EV.PostAlarmLog(Module.ToString(), $"can not run clean recipe, a wafer at {Module}");
  153. return RState.Failed;
  154. }
  155. if (!_chamber.IsRFGInterlockOn)
  156. {
  157. Stop("射频电源 Interlock条件不满足");
  158. EV.PostAlarmLog(Module.ToString(), "射频电源 Interlock条件不满足");
  159. return RState.Failed;
  160. }
  161. if (!CheckSlitDoor() || !CheckDryPump() || !CheckTurboPump())
  162. {
  163. return RState.Failed;
  164. }
  165. // Load/Validate Recipe
  166. _qeRecipes.Clear();
  167. currentRecipeResult = new RecipeResult();
  168. currentRecipeResult.RecipeName = recipeName;
  169. string recipeContent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipeName, false, objs[2].ToString());
  170. Recipe recipe = Recipe.Load(recipeContent);
  171. currentRecipeResult.RecipeStepCount = recipe.Steps.Count;
  172. if (recipe == null)
  173. {
  174. Stop($"Load Recipe:{recipeName} failed");
  175. EV.PostAlarmLog(Module.ToString(), $"Load Recipe:{recipeName} failed");
  176. return RState.Failed;
  177. }
  178. _recipeRunningMode = SC.GetValue<int>($"{Module}.RecipeRunningMode");
  179. _processHelper.m_RecipeHead = recipe.Header;
  180. switch (recipe.Header.Type)
  181. {
  182. case RecipeType.Process:
  183. if (_recipeRunningMode == 1 && recipe.Header.ChuckRecipe != null && !string.IsNullOrEmpty(recipe.Header.ChuckRecipe))
  184. {
  185. string chuckcontent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipe.Header.ChuckRecipe, false, RecipeType.Chuck.ToString());
  186. var chuckRecipe = Recipe.Load(chuckcontent);
  187. if (chuckRecipe != null)
  188. {
  189. ChuckRecipeName = recipe.Header.ChuckRecipe;
  190. _qeRecipes.Enqueue(chuckRecipe);
  191. }
  192. }
  193. ProcessRecipeHead = recipe.Header;
  194. ProcessRecipeName = recipeName;
  195. _qeRecipes.Enqueue(recipe);
  196. if (_recipeRunningMode == 1 && recipe.Header.DechuckRecipe != null && !string.IsNullOrEmpty(recipe.Header.DechuckRecipe))
  197. {
  198. string dechuckcontent = RecipeFileManager.Instance.LoadRecipe(_chamber.Name, recipe.Header.DechuckRecipe, false, RecipeType.DeChuck.ToString());
  199. var dechuckRecipe = Recipe.Load(dechuckcontent);
  200. if (dechuckRecipe != null)
  201. {
  202. DechuckRecipeName = recipe.Header.DechuckRecipe;
  203. _qeRecipes.Enqueue(dechuckRecipe);
  204. }
  205. }
  206. break;
  207. case RecipeType.Chuck:
  208. ChuckRecipeName = recipeName;
  209. _qeRecipes.Enqueue(recipe);
  210. break;
  211. case RecipeType.DeChuck:
  212. DechuckRecipeName = recipeName;
  213. _qeRecipes.Enqueue(recipe);
  214. break;
  215. case RecipeType.Clean:
  216. CleanRecipeName = recipeName;
  217. _qeRecipes.Enqueue(recipe);
  218. break;
  219. }
  220. foreach (Recipe rcp in _qeRecipes)
  221. {
  222. if (AssignFuns(rcp) == false)
  223. {
  224. Stop($"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  225. EV.PostAlarmLog(Module.ToString(), $"Associate process alogrithm with recipe:{rcp.Header.Name} failed");
  226. return RState.Failed;
  227. }
  228. }
  229. _bLoopMode = false;
  230. _loopStartStep = 0;
  231. _loopCounter = 0;
  232. _processHelper.isLoop = false;
  233. _processHelper.loopsteps = 0;
  234. _processHelper.currentStepIndex = 0;
  235. _tolerance = SC.GetValue<double>($"System.MaxTemperatureToleranceToTarget");
  236. _OffsetTemp = SC.GetValue<double>($"{Module}.Chiller.ChillerTemperatureOffset");
  237. _faCallback.RecipeStart(_chamber.Module.ToString(), recipeName);
  238. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.InProcess);
  239. return Runner.Start(Module, Name);
  240. }
  241. public RState Monitor()
  242. {
  243. Runner
  244. .Run(ProcessStep.kPreparePressure, PreparePressure, IsPressureReady)
  245. .Run(ProcessStep.kPrepareTemperature, PrepareTemp, IsTempReady)
  246. .Run(ProcessStep.kRunRecipes, StartNewRecipe, RunRecipes, 5 * 60 * 60 * 1000)
  247. .End(ProcessStep.kEnd, ProcessDone, _delay_1s);
  248. return Runner.Status;
  249. }
  250. private bool PreparePressure()
  251. {
  252. //2023/09/02 tps remove
  253. //if(_chamber.ProcessHighPressure < 5 && _chamber.ProcessLowPressure<BasePressure)
  254. //{
  255. // _needPumpDown = false;
  256. // return true;
  257. //}
  258. //_needPumpDown = true;
  259. return _pumpDownRoutine.Start(BasePressure) == RState.Running;
  260. }
  261. private bool IsPressureReady()
  262. {
  263. //if (_needPumpDown == false)
  264. // return true;
  265. var status = _pumpDownRoutine.Monitor();
  266. if (status == RState.End)
  267. {
  268. return true;
  269. }
  270. else if (status == RState.Failed || status == RState.Timeout)
  271. {
  272. Runner.Stop($"Pump down to {BasePressure} failed.");
  273. EV.PostAlarmLog(Module.ToString(), $"Pump down to {BasePressure} failed.");
  274. return true;
  275. }
  276. return false;
  277. }
  278. private bool PrepareTemp()
  279. {
  280. if (_jetChamber == JetChamber.Venus)
  281. {
  282. return SetCoolantTemp(ChillerTemp, _OffsetTemp);
  283. }
  284. else
  285. {
  286. return true;
  287. }
  288. }
  289. private bool IsTempReady()
  290. {
  291. if (_jetChamber == JetChamber.Venus)
  292. {
  293. return CheckCoolantTemp(ChillerTemp, _tolerance);
  294. }
  295. else
  296. {
  297. return true;
  298. }
  299. }
  300. public RState StartNewStep()
  301. {
  302. ProcessDataRecorder.StepStart(GuidAllStep, _currentRecipe.Steps[_currentStep].StepNo, $"{Module}:{_currentRecipe.Header.Name}:{_currentRecipe.Steps[_currentStep].Description}", _currentRecipe.Steps[_currentStep].Time);
  303. _stepTime.Restart();
  304. var state = _currentRecipe.Steps[_currentStep].Start();
  305. if (state != RState.Running)
  306. return state;
  307. //if (_bLoopMode == true)
  308. //{
  309. //}
  310. if (_currentRecipe.Steps[_currentStep].CycleStart)
  311. {
  312. if (!_bLoopMode)
  313. {
  314. _bLoopMode = true;
  315. _loopStartStep = _currentStep;
  316. _loopCounter = _currentRecipe.Steps[_currentStep].CycleNumber - 1;
  317. currentRecipeResult.RecipeAllCounters = _currentRecipe.Steps[_currentStep].CycleNumber;
  318. currentRecipeResult.RecipeCurrentCounter = _loopCounter == 0 ? 0 : 1;
  319. _processHelper.isLoop = true;
  320. _processHelper.loopsteps = _currentRecipe.Steps[_currentStep].CycleNumber;
  321. }
  322. else
  323. {
  324. _processHelper.currentStepIndex += 1;
  325. }
  326. }
  327. return RState.Running;
  328. }
  329. private bool StartNewRecipe()
  330. {
  331. if (_qeRecipes.Count > 0)
  332. {
  333. _currentStep = 0;
  334. _currentRecipe = _qeRecipes.Dequeue();
  335. CurrentRunningRecipe = _currentRecipe.Header.Name;
  336. if (GuidAllStep == null)
  337. {
  338. GuidAllStep = Guid.NewGuid().ToString();
  339. RecipeStartTime = DateTime.Now;
  340. Recipetime.Restart();
  341. }
  342. Notify($"Recipe:{CurrentRunningRecipe} start");
  343. _chamber.EPDRecipeStart(CurrentRunningRecipe);
  344. return StartNewStep() == RState.Running;
  345. }
  346. return false;
  347. }
  348. private bool RunRecipes()
  349. {
  350. var step = _currentRecipe.Steps[_currentStep];
  351. currentRecipeResult.RecipeStepCount = _currentRecipe.Steps.Count;
  352. currentRecipeResult.RecipeName = _currentRecipe.Header.Name;
  353. currentRecipeResult.RecipeType = _currentRecipe.Header.Type.ToString();
  354. currentRecipeResult.RecipeStepNumber = step.StepNo;
  355. currentRecipeResult.RecipeStepType = step.Type.ToString();
  356. currentRecipeResult.RecipeStepDescription = string.IsNullOrEmpty(step.Description) ? "" : step.Description;
  357. currentRecipeResult.RecipeStepSetTime = step.Time;
  358. currentRecipeResult.RecipeType = _currentRecipe.Header.Type.ToString();
  359. currentRecipeResult.RecipeStepDuringTime = new System.TimeSpan(0, 0, System.Convert.ToInt32(_stepTime.ElapsedMilliseconds / 1000));
  360. var result = step.Run();
  361. if (result == RState.Failed)
  362. {
  363. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Failed);
  364. RecipeDown("Fail");
  365. UpdateWaferStatus(false);
  366. Runner.Stop($"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  367. EV.PostAlarmLog(Module.ToString(), $"Recipe:{CurrentRunningRecipe}, Step:{_currentStep + 1} Failed");
  368. return true;
  369. }
  370. else if (result == RState.End || isMaualEndStep == true)
  371. {
  372. if (_currentRecipe.Steps.Count > _currentStep + 1 && _currentRecipe.Steps[_currentStep + 1].Type != StepType.OverEtch)
  373. {
  374. _currentRecipe.Steps[_currentStep].End();
  375. }
  376. if (_currentRecipe.Steps[_currentStep].CycleEnd)
  377. {
  378. if (_loopCounter > 0)
  379. {
  380. _loopCounter--;
  381. currentRecipeResult.RecipeCurrentCounter += 1;
  382. _currentStep = _loopStartStep;
  383. return StartNewStep() != RState.Running;
  384. }
  385. else
  386. {
  387. _bLoopMode = false;
  388. _loopStartStep = 0;
  389. //_processHelper.loopStep(false, 0, 0);
  390. _processHelper.isLoop = false;
  391. _processHelper.loopsteps = 0;
  392. _processHelper.currentStepIndex = 0;
  393. }
  394. }
  395. if (_currentStep < _currentRecipe.Steps.Count - 1 || isMaualEndStep == true)
  396. {
  397. result = RState.End;
  398. isMaualEndStep = false;
  399. _currentStep++;
  400. return StartNewStep() != RState.Running;
  401. }
  402. else
  403. {
  404. Notify($"Recipe:{CurrentRunningRecipe} finished");
  405. //FaEvent.FaPostInfo(Module.ToString(), $"Recipe:{CurrentRunningRecipe} finished");
  406. UpdateWaferStatus();
  407. if (_currentRecipe.Header.Type == RecipeType.Process)
  408. {
  409. processRecipe = (Recipe)SerializeHelper.Instance.Clone(_currentRecipe);
  410. }
  411. _chamber.EPDRecipeStop();
  412. RecipeDown("Success");
  413. return !StartNewRecipe();
  414. }
  415. }
  416. return false;
  417. }
  418. public void RecipeDown(string result)
  419. {
  420. Recipetime.Stop();
  421. WaferInfo waferInfo = WaferManager.Instance.GetWafer(ModuleHelper.Converter(Module.ToString()), 0);
  422. if (!waferInfo.IsEmpty)
  423. {
  424. WaferId = waferInfo.InnerId.ToString();
  425. SlotID = waferInfo.OriginSlot.ToString();
  426. LotID = waferInfo.ProcessJob == null || string.IsNullOrEmpty(waferInfo.ProcessJob.ControlJobName) ? "" : waferInfo.ProcessJob.ControlJobName;
  427. }
  428. RecipeEndTime = RecipeStartTime + Recipetime.Elapsed;
  429. switch (_currentRecipe.Header.Type)
  430. {
  431. case RecipeType.Clean:
  432. ProcessDataRecorder.RecordPrecess(GuidAllStep, RecipeStartTime, DateTime.Now, _currentRecipe.Header.Name, result, "", _chamber.Name, "", "", _currentRecipe.Header.Type.ToString());
  433. break;
  434. case RecipeType.Chuck:
  435. case RecipeType.DeChuck:
  436. case RecipeType.Process:
  437. ProcessDataRecorder.RecordPrecess(GuidAllStep, RecipeStartTime, RecipeEndTime, _currentRecipe.Header.Name, result, WaferId, _chamber.Name, LotID, SlotID, _currentRecipe.Header.Type.ToString());
  438. break;
  439. }
  440. GuidAllStep = null;
  441. }
  442. private bool ProcessDone()
  443. {
  444. _currentRecipe.Steps[_currentStep].End();
  445. RecipeFileManager.Instance.SaveAsRecipe2(Module.ToString(), _currentRecipe.Header.Type.ToString(), _currentRecipe.Header.Name, RecipeUnity.RecipeToString(_currentRecipe));
  446. _stepTime.Stop();
  447. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Idle);
  448. CloseAllValves();
  449. _chamber.GeneratorSetpower(0);
  450. _chamber.GeneratorBiasSetpower(0);
  451. _chamber.GeneratorBiasPowerOn(false);
  452. _chamber.GeneratorPowerOn(false);
  453. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  454. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  455. _chamber.OpenValve(ValveType.Guage, true);
  456. _chamber.SetPVPostion(1000);
  457. if (_jetChamber == JetChamber.Venus && _chamber.IsHVOn == true)
  458. {
  459. _chamber.OnOffSetESCHV(false);
  460. }
  461. return true;
  462. }
  463. private void UpdateWaferStatus(bool bDone = true)
  464. {
  465. if (bDone == false)
  466. {
  467. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Failed);
  468. if (_currentRecipe.Header.Type == RecipeType.Chuck)
  469. {
  470. // set wafer chucked flag even if the chuck recipe failed.
  471. WaferManager.Instance.UpdateWaferChuckStatus(Module, 0, EnumWaferChuckStatus.Chucked);
  472. }
  473. }
  474. switch (_currentRecipe.Header.Type)
  475. {
  476. case RecipeType.Process:
  477. break;
  478. case RecipeType.Chuck:
  479. WaferManager.Instance.UpdateWaferChuckStatus(Module, 0, EnumWaferChuckStatus.Chucked);
  480. break;
  481. case RecipeType.DeChuck:
  482. WaferManager.Instance.UpdateWaferProcessStatus(Module, 0, EnumWaferProcessStatus.Completed);
  483. WaferManager.Instance.UpdateWaferChuckStatus(Module, 0, EnumWaferChuckStatus.Dechucked);
  484. break;
  485. }
  486. }
  487. public async void Abort()
  488. {
  489. RecipeDown("Abort");
  490. _chamber.GeneratorBiasPowerOn(false);
  491. _chamber.GeneratorPowerOn(false);
  492. _chamber.TurnPendulumValve(false);
  493. CloseAllValves();
  494. _chamber.OpenValve(ValveType.TurboPumpPumping, true);
  495. _chamber.OpenValve(ValveType.TurboPumpPurge, true);
  496. if (_chamber.ChamberType == JetChamber.Venus)
  497. {
  498. await Task.Delay(3000);
  499. _chamber.OnOffSetESCHV(false);
  500. }
  501. }
  502. }
  503. }