Transaction.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* mbed Microcontroller Library
  2. * Copyright (c) 2015 ARM Limited
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MBED_TRANSACTION_H
  17. #define MBED_TRANSACTION_H
  18. #include "platform/platform.h"
  19. #include "platform/FunctionPointer.h"
  20. namespace mbed {
  21. /** \addtogroup platform */
  22. /** @{*/
  23. /**
  24. * \defgroup platform_Transaction Transaction class
  25. * @{
  26. */
  27. /** Transaction structure
  28. */
  29. typedef struct {
  30. void *tx_buffer; /**< Tx buffer */
  31. size_t tx_length; /**< Length of Tx buffer*/
  32. void *rx_buffer; /**< Rx buffer */
  33. size_t rx_length; /**< Length of Rx buffer */
  34. uint32_t event; /**< Event for a transaction */
  35. event_callback_t callback; /**< User's callback */
  36. uint8_t width; /**< Buffer's word width (8, 16, 32, 64) */
  37. } transaction_t;
  38. /** Transaction class defines a transaction.
  39. *
  40. * @note Synchronization level: Not protected
  41. */
  42. template<typename Class>
  43. class Transaction {
  44. public:
  45. Transaction(Class *tpointer, const transaction_t &transaction) : _obj(tpointer), _data(transaction)
  46. {
  47. }
  48. Transaction() : _obj(), _data()
  49. {
  50. }
  51. ~Transaction()
  52. {
  53. }
  54. /** Get object's instance for the transaction
  55. *
  56. * @return The object which was stored
  57. */
  58. Class *get_object()
  59. {
  60. return _obj;
  61. }
  62. /** Get the transaction
  63. *
  64. * @return The transaction which was stored
  65. */
  66. transaction_t *get_transaction()
  67. {
  68. return &_data;
  69. }
  70. private:
  71. Class *_obj;
  72. transaction_t _data;
  73. };
  74. /**@}*/
  75. /**@}*/
  76. }
  77. #endif