Pinned to some recent date

Committer:
Simon Cooksey
Date:
Thu Nov 17 16:43:53 2016 +0000
Revision:
0:fb7af294d5d9
Initial commit

Who changed what in which revision?

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