mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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