Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

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