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