Test code for Grove Node BLE

Dependencies:   BLE_API nRF51822

Fork of BLE_LoopbackUART by Bluetooth Low Energy

Committer:
yihui
Date:
Thu Nov 27 09:30:36 2014 +0000
Revision:
10:22480ac31879
Parent:
9:05f0b5a3a70a
change to new revision hardware

Who changed what in which revision?

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