Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Ethernet.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #ifndef MBED_ETHERNET_H
  17. #define MBED_ETHERNET_H
  18. #include "platform.h"
  19. #if DEVICE_ETHERNET
  20. namespace mbed {
  21. /** An ethernet interface, to use with the ethernet pins.
  22. *
  23. * Example:
  24. * @code
  25. * // Read destination and source from every ethernet packet
  26. *
  27. * #include "mbed.h"
  28. *
  29. * Ethernet eth;
  30. *
  31. * int main() {
  32. * char buf[0x600];
  33. *
  34. * while(1) {
  35. * int size = eth.receive();
  36. * if(size > 0) {
  37. * eth.read(buf, size);
  38. * printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
  39. * buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
  40. * printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
  41. * buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
  42. * }
  43. *
  44. * wait(1);
  45. * }
  46. * }
  47. * @endcode
  48. */
  49. class Ethernet {
  50. public:
  51. /** Initialise the ethernet interface.
  52. */
  53. Ethernet();
  54. /** Powers the hardware down.
  55. */
  56. virtual ~Ethernet();
  57. enum Mode {
  58. AutoNegotiate,
  59. HalfDuplex10,
  60. FullDuplex10,
  61. HalfDuplex100,
  62. FullDuplex100
  63. };
  64. /** Writes into an outgoing ethernet packet.
  65. *
  66. * It will append size bytes of data to the previously written bytes.
  67. *
  68. * @param data An array to write.
  69. * @param size The size of data.
  70. *
  71. * @returns
  72. * The number of written bytes.
  73. */
  74. int write(const char *data, int size);
  75. /** Send an outgoing ethernet packet.
  76. *
  77. * After filling in the data in an ethernet packet it must be send.
  78. * Send will provide a new packet to write to.
  79. *
  80. * @returns
  81. * 0 if the sending was failed,
  82. * or the size of the packet successfully sent.
  83. */
  84. int send();
  85. /** Recevies an arrived ethernet packet.
  86. *
  87. * Receiving an ethernet packet will drop the last received ethernet packet
  88. * and make a new ethernet packet ready to read.
  89. * If no ethernet packet is arrived it will return 0.
  90. *
  91. * @returns
  92. * 0 if no ethernet packet is arrived,
  93. * or the size of the arrived packet.
  94. */
  95. int receive();
  96. /** Read from an recevied ethernet packet.
  97. *
  98. * After receive returnd a number bigger than 0it is
  99. * possible to read bytes from this packet.
  100. * Read will write up to size bytes into data.
  101. *
  102. * It is possible to use read multible times.
  103. * Each time read will start reading after the last read byte before.
  104. *
  105. * @returns
  106. * The number of byte read.
  107. */
  108. int read(char *data, int size);
  109. /** Gives the ethernet address of the mbed.
  110. *
  111. * @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
  112. */
  113. void address(char *mac);
  114. /** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
  115. *
  116. * @returns
  117. * 0 if no ethernet link is pressent,
  118. * 1 if an ethernet link is pressent.
  119. *
  120. * Example:
  121. * @code
  122. * // Using the Ethernet link function
  123. * #include "mbed.h"
  124. *
  125. * Ethernet eth;
  126. *
  127. * int main() {
  128. * wait(1); // Needed after startup.
  129. * if (eth.link()) {
  130. * printf("online\n");
  131. * } else {
  132. * printf("offline\n");
  133. * }
  134. * }
  135. * @endcode
  136. */
  137. int link();
  138. /** Sets the speed and duplex parameters of an ethernet link
  139. *
  140. * - AutoNegotiate Auto negotiate speed and duplex
  141. * - HalfDuplex10 10 Mbit, half duplex
  142. * - FullDuplex10 10 Mbit, full duplex
  143. * - HalfDuplex100 100 Mbit, half duplex
  144. * - FullDuplex100 100 Mbit, full duplex
  145. *
  146. * @param mode the speed and duplex mode to set the link to:
  147. */
  148. void set_link(Mode mode);
  149. };
  150. } // namespace mbed
  151. #endif
  152. #endif