Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 6:40e873bbc5f7 1 /* mbed Microcontroller Library
MACRUM 6:40e873bbc5f7 2 * Copyright (c) 2006-2013 ARM Limited
MACRUM 6:40e873bbc5f7 3 *
MACRUM 6:40e873bbc5f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 6:40e873bbc5f7 5 * you may not use this file except in compliance with the License.
MACRUM 6:40e873bbc5f7 6 * You may obtain a copy of the License at
MACRUM 6:40e873bbc5f7 7 *
MACRUM 6:40e873bbc5f7 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 6:40e873bbc5f7 9 *
MACRUM 6:40e873bbc5f7 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 6:40e873bbc5f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 6:40e873bbc5f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 6:40e873bbc5f7 13 * See the License for the specific language governing permissions and
MACRUM 6:40e873bbc5f7 14 * limitations under the License.
MACRUM 6:40e873bbc5f7 15 */
MACRUM 6:40e873bbc5f7 16 #ifndef MBED_ETHERNET_H
MACRUM 6:40e873bbc5f7 17 #define MBED_ETHERNET_H
MACRUM 6:40e873bbc5f7 18
MACRUM 6:40e873bbc5f7 19 #include "platform/platform.h"
MACRUM 6:40e873bbc5f7 20
MACRUM 6:40e873bbc5f7 21 #if DEVICE_ETHERNET
MACRUM 6:40e873bbc5f7 22
MACRUM 6:40e873bbc5f7 23 namespace mbed {
MACRUM 6:40e873bbc5f7 24 /** \addtogroup drivers */
MACRUM 6:40e873bbc5f7 25 /** @{*/
MACRUM 6:40e873bbc5f7 26
MACRUM 6:40e873bbc5f7 27 /** An ethernet interface, to use with the ethernet pins.
MACRUM 6:40e873bbc5f7 28 *
MACRUM 6:40e873bbc5f7 29 * @Note Synchronization level: Not protected
MACRUM 6:40e873bbc5f7 30 *
MACRUM 6:40e873bbc5f7 31 * Example:
MACRUM 6:40e873bbc5f7 32 * @code
MACRUM 6:40e873bbc5f7 33 * // Read destination and source from every ethernet packet
MACRUM 6:40e873bbc5f7 34 *
MACRUM 6:40e873bbc5f7 35 * #include "mbed.h"
MACRUM 6:40e873bbc5f7 36 *
MACRUM 6:40e873bbc5f7 37 * Ethernet eth;
MACRUM 6:40e873bbc5f7 38 *
MACRUM 6:40e873bbc5f7 39 * int main() {
MACRUM 6:40e873bbc5f7 40 * char buf[0x600];
MACRUM 6:40e873bbc5f7 41 *
MACRUM 6:40e873bbc5f7 42 * while(1) {
MACRUM 6:40e873bbc5f7 43 * int size = eth.receive();
MACRUM 6:40e873bbc5f7 44 * if(size > 0) {
MACRUM 6:40e873bbc5f7 45 * eth.read(buf, size);
MACRUM 6:40e873bbc5f7 46 * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
MACRUM 6:40e873bbc5f7 47 * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
MACRUM 6:40e873bbc5f7 48 * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
MACRUM 6:40e873bbc5f7 49 * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
MACRUM 6:40e873bbc5f7 50 * }
MACRUM 6:40e873bbc5f7 51 *
MACRUM 6:40e873bbc5f7 52 * wait(1);
MACRUM 6:40e873bbc5f7 53 * }
MACRUM 6:40e873bbc5f7 54 * }
MACRUM 6:40e873bbc5f7 55 * @endcode
MACRUM 6:40e873bbc5f7 56 */
MACRUM 6:40e873bbc5f7 57 class Ethernet {
MACRUM 6:40e873bbc5f7 58
MACRUM 6:40e873bbc5f7 59 public:
MACRUM 6:40e873bbc5f7 60
MACRUM 6:40e873bbc5f7 61 /** Initialise the ethernet interface.
MACRUM 6:40e873bbc5f7 62 */
MACRUM 6:40e873bbc5f7 63 Ethernet();
MACRUM 6:40e873bbc5f7 64
MACRUM 6:40e873bbc5f7 65 /** Powers the hardware down.
MACRUM 6:40e873bbc5f7 66 */
MACRUM 6:40e873bbc5f7 67 virtual ~Ethernet();
MACRUM 6:40e873bbc5f7 68
MACRUM 6:40e873bbc5f7 69 enum Mode {
MACRUM 6:40e873bbc5f7 70 AutoNegotiate,
MACRUM 6:40e873bbc5f7 71 HalfDuplex10,
MACRUM 6:40e873bbc5f7 72 FullDuplex10,
MACRUM 6:40e873bbc5f7 73 HalfDuplex100,
MACRUM 6:40e873bbc5f7 74 FullDuplex100
MACRUM 6:40e873bbc5f7 75 };
MACRUM 6:40e873bbc5f7 76
MACRUM 6:40e873bbc5f7 77 /** Writes into an outgoing ethernet packet.
MACRUM 6:40e873bbc5f7 78 *
MACRUM 6:40e873bbc5f7 79 * It will append size bytes of data to the previously written bytes.
MACRUM 6:40e873bbc5f7 80 *
MACRUM 6:40e873bbc5f7 81 * @param data An array to write.
MACRUM 6:40e873bbc5f7 82 * @param size The size of data.
MACRUM 6:40e873bbc5f7 83 *
MACRUM 6:40e873bbc5f7 84 * @returns
MACRUM 6:40e873bbc5f7 85 * The number of written bytes.
MACRUM 6:40e873bbc5f7 86 */
MACRUM 6:40e873bbc5f7 87 int write(const char *data, int size);
MACRUM 6:40e873bbc5f7 88
MACRUM 6:40e873bbc5f7 89 /** Send an outgoing ethernet packet.
MACRUM 6:40e873bbc5f7 90 *
MACRUM 6:40e873bbc5f7 91 * After filling in the data in an ethernet packet it must be send.
MACRUM 6:40e873bbc5f7 92 * Send will provide a new packet to write to.
MACRUM 6:40e873bbc5f7 93 *
MACRUM 6:40e873bbc5f7 94 * @returns
MACRUM 6:40e873bbc5f7 95 * 0 if the sending was failed,
MACRUM 6:40e873bbc5f7 96 * or the size of the packet successfully sent.
MACRUM 6:40e873bbc5f7 97 */
MACRUM 6:40e873bbc5f7 98 int send();
MACRUM 6:40e873bbc5f7 99
MACRUM 6:40e873bbc5f7 100 /** Recevies an arrived ethernet packet.
MACRUM 6:40e873bbc5f7 101 *
MACRUM 6:40e873bbc5f7 102 * Receiving an ethernet packet will drop the last received ethernet packet
MACRUM 6:40e873bbc5f7 103 * and make a new ethernet packet ready to read.
MACRUM 6:40e873bbc5f7 104 * If no ethernet packet is arrived it will return 0.
MACRUM 6:40e873bbc5f7 105 *
MACRUM 6:40e873bbc5f7 106 * @returns
MACRUM 6:40e873bbc5f7 107 * 0 if no ethernet packet is arrived,
MACRUM 6:40e873bbc5f7 108 * or the size of the arrived packet.
MACRUM 6:40e873bbc5f7 109 */
MACRUM 6:40e873bbc5f7 110 int receive();
MACRUM 6:40e873bbc5f7 111
MACRUM 6:40e873bbc5f7 112 /** Read from an recevied ethernet packet.
MACRUM 6:40e873bbc5f7 113 *
MACRUM 6:40e873bbc5f7 114 * After receive returnd a number bigger than 0it is
MACRUM 6:40e873bbc5f7 115 * possible to read bytes from this packet.
MACRUM 6:40e873bbc5f7 116 * Read will write up to size bytes into data.
MACRUM 6:40e873bbc5f7 117 *
MACRUM 6:40e873bbc5f7 118 * It is possible to use read multible times.
MACRUM 6:40e873bbc5f7 119 * Each time read will start reading after the last read byte before.
MACRUM 6:40e873bbc5f7 120 *
MACRUM 6:40e873bbc5f7 121 * @returns
MACRUM 6:40e873bbc5f7 122 * The number of byte read.
MACRUM 6:40e873bbc5f7 123 */
MACRUM 6:40e873bbc5f7 124 int read(char *data, int size);
MACRUM 6:40e873bbc5f7 125
MACRUM 6:40e873bbc5f7 126 /** Gives the ethernet address of the mbed.
MACRUM 6:40e873bbc5f7 127 *
MACRUM 6:40e873bbc5f7 128 * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
MACRUM 6:40e873bbc5f7 129 */
MACRUM 6:40e873bbc5f7 130 void address(char *mac);
MACRUM 6:40e873bbc5f7 131
MACRUM 6:40e873bbc5f7 132 /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
MACRUM 6:40e873bbc5f7 133 *
MACRUM 6:40e873bbc5f7 134 * @returns
MACRUM 6:40e873bbc5f7 135 * 0 if no ethernet link is pressent,
MACRUM 6:40e873bbc5f7 136 * 1 if an ethernet link is pressent.
MACRUM 6:40e873bbc5f7 137 *
MACRUM 6:40e873bbc5f7 138 * Example:
MACRUM 6:40e873bbc5f7 139 * @code
MACRUM 6:40e873bbc5f7 140 * // Using the Ethernet link function
MACRUM 6:40e873bbc5f7 141 * #include "mbed.h"
MACRUM 6:40e873bbc5f7 142 *
MACRUM 6:40e873bbc5f7 143 * Ethernet eth;
MACRUM 6:40e873bbc5f7 144 *
MACRUM 6:40e873bbc5f7 145 * int main() {
MACRUM 6:40e873bbc5f7 146 * wait(1); // Needed after startup.
MACRUM 6:40e873bbc5f7 147 * if (eth.link()) {
MACRUM 6:40e873bbc5f7 148 * printf("online\n");
MACRUM 6:40e873bbc5f7 149 * } else {
MACRUM 6:40e873bbc5f7 150 * printf("offline\n");
MACRUM 6:40e873bbc5f7 151 * }
MACRUM 6:40e873bbc5f7 152 * }
MACRUM 6:40e873bbc5f7 153 * @endcode
MACRUM 6:40e873bbc5f7 154 */
MACRUM 6:40e873bbc5f7 155 int link();
MACRUM 6:40e873bbc5f7 156
MACRUM 6:40e873bbc5f7 157 /** Sets the speed and duplex parameters of an ethernet link
MACRUM 6:40e873bbc5f7 158 *
MACRUM 6:40e873bbc5f7 159 * - AutoNegotiate Auto negotiate speed and duplex
MACRUM 6:40e873bbc5f7 160 * - HalfDuplex10 10 Mbit, half duplex
MACRUM 6:40e873bbc5f7 161 * - FullDuplex10 10 Mbit, full duplex
MACRUM 6:40e873bbc5f7 162 * - HalfDuplex100 100 Mbit, half duplex
MACRUM 6:40e873bbc5f7 163 * - FullDuplex100 100 Mbit, full duplex
MACRUM 6:40e873bbc5f7 164 *
MACRUM 6:40e873bbc5f7 165 * @param mode the speed and duplex mode to set the link to:
MACRUM 6:40e873bbc5f7 166 */
MACRUM 6:40e873bbc5f7 167 void set_link(Mode mode);
MACRUM 6:40e873bbc5f7 168 };
MACRUM 6:40e873bbc5f7 169
MACRUM 6:40e873bbc5f7 170 } // namespace mbed
MACRUM 6:40e873bbc5f7 171
MACRUM 6:40e873bbc5f7 172 #endif
MACRUM 6:40e873bbc5f7 173
MACRUM 6:40e873bbc5f7 174 #endif
MACRUM 6:40e873bbc5f7 175
MACRUM 6:40e873bbc5f7 176 /** @}*/