sama_onewire.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file SAMA5D2x/sama_onewire.h
  15. * @brief SAMA ONEWIRE support macros and structures.
  16. *
  17. * @addtogroup SAMA5D2x_ONEWIRE
  18. * @{
  19. */
  20. #ifndef SAMA_ONEWIRE_LLD_H
  21. #define SAMA_ONEWIRE_LLD_H
  22. /**
  23. * @brief Using the ONEWIRE driver.
  24. */
  25. #if !defined(SAMA_USE_ONEWIRE) || defined(__DOXYGEN__)
  26. #define SAMA_USE_ONEWIRE FALSE
  27. #endif
  28. #if (SAMA_USE_ONEWIRE) || defined(__DOXYGEN__)
  29. /*===========================================================================*/
  30. /* Driver constants. */
  31. /*===========================================================================*/
  32. /*===========================================================================*/
  33. /* Driver pre-compile time settings. */
  34. /*===========================================================================*/
  35. /*===========================================================================*/
  36. /* Derived constants and error checks. */
  37. /*===========================================================================*/
  38. /*===========================================================================*/
  39. /* Driver data structures and types. */
  40. /*===========================================================================*/
  41. /**
  42. * @brief Driver state machine possible states.
  43. */
  44. typedef enum {
  45. ONEW_UNINIT = 0, /**< Not initialized. */
  46. ONEW_STOP = 1, /**< Stopped. */
  47. ONEW_READY = 2, /**< Active. */
  48. ONEW_ACTIVE = 3 /**< Active. */
  49. } onewstate_t;
  50. /**
  51. * @brief Type of a structure representing a ONEWIRE driver.
  52. */
  53. typedef struct ONEWIREDriver ONEWIREDriver;
  54. /**
  55. * @brief Driver configuration structure.
  56. */
  57. typedef struct {
  58. /**
  59. * @brief Line for the data IO
  60. */
  61. uint32_t line;
  62. } ONEWIREConfig;
  63. /**
  64. * @brief Structure representing an ONEWIRE driver.
  65. */
  66. struct ONEWIREDriver {
  67. /**
  68. * @brief Driver state.
  69. */
  70. onewstate_t state;
  71. /**
  72. * @brief Current configuration data.
  73. */
  74. const ONEWIREConfig *config;
  75. /**
  76. * @brief Mutex protecting the bus.
  77. */
  78. mutex_t mutex;
  79. };
  80. /*===========================================================================*/
  81. /* Driver macros. */
  82. /*===========================================================================*/
  83. /*===========================================================================*/
  84. /* External declarations. */
  85. /*===========================================================================*/
  86. extern ONEWIREDriver ONEWD0;
  87. #ifdef __cplusplus
  88. extern "C" {
  89. #endif
  90. void onewireInit(void);
  91. void onewireObjectInit(ONEWIREDriver *onewp);
  92. void onewireStart(ONEWIREDriver *onewp, const ONEWIREConfig *config);
  93. void onewireStop(ONEWIREDriver *onewp);
  94. bool onewireReset(ONEWIREDriver *onewp);
  95. void onewireCommand(ONEWIREDriver *onewp, uint8_t *cmdp, size_t n);
  96. void onewireWriteBlock(ONEWIREDriver *onewp, uint8_t *txbuf, size_t n);
  97. void onewireReadBlock(ONEWIREDriver *onewp, uint8_t *rxbuf, size_t n);
  98. void onewireAcquireBus(ONEWIREDriver *onewp);
  99. void onewireReleaseBus(ONEWIREDriver *onewp);
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif /* SAMA_USE_ONEWIRE */
  104. #endif /* SAMA_ONEWIRE_LLD_H */
  105. /** @} */