|
| 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 | + |
| 19 | +#include "platform.h" |
| 20 | +#include "FunctionPointer.h" |
| 21 | + |
| 22 | +namespace mbed { |
| 23 | + |
| 24 | +/** Transaction structure |
| 25 | + */ |
| 26 | +typedef struct { |
| 27 | + void *tx_buffer; /**< Tx buffer */ |
| 28 | + size_t tx_length; /**< Length of Tx buffer*/ |
| 29 | + void *rx_buffer; /**< Rx buffer */ |
| 30 | + size_t rx_length; /**< Length of Rx buffer */ |
| 31 | + uint32_t event; /**< Event for a transaction */ |
| 32 | + event_callback_t callback; /**< User's callback */ |
| 33 | + uint8_t width; /**< Buffer's word width (8, 16, 32, 64) */ |
| 34 | +} transaction_t; |
| 35 | + |
| 36 | +/** Transaction class defines a transaction. |
| 37 | + * |
| 38 | + * @Note Synchronization level: Not protected |
| 39 | + */ |
| 40 | +template<typename Class> |
| 41 | +class Transaction { |
| 42 | +public: |
| 43 | + Transaction(Class *tpointer, const transaction_t& transaction) : _obj(tpointer), _data(transaction) { |
| 44 | + } |
| 45 | + |
| 46 | + Transaction() : _obj(), _data() { |
| 47 | + } |
| 48 | + |
| 49 | + ~Transaction() { |
| 50 | + } |
| 51 | + |
| 52 | + /** Get object's instance for the transaction |
| 53 | + * |
| 54 | + * @return The object which was stored |
| 55 | + */ |
| 56 | + Class* get_object() { |
| 57 | + return _obj; |
| 58 | + } |
| 59 | + |
| 60 | + /** Get the transaction |
| 61 | + * |
| 62 | + * @return The transaction which was stored |
| 63 | + */ |
| 64 | + transaction_t* get_transaction() { |
| 65 | + return &_data; |
| 66 | + } |
| 67 | + |
| 68 | +private: |
| 69 | + Class* _obj; |
| 70 | + transaction_t _data; |
| 71 | +}; |
| 72 | + |
| 73 | +} |
| 74 | + |
| 75 | +#endif |
0 commit comments