mbed library sources

Dependents:   RPC_Serial_V_mac

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Ethernet.cpp Source File

Ethernet.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "Ethernet.h"
00017 
00018 #if DEVICE_ETHERNET
00019 
00020 #include "ethernet_api.h"
00021 
00022 namespace mbed {
00023 
00024 Ethernet::Ethernet() {
00025     ethernet_init();
00026 }
00027 
00028 Ethernet::~Ethernet() {
00029     ethernet_free();
00030 }
00031 
00032 int Ethernet::write(const char *data, int size) {
00033     return ethernet_write(data, size);
00034 }
00035 
00036 int Ethernet::send() {
00037     return ethernet_send();
00038 }
00039 
00040 int Ethernet::receive() {
00041     return ethernet_receive();
00042 }
00043 
00044 int Ethernet::read(char *data, int size) {
00045     return ethernet_read(data, size);
00046 }
00047 
00048 void Ethernet::address(char *mac) {
00049     return ethernet_address(mac);
00050 }
00051 
00052 int Ethernet::link() {
00053     return ethernet_link();
00054 }
00055 
00056 void Ethernet::set_link(Mode mode) {
00057     int speed = -1;
00058     int duplex = 0;
00059 
00060     switch(mode) {
00061         case AutoNegotiate : speed = -1; duplex = 0; break;
00062         case HalfDuplex10  : speed = 0;  duplex = 0; break;
00063         case FullDuplex10  : speed = 0;  duplex = 1; break;
00064         case HalfDuplex100 : speed = 1;  duplex = 0; break;
00065         case FullDuplex100 : speed = 1;  duplex = 1; break;
00066     }
00067 
00068     ethernet_set_link(speed, duplex);
00069 }
00070 
00071 } // namespace mbed
00072 
00073 #endif