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