Entrega 3er corte - sistemas embebidos

Committer:
Bethory
Date:
Wed May 30 04:46:28 2018 +0000
Revision:
1:fcdb45ee95b9
Parent:
0:6ad07c9019fd
Entrega Final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bethory 0:6ad07c9019fd 1 /* mbed Microcontroller Library
Bethory 0:6ad07c9019fd 2 * Copyright (c) 2006-2013 ARM Limited
Bethory 0:6ad07c9019fd 3 *
Bethory 0:6ad07c9019fd 4 * Licensed under the Apache License, Version 2.0 (the "License");
Bethory 0:6ad07c9019fd 5 * you may not use this file except in compliance with the License.
Bethory 0:6ad07c9019fd 6 * You may obtain a copy of the License at
Bethory 0:6ad07c9019fd 7 *
Bethory 0:6ad07c9019fd 8 * http://www.apache.org/licenses/LICENSE-2.0
Bethory 0:6ad07c9019fd 9 *
Bethory 0:6ad07c9019fd 10 * Unless required by applicable law or agreed to in writing, software
Bethory 0:6ad07c9019fd 11 * distributed under the License is distributed on an "AS IS" BASIS,
Bethory 0:6ad07c9019fd 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Bethory 0:6ad07c9019fd 13 * See the License for the specific language governing permissions and
Bethory 0:6ad07c9019fd 14 * limitations under the License.
Bethory 0:6ad07c9019fd 15 */
Bethory 0:6ad07c9019fd 16 #ifndef MBED_BUSOUT_H
Bethory 0:6ad07c9019fd 17 #define MBED_BUSOUT_H
Bethory 0:6ad07c9019fd 18
Bethory 0:6ad07c9019fd 19 #include "drivers/DigitalOut.h"
Bethory 0:6ad07c9019fd 20 #include "platform/PlatformMutex.h"
Bethory 0:6ad07c9019fd 21 #include "platform/NonCopyable.h"
Bethory 0:6ad07c9019fd 22
Bethory 0:6ad07c9019fd 23 namespace mbed {
Bethory 0:6ad07c9019fd 24 /** \addtogroup drivers */
Bethory 0:6ad07c9019fd 25
Bethory 0:6ad07c9019fd 26 /** A digital output bus, used for setting the state of a collection of pins
Bethory 0:6ad07c9019fd 27 * @ingroup drivers
Bethory 0:6ad07c9019fd 28 */
Bethory 0:6ad07c9019fd 29 class BusOut : private NonCopyable<BusOut> {
Bethory 0:6ad07c9019fd 30
Bethory 0:6ad07c9019fd 31 public:
Bethory 0:6ad07c9019fd 32
Bethory 0:6ad07c9019fd 33 /** Create an BusOut, connected to the specified pins
Bethory 0:6ad07c9019fd 34 *
Bethory 0:6ad07c9019fd 35 * @param p0 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 36 * @param p1 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 37 * @param p2 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 38 * @param p3 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 39 * @param p4 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 40 * @param p5 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 41 * @param p6 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 42 * @param p7 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 43 * @param p8 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 44 * @param p9 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 45 * @param p10 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 46 * @param p11 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 47 * @param p12 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 48 * @param p13 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 49 * @param p14 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 50 * @param p15 DigitalOut pin to connect to bus bit
Bethory 0:6ad07c9019fd 51 *
Bethory 0:6ad07c9019fd 52 * @note Synchronization level: Thread safe
Bethory 0:6ad07c9019fd 53 *
Bethory 0:6ad07c9019fd 54 * @note
Bethory 0:6ad07c9019fd 55 * It is only required to specify as many pin variables as is required
Bethory 0:6ad07c9019fd 56 * for the bus; the rest will default to NC (not connected)
Bethory 0:6ad07c9019fd 57 */
Bethory 0:6ad07c9019fd 58 BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
Bethory 0:6ad07c9019fd 59 PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
Bethory 0:6ad07c9019fd 60 PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
Bethory 0:6ad07c9019fd 61 PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
Bethory 0:6ad07c9019fd 62
Bethory 0:6ad07c9019fd 63 /** Create an BusOut, connected to the specified pins
Bethory 0:6ad07c9019fd 64 *
Bethory 0:6ad07c9019fd 65 * @param pins An array of pins to connect to bus the bit
Bethory 0:6ad07c9019fd 66 */
Bethory 0:6ad07c9019fd 67 BusOut(PinName pins[16]);
Bethory 0:6ad07c9019fd 68
Bethory 0:6ad07c9019fd 69 virtual ~BusOut();
Bethory 0:6ad07c9019fd 70
Bethory 0:6ad07c9019fd 71 /** Write the value to the output bus
Bethory 0:6ad07c9019fd 72 *
Bethory 0:6ad07c9019fd 73 * @param value An integer specifying a bit to write for every corresponding DigitalOut pin
Bethory 0:6ad07c9019fd 74 */
Bethory 0:6ad07c9019fd 75 void write(int value);
Bethory 0:6ad07c9019fd 76
Bethory 0:6ad07c9019fd 77 /** Read the value currently output on the bus
Bethory 0:6ad07c9019fd 78 *
Bethory 0:6ad07c9019fd 79 * @returns
Bethory 0:6ad07c9019fd 80 * An integer with each bit corresponding to associated DigitalOut pin setting
Bethory 0:6ad07c9019fd 81 */
Bethory 0:6ad07c9019fd 82 int read();
Bethory 0:6ad07c9019fd 83
Bethory 0:6ad07c9019fd 84 /** Binary mask of bus pins connected to actual pins (not NC pins)
Bethory 0:6ad07c9019fd 85 * If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
Bethory 0:6ad07c9019fd 86 *
Bethory 0:6ad07c9019fd 87 * @returns
Bethory 0:6ad07c9019fd 88 * Binary mask of connected pins
Bethory 0:6ad07c9019fd 89 */
Bethory 0:6ad07c9019fd 90 int mask() {
Bethory 0:6ad07c9019fd 91 // No lock needed since _nc_mask is not modified outside the constructor
Bethory 0:6ad07c9019fd 92 return _nc_mask;
Bethory 0:6ad07c9019fd 93 }
Bethory 0:6ad07c9019fd 94
Bethory 0:6ad07c9019fd 95 /** A shorthand for write()
Bethory 0:6ad07c9019fd 96 * \sa BusOut::write()
Bethory 0:6ad07c9019fd 97 */
Bethory 0:6ad07c9019fd 98 BusOut& operator= (int v);
Bethory 0:6ad07c9019fd 99 BusOut& operator= (BusOut& rhs);
Bethory 0:6ad07c9019fd 100
Bethory 0:6ad07c9019fd 101 /** Access to particular bit in random-iterator fashion
Bethory 0:6ad07c9019fd 102 * @param index Bit Position
Bethory 0:6ad07c9019fd 103 */
Bethory 0:6ad07c9019fd 104 DigitalOut& operator[] (int index);
Bethory 0:6ad07c9019fd 105
Bethory 0:6ad07c9019fd 106 /** A shorthand for read()
Bethory 0:6ad07c9019fd 107 * \sa BusOut::read()
Bethory 0:6ad07c9019fd 108 */
Bethory 0:6ad07c9019fd 109 operator int();
Bethory 0:6ad07c9019fd 110
Bethory 0:6ad07c9019fd 111 protected:
Bethory 0:6ad07c9019fd 112 virtual void lock();
Bethory 0:6ad07c9019fd 113 virtual void unlock();
Bethory 0:6ad07c9019fd 114 DigitalOut* _pin[16];
Bethory 0:6ad07c9019fd 115
Bethory 0:6ad07c9019fd 116 /* Mask of bus's NC pins
Bethory 0:6ad07c9019fd 117 * If bit[n] is set to 1 - pin is connected
Bethory 0:6ad07c9019fd 118 * if bit[n] is cleared - pin is not connected (NC)
Bethory 0:6ad07c9019fd 119 */
Bethory 0:6ad07c9019fd 120 int _nc_mask;
Bethory 0:6ad07c9019fd 121
Bethory 0:6ad07c9019fd 122 PlatformMutex _mutex;
Bethory 0:6ad07c9019fd 123 };
Bethory 0:6ad07c9019fd 124
Bethory 0:6ad07c9019fd 125 } // namespace mbed
Bethory 0:6ad07c9019fd 126
Bethory 0:6ad07c9019fd 127 #endif