Yihui Xiong
/
Seeed_nRF51822_Motion
initial
mbed-src/common/Ethernet.cpp@0:638edba3adf6, 2016-01-11 (annotated)
- Committer:
- yihui
- Date:
- Mon Jan 11 02:32:24 2016 +0000
- Revision:
- 0:638edba3adf6
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:638edba3adf6 | 1 | /* mbed Microcontroller Library |
yihui | 0:638edba3adf6 | 2 | * Copyright (c) 2006-2013 ARM Limited |
yihui | 0:638edba3adf6 | 3 | * |
yihui | 0:638edba3adf6 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
yihui | 0:638edba3adf6 | 5 | * you may not use this file except in compliance with the License. |
yihui | 0:638edba3adf6 | 6 | * You may obtain a copy of the License at |
yihui | 0:638edba3adf6 | 7 | * |
yihui | 0:638edba3adf6 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
yihui | 0:638edba3adf6 | 9 | * |
yihui | 0:638edba3adf6 | 10 | * Unless required by applicable law or agreed to in writing, software |
yihui | 0:638edba3adf6 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
yihui | 0:638edba3adf6 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
yihui | 0:638edba3adf6 | 13 | * See the License for the specific language governing permissions and |
yihui | 0:638edba3adf6 | 14 | * limitations under the License. |
yihui | 0:638edba3adf6 | 15 | */ |
yihui | 0:638edba3adf6 | 16 | #include "Ethernet.h" |
yihui | 0:638edba3adf6 | 17 | |
yihui | 0:638edba3adf6 | 18 | #if DEVICE_ETHERNET |
yihui | 0:638edba3adf6 | 19 | |
yihui | 0:638edba3adf6 | 20 | #include "ethernet_api.h" |
yihui | 0:638edba3adf6 | 21 | |
yihui | 0:638edba3adf6 | 22 | namespace mbed { |
yihui | 0:638edba3adf6 | 23 | |
yihui | 0:638edba3adf6 | 24 | Ethernet::Ethernet() { |
yihui | 0:638edba3adf6 | 25 | ethernet_init(); |
yihui | 0:638edba3adf6 | 26 | } |
yihui | 0:638edba3adf6 | 27 | |
yihui | 0:638edba3adf6 | 28 | Ethernet::~Ethernet() { |
yihui | 0:638edba3adf6 | 29 | ethernet_free(); |
yihui | 0:638edba3adf6 | 30 | } |
yihui | 0:638edba3adf6 | 31 | |
yihui | 0:638edba3adf6 | 32 | int Ethernet::write(const char *data, int size) { |
yihui | 0:638edba3adf6 | 33 | return ethernet_write(data, size); |
yihui | 0:638edba3adf6 | 34 | } |
yihui | 0:638edba3adf6 | 35 | |
yihui | 0:638edba3adf6 | 36 | int Ethernet::send() { |
yihui | 0:638edba3adf6 | 37 | return ethernet_send(); |
yihui | 0:638edba3adf6 | 38 | } |
yihui | 0:638edba3adf6 | 39 | |
yihui | 0:638edba3adf6 | 40 | int Ethernet::receive() { |
yihui | 0:638edba3adf6 | 41 | return ethernet_receive(); |
yihui | 0:638edba3adf6 | 42 | } |
yihui | 0:638edba3adf6 | 43 | |
yihui | 0:638edba3adf6 | 44 | int Ethernet::read(char *data, int size) { |
yihui | 0:638edba3adf6 | 45 | return ethernet_read(data, size); |
yihui | 0:638edba3adf6 | 46 | } |
yihui | 0:638edba3adf6 | 47 | |
yihui | 0:638edba3adf6 | 48 | void Ethernet::address(char *mac) { |
yihui | 0:638edba3adf6 | 49 | return ethernet_address(mac); |
yihui | 0:638edba3adf6 | 50 | } |
yihui | 0:638edba3adf6 | 51 | |
yihui | 0:638edba3adf6 | 52 | int Ethernet::link() { |
yihui | 0:638edba3adf6 | 53 | return ethernet_link(); |
yihui | 0:638edba3adf6 | 54 | } |
yihui | 0:638edba3adf6 | 55 | |
yihui | 0:638edba3adf6 | 56 | void Ethernet::set_link(Mode mode) { |
yihui | 0:638edba3adf6 | 57 | int speed = -1; |
yihui | 0:638edba3adf6 | 58 | int duplex = 0; |
yihui | 0:638edba3adf6 | 59 | |
yihui | 0:638edba3adf6 | 60 | switch(mode) { |
yihui | 0:638edba3adf6 | 61 | case AutoNegotiate : speed = -1; duplex = 0; break; |
yihui | 0:638edba3adf6 | 62 | case HalfDuplex10 : speed = 0; duplex = 0; break; |
yihui | 0:638edba3adf6 | 63 | case FullDuplex10 : speed = 0; duplex = 1; break; |
yihui | 0:638edba3adf6 | 64 | case HalfDuplex100 : speed = 1; duplex = 0; break; |
yihui | 0:638edba3adf6 | 65 | case FullDuplex100 : speed = 1; duplex = 1; break; |
yihui | 0:638edba3adf6 | 66 | } |
yihui | 0:638edba3adf6 | 67 | |
yihui | 0:638edba3adf6 | 68 | ethernet_set_link(speed, duplex); |
yihui | 0:638edba3adf6 | 69 | } |
yihui | 0:638edba3adf6 | 70 | |
yihui | 0:638edba3adf6 | 71 | } // namespace mbed |
yihui | 0:638edba3adf6 | 72 | |
yihui | 0:638edba3adf6 | 73 | #endif |