Zynq.PrivateWatchdog.Mod 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. MODULE PrivateWatchdog; (** AUTHOR "Timothée Martiel, 11/2017"; PURPOSE "Zynq private watchdog driver"; *)
  2. IMPORT SYSTEM, Platform;
  3. CONST
  4. (** Modes *)
  5. Reset * = TRUE; (** Resets the system *)
  6. Interrupt * = FALSE; (** Triggers an interrupt *)
  7. ControlWatchdogEnable = 0;
  8. ControlAutoReload = 1;
  9. ControlItEnable = 2;
  10. ControlWdMode = 3;
  11. ControlPrescalerOfs = 8;
  12. ControlPrescalerMask = {8 .. 15};
  13. VAR
  14. frequency: HUGEINT;
  15. (** Start the private watchdog with the given mode and delay *)
  16. PROCEDURE Start * (mode: BOOLEAN; delay: LONGINT);
  17. VAR
  18. val: SET;
  19. BEGIN
  20. ASSERT(frequency > 0);
  21. Platform.mpcore.Watchdog_Reset_Status_Register := 1; (* Clear the reset status *)
  22. Feed(delay);
  23. val := {ControlWatchdogEnable};
  24. IF mode THEN
  25. (* Reset *)
  26. INCL(val, ControlWdMode)
  27. ELSE
  28. INCL(val, ControlItEnable)
  29. END;
  30. Platform.mpcore.Watchdog_Control_Register := SYSTEM.VAL(LONGINT, val)
  31. END Start;
  32. (** Stop private watchdog *)
  33. PROCEDURE Stop *;
  34. BEGIN
  35. Platform.mpcore.Watchdog_Disable_Register := Platform.PrivateWatchdogDisableKey0;
  36. Platform.mpcore.Watchdog_Disable_Register := LONGINT(Platform.PrivateWatchdogDisableKey1);
  37. Platform.mpcore.Watchdog_Control_Register := 0
  38. END Stop;
  39. (** Feed the watchdog: overwrites its count with the given delay *)
  40. PROCEDURE Feed * (delay: LONGINT);
  41. BEGIN
  42. Platform.mpcore.Watchdog_Load_Register := LONGINT(HUGEINT(delay) * frequency);
  43. END Feed;
  44. (** Check if the watchdog has been triggered *)
  45. PROCEDURE Triggered * (): BOOLEAN;
  46. BEGIN
  47. RETURN Platform.mpcore.Watchdog_Reset_Status_Register = 1
  48. END Triggered;
  49. (** Initialise watchdog reference frequency (CPU freq / 2) *)
  50. PROCEDURE Init * (timerFrequency: HUGEINT);
  51. BEGIN
  52. frequency := timerFrequency
  53. END Init;
  54. END PrivateWatchdog.