esp32.pp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 vTaskDelay(xTicksToDelay: uint32); external;
  41. procedure flushOutput(var t : TextRec);
  42. begin
  43. fflush(ppointer(__getreent+8)^);
  44. end;
  45. procedure _FPC_haltproc; public name '_haltproc';noreturn;
  46. begin
  47. if operatingsystem_result <> 0 then
  48. writeln('Runtime error ', operatingsystem_result);
  49. writeln('_haltproc called, exit code: ',operatingsystem_result);
  50. flushOutput(TextRec(Output));
  51. repeat
  52. // Allow other tasks to run
  53. // Do not enter deep sleep, can lead to problems with flashing
  54. vTaskDelay(1000);
  55. until false;
  56. end;
  57. procedure app_main;public name 'app_main';noreturn;
  58. begin
  59. PASCALMAIN;
  60. _FPC_haltproc;
  61. end;
  62. function WriteChar(ACh: char; AUserData: pointer): boolean;
  63. begin
  64. WriteChar:=true;
  65. putchar(ACh);
  66. end;
  67. function ReadChar(var ACh: char; AUserData: pointer): boolean;
  68. begin
  69. ReadChar:=true;
  70. ACh:=getchar;
  71. end;
  72. begin
  73. OpenIO(Input, @WriteChar, @ReadChar, fmInput, nil);
  74. OpenIO(Output, @WriteChar, @ReadChar, fmOutput, nil);
  75. OpenIO(ErrOutput, @WriteChar, @ReadChar, fmOutput, nil);
  76. OpenIO(StdOut, @WriteChar, @ReadChar, fmOutput, nil);
  77. OpenIO(StdErr, @WriteChar, @ReadChar, fmOutput, nil);
  78. end.