esp32c3.pp 2.1 KB

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