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