application.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. * 2013-07-12 aozima update for auto initial.
  14. */
  15. /**
  16. * @addtogroup STM32
  17. */
  18. /*@{*/
  19. #include <board.h>
  20. #include <rtthread.h>
  21. #ifdef RT_USING_COMPONENTS_INIT
  22. #include <components.h>
  23. #endif /* RT_USING_COMPONENTS_INIT */
  24. #ifdef RT_USING_DFS
  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. extern int dfs_init(void);
  31. #endif
  32. //ALIGN(RT_ALIGN_SIZE)
  33. void rt_init_thread_entry(void *parameter)
  34. {
  35. /* Filesystem Initialization */
  36. #ifdef RT_USING_SPI
  37. stm32_hw_spi_init();
  38. #endif
  39. #if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
  40. dfs_init();
  41. elm_init();
  42. /* mount sd card fat partition 1 as root directory */
  43. if (dfs_mount("flash0", "/", "elm", 0, 0) == 0)
  44. {
  45. rt_kprintf("File System initialized!\n");
  46. }
  47. else
  48. {
  49. rt_kprintf("File System initialzation failed!\n");
  50. dfs_mkfs("elm","flash0");
  51. HAL_NVIC_SystemReset();
  52. }
  53. #endif /* RT_USING_DFS */
  54. }
  55. int rt_application_init(void)
  56. {
  57. rt_thread_t init_thread;
  58. // rt_err_t result;
  59. #if (RT_THREAD_PRIORITY_MAX == 32)
  60. init_thread = rt_thread_create("init",
  61. rt_init_thread_entry, RT_NULL,
  62. 1024, 8, 20);
  63. #else
  64. init_thread = rt_thread_create("init",
  65. rt_init_thread_entry, RT_NULL,
  66. 1024, 80, 20);
  67. #endif
  68. if (init_thread != RT_NULL)
  69. rt_thread_startup(init_thread);
  70. return 0;
  71. }
  72. /*@}*/