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