您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

102 行
3.3KB

  1. /**
  2. * Copyright (c) 2011-2019 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. /**
  26. * \file
  27. * \brief SysCall class
  28. */
  29. #ifndef SysCall_h
  30. #define SysCall_h
  31. #include <stdint.h>
  32. #include <stddef.h>
  33. #include "../SdFatConfig.h"
  34. #if __cplusplus < 201103
  35. #warning nullptr defined
  36. /** Define nullptr if not C++11 */
  37. #define nullptr NULL
  38. #endif // __cplusplus < 201103
  39. //------------------------------------------------------------------------------
  40. /** Type for millis. */
  41. typedef uint16_t SdMillis_t;
  42. //------------------------------------------------------------------------------
  43. /**
  44. * \class SysCall
  45. * \brief SysCall - Class to wrap system calls.
  46. */
  47. class SysCall {
  48. public:
  49. /** \return the time in milliseconds. */
  50. static SdMillis_t curTimeMS();
  51. /** Halt execution of this thread. */
  52. static void halt() {
  53. while (1) {
  54. yield();
  55. }
  56. }
  57. /** Yield to other threads. */
  58. static void yield();
  59. };
  60. #if ENABLE_ARDUINO_FEATURES
  61. #if defined(ARDUINO)
  62. /** Use Arduino Print. */
  63. typedef Print print_t;
  64. /** Use Arduino Stream. */
  65. typedef Stream stream_t;
  66. #else // defined(ARDUINO)
  67. #error "Unknown system"
  68. #endif // defined(ARDUINO)
  69. //------------------------------------------------------------------------------
  70. #ifndef F
  71. /** Define macro for strings stored in flash. */
  72. #define F(str) (str)
  73. #endif // F
  74. //------------------------------------------------------------------------------
  75. /** \return the time in milliseconds. */
  76. inline SdMillis_t SysCall::curTimeMS() {
  77. return millis();
  78. }
  79. //------------------------------------------------------------------------------
  80. #if defined(PLATFORM_ID) // Only defined if a Particle device
  81. inline void SysCall::yield() {
  82. Particle.process();
  83. }
  84. #elif defined(ARDUINO)
  85. inline void SysCall::yield() {
  86. // Use the external Arduino yield() function.
  87. ::yield();
  88. }
  89. #else // defined(PLATFORM_ID)
  90. inline void SysCall::yield() {}
  91. #endif // defined(PLATFORM_ID)
  92. //------------------------------------------------------------------------------
  93. #else // ENABLE_ARDUINO_FEATURES
  94. #include "./PrintBasic.h"
  95. /** If not Arduino */
  96. typedef PrintBasic print_t;
  97. /** If not Arduino */
  98. typedef PrintBasic stream_t;
  99. inline void SysCall::yield() {}
  100. #endif // ENABLE_ARDUINO_FEATURES
  101. #endif // SysCall_h