application.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /******************************************************************//**
  2. * @file application.c
  3. * @brief application tasks
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. * @author Bernard, onelife
  6. * @version 0.4 beta
  7. **********************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file LICENSE in this
  10. * distribution or at http://www.rt-thread.org/license/LICENSE
  11. **********************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2009-01-05 Bernard first version
  15. * 2010-12-29 onelife Modify for EFM32
  16. * 2011-05-06 onelife Add SPI Flash DEMO
  17. *********************************************************************/
  18. /******************************************************************//**
  19. * @addtogroup cortex-m3
  20. * @{
  21. *********************************************************************/
  22. /* Includes -------------------------------------------------------------------*/
  23. #include <board.h>
  24. #ifdef RT_USING_DFS
  25. /* dfs init */
  26. #include <dfs_init.h>
  27. /* dfs filesystem:ELM filesystem init */
  28. #include <dfs_elm.h>
  29. /* dfs Filesystem APIs */
  30. #include <dfs_fs.h>
  31. #endif
  32. #include "dev_led.h"
  33. #ifdef EFM32_USING_SFLASH
  34. #include "dev_sflash.h"
  35. #endif
  36. #ifdef EFM32_USING_SPISD
  37. #include "drv_sdcard.h"
  38. #endif
  39. /* Private typedef -------------------------------------------------------------*/
  40. /* Private define --------------------------------------------------------------*/
  41. /* Private macro --------------------------------------------------------------*/
  42. /* Private variables ------------------------------------------------------------*/
  43. rt_uint32_t rt_system_status = 0;
  44. /* Private function prototypes ---------------------------------------------------*/
  45. /* Private functions ------------------------------------------------------------*/
  46. void rt_demo_thread_entry(void* parameter)
  47. {
  48. #if defined(RT_USING_DFS)
  49. /* Filesystem Initialization */
  50. dfs_init();
  51. #if defined(RT_USING_DFS_ELMFAT)
  52. /* init the elm chan FatFs filesystam*/
  53. elm_init();
  54. #if defined(EFM32_USING_SPISD)
  55. /* mount sd card fat partition 1 as root directory */
  56. if (dfs_mount(SPISD_DEVICE_NAME, "/", "elm", 0, 0) == 0)
  57. {
  58. rt_kprintf("FatFs init OK\n");
  59. }
  60. else
  61. {
  62. rt_kprintf("FatFs init failed!\n");
  63. }
  64. #endif
  65. #endif
  66. #endif
  67. #ifdef EFM32_USING_SFLASH
  68. {
  69. rt_uint8_t i;
  70. rt_uint8_t test[] = "123456789ABCDEF";
  71. rt_uint8_t buf[30], buf2[30];
  72. efm_spiFlash_cmd(sflash_inst_rdid_l, EFM32_NO_DATA, buf, sizeof(buf));
  73. rt_kprintf("Manuf ID: %x\n", buf[0]);
  74. rt_kprintf("Memory type: %x\n", buf[1]);
  75. rt_kprintf("Memory capacity: %x\n", buf[2]);
  76. rt_kprintf("CFD length: %x\n", buf[3]);
  77. rt_kprintf("CFD: %x%x%x...%x%x\n", buf[4], buf[5], buf[6], buf[18], buf[19]);
  78. efm_spiFlash_cmd(sflash_inst_wren, EFM32_NO_DATA, EFM32_NO_POINTER, EFM32_NO_DATA);
  79. do
  80. {
  81. efm_spiFlash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
  82. rt_kprintf("Status: %x\n", buf2[0]);
  83. } while (buf2[0] == 0xFF);
  84. rt_kprintf("Status: %x\n", buf2[0]);
  85. //efm_spiFash_cmd(sflash_inst_pp, 0x000003F8, test, sizeof(test) - 1);
  86. efm_spiFlash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
  87. rt_kprintf("Status: %x\n", buf2[0]);
  88. efm_spiFlash_cmd(sflash_inst_read, 0x00000300, buf, sizeof(buf));
  89. rt_kprintf("READ: \n");
  90. for (i = 0; i < sizeof(buf); i++)
  91. {
  92. rt_kprintf("%c\n", buf[i]);
  93. }
  94. //efm_spiFlash_deinit();
  95. }
  96. #endif
  97. rt_kprintf("Demo End\n");
  98. }
  99. void rt_led_thread_entry(void* parameter)
  100. {
  101. rt_uint8_t n = 0;
  102. rt_hw_led_on(0);
  103. rt_hw_led_on(1);
  104. rt_hw_led_on(2);
  105. rt_hw_led_on(3);
  106. while(1)
  107. {
  108. /* Toggle a led per second */
  109. rt_hw_led_toggle(n++);
  110. if (n == LEDS_MAX_NUMBER)
  111. {
  112. n =0;
  113. }
  114. rt_thread_delay(100);
  115. }
  116. }
  117. int rt_application_init()
  118. {
  119. rt_thread_t demo_thread, led_thread;
  120. #if defined(EFM32_USING_SFLASH)
  121. efm_spiFlash_init();
  122. #endif
  123. #if defined(EFM32_USING_SPISD)
  124. efm_spiSd_init();
  125. #endif
  126. /* Initialize all device drivers (dev_?.c) */
  127. if (rt_hw_led_init() != RT_EOK)
  128. {
  129. rt_kprintf("*** Failed to initialize LED driver!");
  130. while(1); //Or do something?
  131. }
  132. #if defined(RT_USING_ADC0)
  133. if (rt_hw_misc_init() != RT_EOK)
  134. {
  135. rt_kprintf("*** Failed to miscellaneous driver!");
  136. while(1); //Or do something?
  137. }
  138. #endif
  139. #if (RT_THREAD_PRIORITY_MAX == 32)
  140. demo_thread = rt_thread_create(
  141. "demo",
  142. rt_demo_thread_entry,
  143. RT_NULL,
  144. 2048,
  145. 3,
  146. 20);
  147. led_thread = rt_thread_create(
  148. "led",
  149. rt_led_thread_entry,
  150. RT_NULL,
  151. 256,
  152. 3,
  153. 20);
  154. #else
  155. #endif
  156. if(demo_thread != RT_NULL)
  157. {
  158. rt_kprintf("demo sp:%x\n", demo_thread->sp);
  159. rt_thread_startup(demo_thread);
  160. }
  161. if(led_thread != RT_NULL)
  162. {
  163. rt_thread_startup(led_thread);
  164. }
  165. return 0;
  166. }
  167. /******************************************************************//**
  168. * @}
  169. *********************************************************************/