esp32.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. {******************************************************************************
  2. Startup code for xtensa-esp32 using idf
  3. ******************************************************************************}
  4. unit esp32;
  5. {$goto on}
  6. {$macro on}
  7. interface
  8. {$linklib esp32,static}
  9. {$linklib soc,static}
  10. {$linklib driver,static}
  11. {$linklib freertos,static}
  12. {$linklib log,static}
  13. {$linklib esp_common,static}
  14. {$linklib heap,static}
  15. {$linklib newlib,static}
  16. {$linklib vfs,static}
  17. {$linklib esp_ringbuf,static}
  18. {$linklib spi_flash,static}
  19. {$linklib app_update,static}
  20. {$linklib xtensa,static}
  21. {$linklib bootloader_support,static}
  22. {$linklib pthread,static}
  23. {$linklib hal,static}
  24. {$linklib libm,static}
  25. {$linklib libg,static}
  26. {$linklib c,static}
  27. {$linklib esp_event,static}
  28. implementation
  29. uses
  30. consoleio,heapmgr;
  31. var
  32. _stack_top: record end; public name '_stack_top';
  33. operatingsystem_result: longint; external name 'operatingsystem_result';
  34. procedure PASCALMAIN; external name 'PASCALMAIN';
  35. procedure esp_deep_sleep_start;external;
  36. procedure putchar(c : char);external;
  37. function getchar : char;external;
  38. function __getreent : pointer;external;
  39. procedure fflush(f : pointer);external;
  40. procedure printpchar(p : pchar);
  41. begin
  42. while p^<>#0 do
  43. begin
  44. putchar(p^);
  45. inc(p);
  46. end;
  47. fflush(ppointer(__getreent+8)^);
  48. end;
  49. procedure printdword(d : dword);
  50. const
  51. s = '0123456789ABCDEF';
  52. var
  53. i : longint;
  54. begin
  55. for i:=1 to 8 do
  56. begin
  57. putchar(s[(d and $f)+1]);
  58. d:=d shr 4;
  59. end;
  60. fflush(ppointer(__getreent+8)^);
  61. end;
  62. procedure _FPC_haltproc; public name '_haltproc';noreturn;
  63. begin
  64. printpchar('_haltproc called, going to deep sleep, exit code: $');
  65. printdword(operatingsystem_result);
  66. printpchar(#10);
  67. while true do
  68. esp_deep_sleep_start;
  69. end;
  70. procedure app_main;public name 'app_main';noreturn;
  71. begin
  72. PASCALMAIN;
  73. _FPC_haltproc;
  74. end;
  75. function WriteChar(ACh: char; AUserData: pointer): boolean;
  76. begin
  77. WriteChar:=true;
  78. putchar(ACh);
  79. end;
  80. function ReadChar(var ACh: char; AUserData: pointer): boolean;
  81. begin
  82. ReadChar:=true;
  83. ACh:=getchar;
  84. end;
  85. begin
  86. OpenIO(Input, @WriteChar, @ReadChar, fmInput, nil);
  87. OpenIO(Output, @WriteChar, @ReadChar, fmOutput, nil);
  88. OpenIO(ErrOutput, @WriteChar, @ReadChar, fmOutput, nil);
  89. OpenIO(StdOut, @WriteChar, @ReadChar, fmOutput, nil);
  90. OpenIO(StdErr, @WriteChar, @ReadChar, fmOutput, nil);
  91. end.