application.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * File : application.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2010, 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. * 2010-03-30 Kyle First version
  13. */
  14. #include <rtthread.h>
  15. #include "compiler.h"
  16. #include "gpio.h"
  17. char thread_led1_stack[1024];
  18. struct rt_thread thread_led1;
  19. static void rt_thread_entry_led1(void* parameter)
  20. {
  21. while (1)
  22. {
  23. /* led on */
  24. rt_kprintf("LED1 on\r\n");
  25. gpio_tgl_gpio_pin(AVR32_PIN_PA08);
  26. rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */
  27. /* led off */
  28. rt_kprintf("LED1 off\r\n");
  29. gpio_tgl_gpio_pin(AVR32_PIN_PA08);
  30. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  31. }
  32. }
  33. char thread_led2_stack[1024];
  34. struct rt_thread thread_led2;
  35. void rt_thread_entry_led2(void* parameter)
  36. {
  37. while (1)
  38. {
  39. /* led on */
  40. rt_kprintf("LED2 on");
  41. gpio_tgl_gpio_pin(AVR32_PIN_PA07);
  42. rt_thread_delay(RT_TICK_PER_SECOND);
  43. /* led off */
  44. rt_kprintf("LED2 off\r\n");
  45. gpio_tgl_gpio_pin(AVR32_PIN_PA07);
  46. rt_thread_delay(RT_TICK_PER_SECOND);
  47. }
  48. }
  49. int rt_application_init()
  50. {
  51. /* create led1 thread */
  52. rt_thread_init(&thread_led1,
  53. "led1",
  54. rt_thread_entry_led1,
  55. RT_NULL,
  56. &thread_led1_stack[0],
  57. sizeof(thread_led1_stack), 5, 5);
  58. rt_thread_startup(&thread_led1);
  59. //------- init led2 thread
  60. rt_thread_init(&thread_led2,
  61. "led2",
  62. rt_thread_entry_led2,
  63. RT_NULL,
  64. &thread_led2_stack[0],
  65. sizeof(thread_led2_stack),5,10);
  66. rt_thread_startup(&thread_led2);
  67. return 0;
  68. }