esp8266.pp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {******************************************************************************
  2. Startup code for xtensa-esp8266 using ESP8266_RTOS_SDK V3.3
  3. ******************************************************************************}
  4. unit esp8266;
  5. {$goto on}
  6. {$macro on}
  7. interface
  8. {$linklib esp8266, static}
  9. {$linklib log, static}
  10. {$linklib c_fnano, static}
  11. {$linklib newlib, static}
  12. {$linklib heap, static}
  13. {$linklib vfs, static}
  14. {$linklib esp_common, static}
  15. {$linklib core, static}
  16. {$linklib freertos, static}
  17. {$linklib phy, static}
  18. {$linklib net80211, static}
  19. {$linklib hal, static}
  20. {$linklib nvs_flash, static}
  21. {$linklib rtc, static}
  22. {$linklib spi_flash, static}
  23. {$linklib esp_ringbuf, static}
  24. {$linklib gcc, static}
  25. {$linklib pp, static}
  26. {$linklib stdc++, static}
  27. {$linklib pthread, 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 putchar(c : char);external;
  36. function uart_rx_one_char(pRxChar: PChar): longint; external;
  37. function __getreent : pointer;external;
  38. procedure fflush(f : pointer);external;
  39. procedure vTaskDelay(xTicksToDelay: uint32); external;
  40. procedure flushOutput(var t : TextRec);
  41. begin
  42. fflush(ppointer(__getreent+8)^);
  43. end;
  44. procedure _FPC_haltproc; public name '_haltproc';
  45. begin
  46. writeln;
  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';
  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 := #0;
  71. repeat
  72. uart_rx_one_char(@ACh); // check failure?
  73. if ACh = #0 then
  74. vTaskDelay(1);
  75. until ACh <> #0;
  76. end;
  77. begin
  78. OpenIO(Input, @WriteChar, @ReadChar, fmInput, nil);
  79. OpenIO(Output, @WriteChar, @ReadChar, fmOutput, nil);
  80. OpenIO(ErrOutput, @WriteChar, @ReadChar, fmOutput, nil);
  81. OpenIO(StdOut, @WriteChar, @ReadChar, fmOutput, nil);
  82. OpenIO(StdErr, @WriteChar, @ReadChar, fmOutput, nil);
  83. end.