PMProcessRoutine.cs 21 KB

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