Ethernet.cpp 1.9 KB

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