application.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2010-03-30 Kyle First version
  9. * 2023-10-20 Raman Gopalan Access GPIO using RT's pin abstractions
  10. */
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include "compiler.h"
  14. #include "gpio.h"
  15. #define USER_LED_1 AVR32_PIN_PA08
  16. #define USER_LED_2 AVR32_PIN_PA07
  17. char thread_led1_stack[1024];
  18. struct rt_thread thread_led1;
  19. static void rt_thread_entry_led1(void* parameter)
  20. {
  21. rt_pin_mode(USER_LED_1, PIN_MODE_OUTPUT);
  22. while (1)
  23. {
  24. rt_pin_write(USER_LED_1, 1);
  25. rt_thread_delay(RT_TICK_PER_SECOND / 2); /* sleep 0.5 second and switch to other thread */
  26. rt_pin_write(USER_LED_1, 0);
  27. rt_thread_delay(RT_TICK_PER_SECOND / 2);
  28. }
  29. }
  30. char thread_led2_stack[1024];
  31. struct rt_thread thread_led2;
  32. void rt_thread_entry_led2(void* parameter)
  33. {
  34. rt_pin_mode(USER_LED_2, PIN_MODE_OUTPUT);
  35. while (1)
  36. {
  37. rt_pin_write(USER_LED_2, 1);
  38. rt_thread_delay(RT_TICK_PER_SECOND);
  39. rt_pin_write(USER_LED_2, 0);
  40. rt_thread_delay(RT_TICK_PER_SECOND);
  41. }
  42. }
  43. int rt_application_init()
  44. {
  45. /* create led1 thread */
  46. rt_thread_init(&thread_led1,
  47. "led1",
  48. rt_thread_entry_led1,
  49. RT_NULL,
  50. &thread_led1_stack[0],
  51. sizeof(thread_led1_stack), 5, 5);
  52. rt_thread_startup(&thread_led1);
  53. //------- init led2 thread
  54. rt_thread_init(&thread_led2,
  55. "led2",
  56. rt_thread_entry_led2,
  57. RT_NULL,
  58. &thread_led2_stack[0],
  59. sizeof(thread_led2_stack),5,10);
  60. rt_thread_startup(&thread_led2);
  61. return 0;
  62. }