1
0

application.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2014, 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. * 2014-07-13 xiaonong port for lpc43xx
  13. */
  14. #include <rtthread.h>
  15. #include <board.h>
  16. #include <rtdevice.h>
  17. #include "drv_led.h"
  18. #ifdef RT_USING_FINSH
  19. #include <finsh.h>
  20. #include <shell.h>
  21. #endif
  22. /* thread phase init */
  23. void rt_init_thread_entry(void *parameter)
  24. {
  25. #ifdef RT_USING_FINSH
  26. /* initialize finsh */
  27. finsh_system_init();
  28. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  29. #endif
  30. }
  31. /*the led thread*/
  32. ALIGN(RT_ALIGN_SIZE)
  33. static rt_uint8_t led_stack[ 512 ];
  34. static struct rt_thread led_thread;
  35. static void led_thread_entry(void *parameter)
  36. {
  37. rt_uint8_t led_value = 0;
  38. rt_device_t led_dev;
  39. rt_led_hw_init();
  40. led_dev = rt_device_find("led");
  41. if (led_dev == RT_NULL)
  42. {
  43. rt_kprintf("can not find the led device!\n");
  44. return;
  45. }
  46. while (1)
  47. {
  48. /* led0 on */
  49. led_value = 1;
  50. led_dev->write(led_dev, 0, &led_value, 1);
  51. rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */
  52. /* led0 off */
  53. led_value = 0;
  54. led_dev->write(led_dev, 0, &led_value, 1);
  55. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  56. }
  57. }
  58. int rt_application_init(void)
  59. {
  60. rt_thread_t tid;
  61. rt_err_t result;
  62. tid = rt_thread_create("init",
  63. rt_init_thread_entry, RT_NULL,
  64. 2048, RT_THREAD_PRIORITY_MAX / 3, 20);
  65. if (tid != RT_NULL) rt_thread_startup(tid);
  66. /* init led thread */
  67. result = rt_thread_init(&led_thread,
  68. "led",
  69. led_thread_entry,
  70. RT_NULL,
  71. (rt_uint8_t *)&led_stack[0],
  72. sizeof(led_stack),
  73. 20,
  74. 5);
  75. if (result == RT_EOK)
  76. {
  77. rt_thread_startup(&led_thread);
  78. }
  79. return 0;
  80. }