ARM.A2.EnetEnvironment.Mod 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. MODULE EnetEnvironment;
  2. (**
  3. AUTHOR: Alexey Morozov, HighDim GmbH, 2015
  4. PURPOSE: Ethernet networking stack, ARM A2 - specific environment
  5. *)
  6. IMPORT
  7. Platform, BootConfig, Machine, Objects, KernelLog;
  8. TYPE
  9. Time* = HUGEINT; (* Time type used in EnetTiming *)
  10. (* The prototype of an interrupt handler *)
  11. InterruptHandler* = PROCEDURE();
  12. (** Uncached memory descriptor *)
  13. UncachedMemDesc* = RECORD
  14. addr-: ADDRESS; (** starting address of the uncached memory available to the user *)
  15. length-: SIZE; (** length of the uncached memory region available to the user; can be greater than the value passed to AllocateUncachedMemory *)
  16. mem: POINTER TO ARRAY OF CHAR; (* actual allocated memory block *)
  17. END;
  18. VAR
  19. TraceString-: PROCEDURE(CONST str: ARRAY OF CHAR);
  20. GetTimeCounter-: PROCEDURE(): Time;
  21. InvalidateDCacheRange-: PROCEDURE(addr: ADDRESS; length: SIZE);
  22. FlushDCacheRange-: PROCEDURE(addr: ADDRESS; length: SIZE);
  23. cpuClockHz: LONGINT;
  24. (**
  25. Install an interrupt handler
  26. *)
  27. PROCEDURE InstallInterruptHandler*(interruptHandler: InterruptHandler; interruptNumber: LONGINT);
  28. BEGIN
  29. Objects.InstallHandler(interruptHandler,interruptNumber);
  30. END InstallInterruptHandler;
  31. (**
  32. Allocate length bytes of uncached memory
  33. *)
  34. PROCEDURE AllocateUncachedMemory*(length: SIZE; VAR memDesc: UncachedMemDesc);
  35. CONST
  36. MB = 1024*1024; (* one Mega byte *)
  37. BEGIN
  38. ASSERT(memDesc.mem = NIL);
  39. memDesc.length := MB*((length+MB-1) DIV MB); (* length as a multiple of MB *)
  40. NEW(memDesc.mem,memDesc.length+MB); (* have 1 MB reserve to be able to align to 1 MB boundary *)
  41. memDesc.addr := ADDRESSOF(memDesc.mem[0]);
  42. memDesc.addr := memDesc.addr + (MB - memDesc.addr MOD MB); (* align to 1 MB boundary *)
  43. ASSERT(memDesc.addr >= ADDRESSOF(memDesc.mem[0]));
  44. ASSERT(memDesc.addr MOD MB = 0);
  45. ASSERT(memDesc.addr+memDesc.length <= ADDRESSOF(memDesc.mem[LEN(memDesc.mem)-1]));
  46. Machine.DisableDCacheRange(memDesc.addr,memDesc.length);
  47. END AllocateUncachedMemory;
  48. (**
  49. Dispose uncached memory
  50. *)
  51. PROCEDURE DisposeUncachedMemory*(VAR memDesc: UncachedMemDesc);
  52. BEGIN
  53. ASSERT(memDesc.mem # NIL);
  54. Machine.EnableDCacheRange(memDesc.addr,memDesc.length);
  55. memDesc.mem := NIL;
  56. memDesc.addr := NIL;
  57. memDesc.length := 0;
  58. END DisposeUncachedMemory;
  59. (** Convert microseconds to time counts *)
  60. PROCEDURE FromMicro*(us: Time): Time;
  61. BEGIN
  62. RETURN us * ENTIERH(0.5D0+LONGREAL(cpuClockHz)/2.0D6);
  63. END FromMicro;
  64. (** Convert milliseconds to time counts *)
  65. PROCEDURE FromMilli*(ms: Time): Time;
  66. BEGIN
  67. RETURN ms * ENTIERH(0.5D0+LONGREAL(cpuClockHz)/2.0D3);
  68. END FromMilli;
  69. BEGIN
  70. cpuClockHz := BootConfig.GetIntValue("CpuClockHz");
  71. TraceString := KernelLog.String;
  72. GetTimeCounter := Machine.GetTimer;
  73. InvalidateDCacheRange := Machine.InvalidateDCacheRange;
  74. FlushDCacheRange := Machine.FlushDCacheRange;
  75. TraceString("EnetEnvironment has been initialized!");
  76. END EnetEnvironment.