main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*!
  2. \file main.c
  3. \brief enet demo
  4. \version 2017-02-10, V1.0.0, firmware for GD32F30x
  5. \version 2018-10-10, V1.1.0, firmware for GD32F30x
  6. \version 2018-12-25, V2.0.0, firmware for GD32F30x
  7. */
  8. /*
  9. Copyright (c) 2018, GigaDevice Semiconductor Inc.
  10. All rights reserved.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  24. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  25. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  26. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  29. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  30. OF SUCH DAMAGE.
  31. */
  32. #include "gd32f30x.h"
  33. #include "hd_eth.h"
  34. #include "main.h"
  35. #include "tcpip.h"
  36. #include "hello_gigadevice.h"
  37. #include "tcp_client.h"
  38. #include "udp_echo.h"
  39. #include "led.h"
  40. #include "usart.h"
  41. #include "string.h"
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include "netconf.h"
  45. #include "sys_mqtt.h"
  46. /*
  47. *freertosÓÅÏȼ¶¹ÜÀí
  48. *
  49. */
  50. #define INIT_TASK_PRIO ( tskIDLE_PRIORITY + 1 )
  51. #define DHCP_TASK_PRIO ( tskIDLE_PRIORITY + 4 )
  52. #define LED_TASK_PRIO ( tskIDLE_PRIORITY + 2 )
  53. void led_task(void * pvParameters);
  54. void init_task(void * pvParameters);
  55. /*!
  56. \brief main function
  57. \param[in] none
  58. \param[out] none
  59. \retval none
  60. */
  61. int main(void)
  62. {
  63. /* configure 4 bits pre-emption priority */
  64. nvic_priority_group_set(NVIC_PRIGROUP_PRE4_SUB0);
  65. gd_485_DE_pin_init();
  66. config_485_port(COM_485,115200,8,1,0);
  67. gd_485_DE_tx();
  68. /* init task */
  69. xTaskCreate(init_task, "INIT",1024, NULL, INIT_TASK_PRIO, NULL);
  70. /* start scheduler */
  71. vTaskStartScheduler();
  72. while(1)
  73. {
  74. }
  75. }
  76. /*!
  77. \brief init task
  78. \param[in] pvParameters not used
  79. \param[out] none
  80. \retval none
  81. */
  82. void init_task(void * pvParameters)
  83. {
  84. /* configure ethernet (GPIOs, clocks, MAC, DMA) */
  85. enet_system_setup();
  86. /* initilaize the LwIP stack */
  87. lwip_stack_init();
  88. /* initilaize the tcp server: telnet 8000 */
  89. // hello_gigadevice_init();
  90. /* initilaize the tcp client: echo 1026 */
  91. // tcp_client_init();
  92. /* initilaize the udp: echo 1025 */
  93. udp_echo_init();
  94. #ifdef USE_DHCP
  95. /* start DHCP client */
  96. xTaskCreate(dhcp_task, "DHCP", 512, NULL, DHCP_TASK_PRIO, NULL);
  97. #endif /* USE_DHCP */
  98. /* start toogle LED task every 250ms */
  99. // xTaskCreate(led_task, "LED", 512, NULL, LED_TASK_PRIO, NULL);
  100. mqtt_task_creat();
  101. for( ;; ){
  102. vTaskDelete(NULL);
  103. }
  104. }
  105. /*!
  106. \brief led task
  107. \param[in] pvParameters not used
  108. \param[out] none
  109. \retval none
  110. */
  111. void led_task(void * pvParameters)
  112. {
  113. for( ;; ){
  114. /* toggle LED3 each 250ms */
  115. gd_eval_led_toggle(LED_DEV);
  116. vTaskDelay(250);
  117. }
  118. }
  119. void vApplicationStackOverflowHook(TaskHandle_t xTask, char *pcTaskName )
  120. {
  121. printf("task :%s Õ»Òç³ö\r\n",pcTaskName);
  122. }
  123. void vApplicationMallocFailedHook()
  124. {
  125. printf("malloc error\r\n");
  126. }