application.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard the first version
  13. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include "stm32f4xx.h"
  19. #include <board.h>
  20. #include <rtthread.h>
  21. #ifdef RT_USING_LWIP
  22. #include <lwip/sys.h>
  23. #include <lwip/api.h>
  24. #include <netif/ethernetif.h>
  25. #include "stm32_eth.h"
  26. #endif
  27. void rt_init_thread_entry(void* parameter)
  28. {
  29. /* LwIP Initialization */
  30. #ifdef RT_USING_LWIP
  31. {
  32. extern void lwip_sys_init(void);
  33. /* register ethernetif device */
  34. eth_system_device_init();
  35. rt_hw_stm32_eth_init();
  36. /* re-init device driver */
  37. rt_device_init_all();
  38. /* init lwip system */
  39. lwip_sys_init();
  40. rt_kprintf("TCP/IP initialized!\n");
  41. }
  42. {
  43. extern void eth_to_can_init(void);
  44. extern void can_to_eth_init(void);
  45. extern void upnp_init(void);
  46. extern void setting_init(void);
  47. setting_init();
  48. eth_to_can_init();
  49. can_to_eth_init();
  50. upnp_init();
  51. }
  52. #endif
  53. }
  54. ALIGN(RT_ALIGN_SIZE)
  55. static char thread_led_stack[1024];
  56. struct rt_thread thread_led;
  57. static void rt_thread_entry_led(void* parameter)
  58. {
  59. GPIO_InitTypeDef GPIO_InitStructure;
  60. /* GPIOD Periph clock enable */
  61. RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  62. /* Configure PD12, PD13, PD14 and PD15 in output pushpull mode */
  63. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
  64. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  65. GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  66. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  67. GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  68. GPIO_Init(GPIOD, &GPIO_InitStructure);
  69. while (1)
  70. {
  71. /* PD12 to be toggled */
  72. GPIO_SetBits(GPIOD, GPIO_Pin_12);
  73. /* Insert delay */
  74. rt_thread_delay(RT_TICK_PER_SECOND/2);
  75. /* PD13 to be toggled */
  76. GPIO_SetBits(GPIOD, GPIO_Pin_13);
  77. /* Insert delay */
  78. rt_thread_delay(RT_TICK_PER_SECOND/2);
  79. /* PD14 to be toggled */
  80. GPIO_SetBits(GPIOD, GPIO_Pin_14);
  81. /* Insert delay */
  82. rt_thread_delay(RT_TICK_PER_SECOND/2);
  83. /* PD15 to be toggled */
  84. GPIO_SetBits(GPIOD, GPIO_Pin_15);
  85. /* Insert delay */
  86. rt_thread_delay(RT_TICK_PER_SECOND*2);
  87. GPIO_ResetBits(GPIOD, GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15);
  88. /* Insert delay */
  89. rt_thread_delay(RT_TICK_PER_SECOND);
  90. }
  91. }
  92. int rt_application_init()
  93. {
  94. // rt_thread_t init_thread;
  95. //
  96. //#if (RT_THREAD_PRIORITY_MAX == 32)
  97. // init_thread = rt_thread_create("init",
  98. // rt_init_thread_entry, RT_NULL,
  99. // 2048, 8, 20);
  100. //#else
  101. // init_thread = rt_thread_create("init",
  102. // rt_init_thread_entry, RT_NULL,
  103. // 2048, 80, 20);
  104. //#endif
  105. //
  106. // if (init_thread != RT_NULL)
  107. // rt_thread_startup(init_thread);
  108. //------- init led1 thread
  109. rt_thread_init(&thread_led,
  110. "led",
  111. rt_thread_entry_led,
  112. RT_NULL,
  113. &thread_led_stack[0],
  114. 1024,11,5);
  115. // sizeof(thread_led_stack),11,5);
  116. rt_thread_startup(&thread_led);
  117. return 0;
  118. }
  119. /*@}*/