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