esp32.pp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. {******************************************************************************
  2. Startup code for xtensa-esp32 using idf
  3. ******************************************************************************}
  4. unit esp32;
  5. {$goto on}
  6. {$macro on}
  7. interface
  8. implementation
  9. uses
  10. consoleio,heapmgr;
  11. var
  12. _stack_top: record end; public name '_stack_top';
  13. operatingsystem_result: longint; external name 'operatingsystem_result';
  14. procedure PASCALMAIN; external name 'PASCALMAIN';
  15. procedure esp_deep_sleep_start;external;
  16. procedure putchar(c : char);external;
  17. function getchar : char;external;
  18. function __getreent : pointer;external;
  19. procedure fflush(f : pointer);external;
  20. procedure vTaskDelay(xTicksToDelay: uint32); external;
  21. procedure flushOutput(var t : TextRec);
  22. begin
  23. fflush(ppointer(__getreent+8)^);
  24. end;
  25. procedure _FPC_haltproc; public name '_haltproc';noreturn;
  26. begin
  27. if operatingsystem_result <> 0 then
  28. writeln('Runtime error ', operatingsystem_result);
  29. writeln('_haltproc called, exit code: ',operatingsystem_result);
  30. flushOutput(TextRec(Output));
  31. repeat
  32. // Allow other tasks to run
  33. // Do not enter deep sleep, can lead to problems with flashing
  34. vTaskDelay(1000);
  35. until false;
  36. end;
  37. procedure app_main;public name 'app_main';noreturn;
  38. begin
  39. PASCALMAIN;
  40. _FPC_haltproc;
  41. end;
  42. function WriteChar(ACh: char; AUserData: pointer): boolean;
  43. begin
  44. WriteChar:=true;
  45. putchar(ACh);
  46. end;
  47. function ReadChar(var ACh: char; AUserData: pointer): boolean;
  48. begin
  49. ReadChar:=true;
  50. ACh:=getchar;
  51. end;
  52. begin
  53. OpenIO(Input, @WriteChar, @ReadChar, fmInput, nil);
  54. OpenIO(Output, @WriteChar, @ReadChar, fmOutput, nil);
  55. OpenIO(ErrOutput, @WriteChar, @ReadChar, fmOutput, nil);
  56. OpenIO(StdOut, @WriteChar, @ReadChar, fmOutput, nil);
  57. OpenIO(StdErr, @WriteChar, @ReadChar, fmOutput, nil);
  58. end.