application.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /* Private typedef -------------------------------------------------------------*/
  37. /* Private define --------------------------------------------------------------*/
  38. /* Private macro --------------------------------------------------------------*/
  39. /* Private variables ------------------------------------------------------------*/
  40. rt_uint32_t rt_system_status = 0;
  41. /* Private function prototypes ---------------------------------------------------*/
  42. /* Private functions ------------------------------------------------------------*/
  43. void rt_demo_thread_entry(void* parameter)
  44. {
  45. #ifdef EFM32_USING_SFLASH
  46. rt_uint8_t i;
  47. rt_uint8_t test[] = "123456789ABCDEF";
  48. rt_uint8_t buf[30], buf2[30];
  49. efm_spiFash_cmd(sflash_inst_rdid_l, EFM32_NO_DATA, buf, sizeof(buf));
  50. rt_kprintf("Manuf ID: %x\n", buf[0]);
  51. rt_kprintf("Memory type: %x\n", buf[1]);
  52. rt_kprintf("Memory capacity: %x\n", buf[2]);
  53. rt_kprintf("CFD length: %x\n", buf[3]);
  54. rt_kprintf("CFD: %x%x%x...%x%x\n", buf[4], buf[5], buf[6], buf[18], buf[19]);
  55. efm_spiFash_cmd(sflash_inst_wren, EFM32_NO_DATA, EFM32_NO_POINTER, EFM32_NO_DATA);
  56. do
  57. {
  58. efm_spiFash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
  59. rt_kprintf("Status: %x\n", buf2[0]);
  60. } while (buf2[0] == 0xFF);
  61. rt_kprintf("Status: %x\n", buf2[0]);
  62. //efm_spiFash_cmd(sflash_inst_pp, 0x000003F8, test, sizeof(test) - 1);
  63. efm_spiFash_cmd(sflash_inst_rdsr, EFM32_NO_DATA, buf2, sizeof(buf2));
  64. rt_kprintf("Status: %x\n", buf2[0]);
  65. efm_spiFash_cmd(sflash_inst_read, 0x00000300, buf, sizeof(buf));
  66. rt_kprintf("READ: \n");
  67. for (i = 0; i < sizeof(buf); i++)
  68. {
  69. rt_kprintf("%c\n", buf[i]);
  70. }
  71. //efm_spiFash_deinit();
  72. #endif
  73. }
  74. void rt_led_thread_entry(void* parameter)
  75. {
  76. rt_uint8_t n = 0;
  77. rt_hw_led_on(0);
  78. rt_hw_led_on(1);
  79. rt_hw_led_on(2);
  80. rt_hw_led_on(3);
  81. while(1)
  82. {
  83. /* Toggle a led per second */
  84. rt_hw_led_toggle(n++);
  85. if (n == LEDS_MAX_NUMBER)
  86. {
  87. n =0;
  88. }
  89. rt_thread_delay(100);
  90. }
  91. }
  92. int rt_application_init()
  93. {
  94. rt_thread_t demo_thread, led_thread;
  95. #if (defined(EFM32_G290_DK) && defined(EFM32_USING_SFLASH))
  96. /* Enable SPI access to Flash */
  97. DVK_writeRegister(BC_SPI_CFG, 0);
  98. efm_spiFash_init();
  99. #endif
  100. /* Initialize all device drivers (dev_?.c) */
  101. if (rt_hw_led_init() != RT_EOK)
  102. {
  103. rt_kprintf("*** Failed to initialize LED driver!");
  104. while(1); //Or do something?
  105. }
  106. if (rt_hw_misc_init() != RT_EOK)
  107. {
  108. rt_kprintf("*** Failed to miscellaneous driver!");
  109. while(1); //Or do something?
  110. }
  111. #if (RT_THREAD_PRIORITY_MAX == 32)
  112. demo_thread = rt_thread_create(
  113. "demo",
  114. rt_demo_thread_entry,
  115. RT_NULL,
  116. 2048,
  117. 3,
  118. 20);
  119. led_thread = rt_thread_create(
  120. "led",
  121. rt_led_thread_entry,
  122. RT_NULL,
  123. 256,
  124. 3,
  125. 20);
  126. #else
  127. #endif
  128. if(demo_thread != RT_NULL)
  129. {
  130. rt_kprintf("demo sp:%x\n", demo_thread->sp);
  131. rt_thread_startup(demo_thread);
  132. }
  133. if(led_thread != RT_NULL)
  134. {
  135. rt_thread_startup(led_thread);
  136. }
  137. return 0;
  138. }
  139. /******************************************************************//**
  140. * @}
  141. *********************************************************************/