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