application.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. */
  14. /**
  15. * @addtogroup STM32
  16. */
  17. /*@{*/
  18. #include <rtthread.h>
  19. #include <finsh.h>
  20. #include <stm32f10x.h>
  21. #include "board.h"
  22. #ifdef RT_USING_DFS
  23. /* dfs init */
  24. #include <dfs_init.h>
  25. /* dfs filesystem:FAT filesystem init */
  26. #include <dfs_fat.h>
  27. /* dfs filesystem:EFS filesystem init */
  28. #include <dfs_efs.h>
  29. /* dfs Filesystem APIs */
  30. #include <dfs_fs.h>
  31. #endif
  32. #ifdef RT_USING_LWIP
  33. #include <lwip/sys.h>
  34. #include <lwip/api.h>
  35. #endif
  36. /*
  37. key_enter PA0
  38. key_down PA1
  39. key_up PA2
  40. key_right PC2
  41. key_left PC3
  42. */
  43. #define key_enter_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)
  44. #define key_down_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)
  45. #define key_up_GETVALUE() GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2)
  46. #define key_right_GETVALUE() GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2)
  47. #define key_left_GETVALUE() GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_3)
  48. void rt_key_entry(void *parameter)
  49. {
  50. GPIO_InitTypeDef GPIO_InitStructure;
  51. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC,ENABLE);
  52. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  53. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  54. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  55. GPIO_Init(GPIOA,&GPIO_InitStructure);
  56. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
  57. GPIO_Init(GPIOC,&GPIO_InitStructure);
  58. while (1)
  59. {
  60. if ( key_enter_GETVALUE() == 0 )rt_kprintf("key_enter\r\n");
  61. if ( key_down_GETVALUE() == 0 )rt_kprintf("key_down\r\n");
  62. if ( key_up_GETVALUE() == 0 )rt_kprintf("key_up\r\n");
  63. if ( key_right_GETVALUE() == 0 )rt_kprintf("key_right\r\n");
  64. if ( key_left_GETVALUE() == 0 )rt_kprintf("key_left\r\n");
  65. rt_thread_delay(20);
  66. }
  67. }
  68. extern rt_err_t lcd_hw_init(void);
  69. void rt_lcd_entry(void *parameter)
  70. {
  71. rt_device_t device;
  72. unsigned int i,k;
  73. unsigned short color[]={0xf800,0x07e0,0x001f,0xffe0,0x0000,0xffff,0x07ff,0xf81f};
  74. lcd_hw_init();
  75. device = rt_device_find("lcd");
  76. rt_kprintf("Now test the LCD......\r\n");
  77. while (1)
  78. {
  79. for (k=0;k<8;k++)
  80. {
  81. for (i=0;i<320*240;i++)
  82. {
  83. device->write(device,i*2,&color[k],2);
  84. }
  85. rt_thread_delay(RT_TICK_PER_SECOND);
  86. }
  87. }
  88. }
  89. void lcd_test()
  90. {
  91. rt_thread_t lcd_tid;
  92. lcd_tid = rt_thread_create("lcd",
  93. rt_lcd_entry, RT_NULL,
  94. 1024, 30, 5);
  95. if (lcd_tid != RT_NULL) rt_thread_startup(lcd_tid);
  96. }
  97. FINSH_FUNCTION_EXPORT(lcd_test, test lcd)
  98. /* thread phase init */
  99. void rt_init_thread_entry(void *parameter)
  100. {
  101. /* Filesystem Initialization */
  102. #ifdef RT_USING_DFS
  103. {
  104. /* init the device filesystem */
  105. dfs_init();
  106. /* init the efsl filesystam*/
  107. efsl_init();
  108. /* mount sd card fat partition 1 as root directory */
  109. if (dfs_mount("sd0", "/", "efs", 0, 0) == 0)
  110. rt_kprintf("File System initialized!\n");
  111. else
  112. rt_kprintf("File System init failed!\n");
  113. }
  114. #endif
  115. /* LwIP Initialization */
  116. #ifdef RT_USING_LWIP
  117. {
  118. extern void lwip_sys_init(void);
  119. /* init lwip system */
  120. lwip_sys_init();
  121. rt_kprintf("TCP/IP initialized!\n");
  122. }
  123. #endif
  124. #if STM32_EXT_SRAM
  125. /* init netbuf worker */
  126. net_buf_init(320 * 1024);
  127. #endif
  128. }
  129. int rt_application_init()
  130. {
  131. rt_thread_t init_thread;
  132. #if (RT_THREAD_PRIORITY_MAX == 32)
  133. init_thread = rt_thread_create("init",
  134. rt_init_thread_entry, RT_NULL,
  135. 2048, 8, 20);
  136. #else
  137. init_thread = rt_thread_create("init",
  138. rt_init_thread_entry, RT_NULL,
  139. 2048, 80, 20);
  140. #endif
  141. if (init_thread != RT_NULL) rt_thread_startup(init_thread);
  142. /* create keypad thread */
  143. {
  144. rt_thread_t key_tid;
  145. key_tid = rt_thread_create("key",
  146. rt_key_entry, RT_NULL,
  147. 512, 30, 5);
  148. if (key_tid != RT_NULL) rt_thread_startup(key_tid);
  149. }
  150. return 0;
  151. }
  152. /*@}*/