application.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * 2014-04-27 Bernard make code cleanup.
  14. */
  15. #include <board.h>
  16. #include <rtthread.h>
  17. #include <finsh.h>
  18. #ifdef RT_USING_GUIENGINE
  19. #include "rtgui_demo.h"
  20. #include <rtgui/driver.h>
  21. #endif
  22. #ifdef RT_USING_DFS
  23. /* dfs init */
  24. #include <dfs_init.h>
  25. /* dfs filesystem:ELM filesystem init */
  26. #include <dfs_elm.h>
  27. /* dfs Filesystem APIs */
  28. #include <dfs_fs.h>
  29. #include <dfs_posix.h>
  30. #endif
  31. #include <gd32f4xx.h>
  32. void gd_eval_led_init (void)
  33. {
  34. /* enable the led clock */
  35. rcu_periph_clock_enable(RCU_GPIOD);
  36. /* configure led GPIO port */
  37. gpio_mode_set(GPIOD, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE,GPIO_PIN_4);
  38. gpio_output_options_set(GPIOD, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_4);
  39. GPIO_BC(GPIOD) = GPIO_PIN_4;
  40. }
  41. void rt_init_thread_entry(void* parameter)
  42. {
  43. /* initialization RT-Thread Components */
  44. #ifdef RT_USING_COMPONENTS_INIT
  45. rt_components_init();
  46. #endif
  47. gd_eval_led_init();
  48. #ifdef RT_USING_GUIENGINE
  49. {
  50. rt_device_t device;
  51. device = rt_device_find("lcd");
  52. /* re-set graphic device */
  53. rtgui_graphic_set_device(device);
  54. rt_gui_demo_init();
  55. }
  56. #endif
  57. #ifdef RT_USING_DFS
  58. #ifdef RT_USING_DFS_ELMFAT
  59. /* mount sd card fat partition 0 as root directory */
  60. if (dfs_mount("gd25q16", "/", "elm", 0, 0) == 0)
  61. {
  62. rt_kprintf("spi flash mount to / !\n");
  63. }
  64. else
  65. {
  66. rt_kprintf("spi flash mount to / failed!\n");
  67. }
  68. #endif /* RT_USING_DFS_ELMFAT */
  69. #endif /* DFS */
  70. while(1)
  71. {
  72. GPIO_TG(GPIOD) = GPIO_PIN_4;
  73. rt_thread_delay(RT_TICK_PER_SECOND);
  74. }
  75. }
  76. int rt_application_init()
  77. {
  78. rt_thread_t tid;
  79. tid = rt_thread_create("init",
  80. rt_init_thread_entry, RT_NULL,
  81. 2048, RT_THREAD_PRIORITY_MAX/3, 20);
  82. if (tid != RT_NULL)
  83. rt_thread_startup(tid);
  84. return 0;
  85. }