change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

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