application.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, 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. * 2007-11-20 Yi.Qiu add rtgui application
  13. * 2008-6-28 Bernard no rtgui init
  14. */
  15. /**
  16. * @addtogroup mini4020
  17. */
  18. /*@{*/
  19. #include <board.h>
  20. #include <rtthread.h>
  21. #ifdef RT_USING_DFS
  22. #include <dfs.h>
  23. #include <dfs_elm.h>
  24. #include <dfs_fs.h>
  25. #include <dfs_posix.h>
  26. #endif
  27. #ifdef RT_USING_RTGUI
  28. #include <rtgui/rtgui.h>
  29. extern void radio_rtgui_init(void);
  30. #endif
  31. #define RT_INIT_THREAD_STACK_SIZE (2*1024)
  32. void rt_init_thread_entry(void *parameter)
  33. {
  34. int fd;
  35. rt_uint32_t sz;
  36. char buffer[20];
  37. #ifdef RT_USING_DFS
  38. dfs_init();
  39. #ifdef RT_USING_DFS_ELMFAT
  40. elm_init();
  41. /* mount sd card fat partition 1 as root directory */
  42. if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
  43. {
  44. rt_kprintf("File System initialized!\n");
  45. /*Open a file*/
  46. fd = open("/fattest.txt", O_RDWR|O_CREAT, 0);
  47. if (fd < 0)
  48. {
  49. rt_kprintf("open file for write failed\n");
  50. return;
  51. }
  52. sz = write(fd,"Hello RT-Thread!",sizeof("Hello RT-Thread!"));
  53. if (sz != 0)
  54. {
  55. rt_kprintf("written %d\n",sz);
  56. }
  57. else
  58. rt_kprintf("haven't written\n");
  59. lseek(fd, 0, SEEK_SET);
  60. sz = read(fd, buffer, sizeof(buffer));
  61. if (sz != 0)
  62. {
  63. rt_kprintf("READ %d:",sz);
  64. while (sz--)
  65. rt_kprintf("%c",buffer[sz]);//opposite
  66. rt_kprintf("\n");
  67. }
  68. else
  69. rt_kprintf("haven't read\n");
  70. close(fd);
  71. }
  72. else
  73. rt_kprintf("File System initialzation failed!\n");
  74. #endif
  75. #endif
  76. }
  77. void rt_led_thread_entry(void *parameter)
  78. {
  79. /*
  80. while (1)
  81. {
  82. count++;
  83. *(RP)GPIO_PORTE_DATA |= 0x1<<4;
  84. rt_thread_delay(RT_TICK_PER_SECOND*2);
  85. *(RP)GPIO_PORTE_DATA &= ~(0x1<<4);
  86. rt_thread_delay(RT_TICK_PER_SECOND*2);
  87. }
  88. */
  89. }
  90. int rt_application_init(void)
  91. {
  92. rt_thread_t init_thread;
  93. rt_thread_t led_thread;
  94. init_thread = rt_thread_create("init",
  95. rt_init_thread_entry, RT_NULL,
  96. RT_INIT_THREAD_STACK_SIZE, 8, 20);
  97. led_thread = rt_thread_create("led",
  98. rt_led_thread_entry, RT_NULL,
  99. 512, 200, 20);
  100. if (init_thread != RT_NULL)
  101. rt_thread_startup(init_thread);
  102. if (led_thread != RT_NULL)
  103. rt_thread_startup(led_thread);
  104. return 0;
  105. }
  106. /*@}*/