application.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2014-07-13 xiaonong port for lpc43xx
  9. */
  10. #include <rtthread.h>
  11. #include <board.h>
  12. #include <rtdevice.h>
  13. #include "drv_led.h"
  14. #ifdef RT_USING_FINSH
  15. #include <finsh.h>
  16. #include <shell.h>
  17. #endif
  18. #ifdef RT_USING_VBUS
  19. #include <vbus.h>
  20. #endif
  21. /* thread phase init */
  22. void rt_init_thread_entry(void *parameter)
  23. {
  24. #ifdef RT_USING_FINSH
  25. /* initialize finsh */
  26. finsh_system_init();
  27. finsh_set_device(RT_CONSOLE_DEVICE_NAME);
  28. #endif
  29. #ifdef RT_USING_VBUS
  30. rt_vbus_do_init();
  31. #endif
  32. }
  33. /*the led thread*/
  34. ALIGN(RT_ALIGN_SIZE)
  35. static rt_uint8_t led_stack[1024];
  36. static struct rt_thread led_thread;
  37. static void led_thread_entry(void *parameter)
  38. {
  39. rt_device_t led_dev;
  40. rt_device_t vbus_dev;
  41. rt_err_t err;
  42. rt_led_hw_init();
  43. led_dev = rt_device_find("led");
  44. if (led_dev == RT_NULL)
  45. {
  46. rt_kprintf("can not find the led device\n");
  47. return;
  48. }
  49. vbus_dev = rt_device_find("vecho");
  50. if (vbus_dev == RT_NULL)
  51. {
  52. rt_kprintf("can not find the vbus device\n");
  53. return;
  54. }
  55. err = rt_device_open(vbus_dev, RT_DEVICE_OFLAG_RDWR);
  56. if (err != RT_EOK)
  57. {
  58. rt_kprintf("open vbus failed: %d\n", err);
  59. return;
  60. }
  61. while (1)
  62. {
  63. rt_uint8_t led_value;
  64. int len;
  65. len = rt_device_read(vbus_dev, 0, &led_value, sizeof(led_value));
  66. if (len <= 0)
  67. {
  68. rt_kprintf("vbus read err: %d, %d\n", len, rt_get_errno());
  69. }
  70. led_dev->write(led_dev, 1, &led_value, sizeof(led_value));
  71. }
  72. }
  73. int rt_application_init(void)
  74. {
  75. rt_thread_t tid;
  76. rt_err_t result;
  77. tid = rt_thread_create("init",
  78. rt_init_thread_entry, RT_NULL,
  79. 2048, 3, 20);
  80. if (tid != RT_NULL)
  81. rt_thread_startup(tid);
  82. /* init led thread */
  83. result = rt_thread_init(&led_thread, "led",
  84. led_thread_entry, RT_NULL,
  85. (rt_uint8_t *)&led_stack[0], sizeof(led_stack),
  86. 20, 5);
  87. if (result == RT_EOK)
  88. {
  89. rt_thread_startup(&led_thread);
  90. }
  91. return 0;
  92. }