PMProcessRoutine.cs 19 KB

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