uIPmain.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Copyright (c) 2001, Adam Dunkels.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. All advertising materials mentioning features or use of this software
  14. * must display the following acknowledgement:
  15. * This product includes software developed by Adam Dunkels.
  16. * 4. The name of the author may not be used to endorse or promote
  17. * products derived from this software without specific prior
  18. * written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
  21. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  26. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  27. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. * This file is part of the uIP TCP/IP stack.
  33. *
  34. * $Id: main.c,v 1.16 2006/06/11 21:55:03 adam Exp $
  35. *
  36. */
  37. #include "uip.h"
  38. #include "uip_arp.h"
  39. #include "stm32_eth.h"
  40. #include "rtconfig.h"
  41. #include "rtdef.h"
  42. #include "uip_timer.h"
  43. #include "rtthread.h"
  44. #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
  45. // Define Prototypes
  46. void TransmitPacket(void)
  47. {
  48. int i;
  49. u8_t data[1500];
  50. // Copy the header portion part
  51. for(i=0; i < (UIP_LLH_LEN + 40); ++i)
  52. {
  53. data[i] = uip_buf[i];
  54. }
  55. // Copy the data portion part
  56. for(; i < uip_len; ++i)
  57. {
  58. data[i] = uip_appdata[i - UIP_LLH_LEN - 40 ];
  59. }
  60. ETH_HandleTxPkt(data,uip_len);
  61. }
  62. void uip_tcpip_thread(void *parameter)
  63. {
  64. int i;
  65. static u8_t cnt;
  66. while(1)
  67. {
  68. rt_thread_delay(CLOCK_SECOND*5);
  69. for (i = 0; i < UIP_CONNS; i++)
  70. {
  71. uip_periodic(i);
  72. /* If the above function invocation resulted in data that
  73. should be sent out on the network, the global variable
  74. uip_len is set to a value > 0. */
  75. if (uip_len > 0)
  76. {
  77. uip_arp_out();
  78. TransmitPacket();
  79. }
  80. }
  81. #if UIP_UDP
  82. for (i = 0; i < UIP_UDP_CONNS; i++)
  83. {
  84. uip_udp_periodic(i);
  85. /* If the above function invocation resulted in data that
  86. should be sent out on the network, the global variable
  87. uip_len is set to a value > 0. */
  88. if (uip_len > 0)
  89. {
  90. uip_arp_out();
  91. TransmitPacket();
  92. }
  93. }
  94. #endif /* UIP_UDP */
  95. /* Call the ARP timer function every 10 seconds. */
  96. if (++cnt > 2) uip_arp_timer();
  97. }
  98. }
  99. rt_thread_t sys_thread_new(char *name, void (* thread)(void *arg), void *arg, int stacksize, int prio)
  100. {
  101. rt_thread_t t;
  102. t = rt_thread_create(name, thread, arg, stacksize, prio, 20);
  103. RT_ASSERT(t != RT_NULL);
  104. rt_thread_startup(t);
  105. return t;
  106. }
  107. void uip_sys_init(void)
  108. {
  109. uip_init(); //uip init
  110. sys_thread_new("uip",uip_tcpip_thread, RT_NULL, RT_LWIP_TCPTHREAD_STACKSIZE, RT_LWIP_TCPTHREAD_PRIORITY);
  111. hello_world_init(); //
  112. }
  113. /*---------------------------------------------------------------------------*/
  114. void uip_log(char *m)
  115. {
  116. rt_kprintf("uIP log message: %s\n", m);
  117. }