SysCall.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * Copyright (c) 2011-2018 Bill Greiman
  3. * This file is part of the SdFat library for SD memory cards.
  4. *
  5. * MIT License
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. * DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef SysCall_h
  26. #define SysCall_h
  27. /**
  28. * \file
  29. * \brief SysCall class
  30. */
  31. #if defined(ARDUINO)
  32. #include <Arduino.h>
  33. #include <SPI.h>
  34. #elif defined(PLATFORM_ID) // Only defined if a Particle device
  35. #include "application.h"
  36. #else // defined(ARDUINO)
  37. #error "Unknown system"
  38. #endif // defined(ARDUINO)
  39. //------------------------------------------------------------------------------
  40. #ifdef ESP8266
  41. // undefine F macro if ESP8266.
  42. #undef F
  43. #endif // ESP8266
  44. //------------------------------------------------------------------------------
  45. #ifndef F
  46. /** Define macro for strings stored in flash. */
  47. #define F(str) (str)
  48. #endif // F
  49. //------------------------------------------------------------------------------
  50. /** \return the time in milliseconds. */
  51. inline uint16_t curTimeMS() {
  52. return millis();
  53. }
  54. //------------------------------------------------------------------------------
  55. /**
  56. * \class SysCall
  57. * \brief SysCall - Class to wrap system calls.
  58. */
  59. class SysCall {
  60. public:
  61. /** Halt execution of this thread. */
  62. static void halt() {
  63. while (1) {
  64. yield();
  65. }
  66. }
  67. /** Yield to other threads. */
  68. static void yield();
  69. };
  70. #if defined(ESP8266)
  71. inline void SysCall::yield() {
  72. // Avoid ESP8266 bug
  73. delay(0);
  74. }
  75. #elif defined(ARDUINO)
  76. inline void SysCall::yield() {
  77. // Use the external Arduino yield() function.
  78. ::yield();
  79. }
  80. #elif defined(PLATFORM_ID) // Only defined if a Particle device
  81. inline void SysCall::yield() {
  82. Particle.process();
  83. }
  84. #else // ESP8266
  85. inline void SysCall::yield() {}
  86. #endif // ESP8266
  87. #endif // SysCall_h