Zynq.SystemWatchdog.Mod 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. MODULE SystemWatchdog; (** AUTHOR "Timothée Martiel"; PURPOSE "Zynq system watchdog driver"; *)
  2. IMPORT SYSTEM, Platform;
  3. CONST
  4. (** Modes *)
  5. Reset * = TRUE; (** In this mode, the watchdog resets the whole system when triggered *)
  6. Irq * = FALSE; (** In this mode, the watchdog triggers IRQ 30 *)
  7. ZmrWdEn = 0;
  8. ZmrRstEn = 1;
  9. ZmrIrqEn = 2;
  10. ZmrIrqLen4 = {};
  11. ZmrIrqLen8 = {7};
  12. ZmrIrqLen16 = {8};
  13. ZmrIrqLen32 = {7, 8};
  14. ZmrIrqLenMask = {7, 8};
  15. ZmrKey = LSH(LONGINT(0ABCH), 12); (*0AB'C0'00H;*)
  16. CcrDelayMask = {2 .. 13};
  17. CcrPrescalerMask = 3H;
  18. CcrKey = 92'00'00H;
  19. RestartKey = 1999H;
  20. (** Start the watchdog for delay ms *)
  21. PROCEDURE Start * (mode: BOOLEAN; delay: LONGINT);
  22. VAR val: SET;
  23. BEGIN
  24. Stop;
  25. (* Set clock input *)
  26. Platform.slcr.SLCR_UNLOCK := Platform.SlcrUnlockKey;
  27. Platform.slcr.WDT_CLK_SEL := 0;
  28. Platform.slcr.SLCR_LOCK := Platform.SlcrLockKey;
  29. (* Set delay *)
  30. val := SYSTEM.VAL(SET, LSH(delay * 150'000', -12) + 1) * CcrDelayMask;
  31. Platform.swdt.XWDTPS_CCR_OFFSET := CcrKey + SYSTEM.VAL(LONGINT, val);
  32. (* Enable Watchdog *)
  33. IF mode THEN
  34. INCL(val, ZmrRstEn)
  35. ELSE
  36. INCL(val, ZmrIrqEn)
  37. END;
  38. INCL(val, ZmrWdEn);
  39. val := val + ZmrIrqLen4;
  40. Platform.swdt.XWDTPS_ZMR_OFFSET := ZmrKey + SYSTEM.VAL(LONGINT, val);
  41. Feed
  42. END Start;
  43. (** Stop the watchdog *)
  44. PROCEDURE Stop *;
  45. BEGIN
  46. Platform.swdt.XWDTPS_ZMR_OFFSET := ZmrKey
  47. END Stop;
  48. (** Feed the watchdog: set its count to delay ms *)
  49. PROCEDURE Feed *;
  50. BEGIN
  51. Platform.swdt.XWDTPS_RESTART_OFFSET := RestartKey;
  52. END Feed;
  53. PROCEDURE Test *;
  54. BEGIN
  55. Start(Reset, 100)
  56. END Test;
  57. END SystemWatchdog.