Fork of mbed for KL05Z based smart sensor which has no crystal on the board, so MCG FEI mode is required.

Dependents:   smart-sensor-KL05Z-debug

Fork of mbed-src by Ermanno Brusadin

Committer:
ebrus
Date:
Wed Jul 27 18:35:32 2016 +0000
Revision:
0:0a673c671a56
4

Who changed what in which revision?

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