LPC11U35 ADC Tick & USBSerial

Dependencies:   mbed

Dependents:   SmallDoseMeter_SingleCH_AE_lpc11u35_V1_00

Committer:
H_Tsunemoto
Date:
Mon Feb 19 09:09:52 2018 +0000
Revision:
1:b1a3be5f48ab
Parent:
0:871ab6846b18
test

Who changed what in which revision?

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